public class BasicTranslationPackage extends java.lang.Object implements MutableTranslationPackage
Modifier and Type | Class and Description |
---|---|
protected class |
BasicTranslationPackage.TranslationIterator |
Constructor and Description |
---|
BasicTranslationPackage() |
BasicTranslationPackage(java.util.Locale baseLocale,
KeyHashRule hashRule) |
BasicTranslationPackage(TranslationPackage copy) |
Modifier and Type | Method and Description |
---|---|
void |
addTerm(java.lang.String key)
Ensures that the specified key is in the translation package.
|
void |
addTranslation(java.lang.String term,
java.util.Locale targetLocale,
java.lang.String translation)
Sets a translation for the specified key and locale.
|
void |
addTranslations(java.lang.String key,
TranslationMap translations)
Sets all of the translations for a specific key.
|
void |
applyPackage(TranslationPackage tp)
Can merge an existing translation package into this one.
|
TranslationPackageDiff |
createDiff()
Returns an empty, modifiable diff that respects the same rules as the translation package.
|
void |
ensureLocaleExists(java.util.Locale locale)
Verifies that the locale is present, adding it if necessary.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
get(java.util.Locale locale,
java.lang.String key)
Returns the translation of the key for the requested locale, or the key, if the translation is not available.
|
java.util.Iterator<Translation> |
getAllTranslations()
Returns an iterator that goes through all of the translations.
|
java.util.Collection<java.lang.String> |
getAvailableKeys()
Returns all of the defined keys.
|
java.util.Collection<java.util.Locale> |
getAvailableLocales()
Returns the locales for which translations are available.
|
java.util.Locale |
getBaseLocale()
Returns the "base" locale, the language in which the terms are defined.
|
TranslationBundle |
getBundle(java.util.Locale l) |
java.util.Map<java.lang.String,TermKey> |
getIndex() |
KeyHashRule |
getKeyHashRule()
The key hash rule dictates how term equivalency is calculated.
|
TranslationBundle |
getOrCreateBundle(java.util.Locale l) |
protected TermKey |
getOrCreateTermKey(java.lang.String term) |
protected java.lang.String |
getOrNull(java.util.List<java.util.Locale> locales,
java.lang.String key)
Returns the translation, or null.
|
java.lang.String |
getStrict(java.util.Locale locale,
java.lang.String key)
Returns the translation, or null if the translation doesn't exist.
|
protected TermKey |
getTermKey(java.lang.String term) |
TranslationMap |
getTranslationsFor(java.lang.String key)
Returns a map of all of the translations available for a given key.
|
protected java.lang.String |
hashKey(java.lang.String term)
Returns the hashKey for the term *
|
boolean |
isDefined(java.lang.String key)
Returns whether the key is defined in the package.
|
boolean |
isDefined(java.lang.String key,
java.util.Locale l)
Returns whether there is a translation defined for the given key in the given locale.
|
boolean |
removeKey(java.lang.String key)
Removes the specific key, and any translations.
|
void |
removeLocale(java.util.Locale locale) |
void |
removeTranslation(java.lang.String term,
java.util.Locale locale)
Removes a translation for a specified key and locale.
|
void |
setBaseLocale(java.util.Locale baseLocale) |
void |
setIndex(java.util.Map<java.lang.String,TermKey> index) |
void |
setKeyHashRule(KeyHashRule rule) |
void |
updateIndex(java.util.Collection<java.lang.String> keys) |
public BasicTranslationPackage(TranslationPackage copy)
public BasicTranslationPackage()
public BasicTranslationPackage(java.util.Locale baseLocale, KeyHashRule hashRule)
protected java.lang.String hashKey(java.lang.String term)
protected TermKey getTermKey(java.lang.String term)
protected TermKey getOrCreateTermKey(java.lang.String term)
public java.util.Map<java.lang.String,TermKey> getIndex()
public void setIndex(java.util.Map<java.lang.String,TermKey> index)
public KeyHashRule getKeyHashRule()
TranslationPackage
getKeyHashRule
in interface TranslationPackage
public void setKeyHashRule(KeyHashRule rule)
public java.util.Locale getBaseLocale()
TranslationPackage
getBaseLocale
in interface TranslationPackage
public void setBaseLocale(java.util.Locale baseLocale)
public java.util.Collection<java.lang.String> getAvailableKeys()
TranslationPackage
getAvailableKeys
in interface TranslationPackage
public java.util.Collection<java.util.Locale> getAvailableLocales()
TranslationPackage
getAvailableLocales
in interface TranslationPackage
public void ensureLocaleExists(java.util.Locale locale)
MutableTranslationPackage
ensureLocaleExists
in interface MutableTranslationPackage
public boolean isDefined(java.lang.String key)
TranslationPackage
isDefined
in interface TranslationPackage
public boolean isDefined(java.lang.String key, java.util.Locale l)
TranslationPackage
isDefined
in interface TranslationPackage
public java.lang.String get(java.util.Locale locale, java.lang.String key)
get
in interface TranslationPackage
locale
- key
- public java.lang.String getStrict(java.util.Locale locale, java.lang.String key)
TranslationPackage
getStrict
in interface TranslationPackage
protected java.lang.String getOrNull(java.util.List<java.util.Locale> locales, java.lang.String key)
public TranslationBundle getBundle(java.util.Locale l)
public TranslationBundle getOrCreateBundle(java.util.Locale l)
public void updateIndex(java.util.Collection<java.lang.String> keys)
public TranslationPackageDiff createDiff()
TranslationPackage
createDiff
in interface TranslationPackage
public void applyPackage(TranslationPackage tp)
tp
- public TranslationMap getTranslationsFor(java.lang.String key)
TranslationPackage
getTranslationsFor
in interface TranslationPackage
public java.util.Iterator<Translation> getAllTranslations()
TranslationPackage
getAllTranslations
in interface TranslationPackage
public void addTranslation(java.lang.String term, java.util.Locale targetLocale, java.lang.String translation)
MutableTranslationPackage
addTranslation
in interface MutableTranslationPackage
public void removeTranslation(java.lang.String term, java.util.Locale locale)
MutableTranslationPackage
removeTranslation
in interface MutableTranslationPackage
public void addTerm(java.lang.String key)
MutableTranslationPackage
addTerm
in interface MutableTranslationPackage
public void addTranslations(java.lang.String key, TranslationMap translations)
MutableTranslationPackage
addTranslations
in interface MutableTranslationPackage
public boolean removeKey(java.lang.String key)
MutableTranslationPackage
removeKey
in interface MutableTranslationPackage
public void removeLocale(java.util.Locale locale)
removeLocale
in interface MutableTranslationPackage
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object