Class BasicTranslationPackage
- java.lang.Object
-
- com.inductiveautomation.ignition.common.i18n.translation.BasicTranslationPackage
-
- All Implemented Interfaces:
MutableTranslationPackage
,TranslationPackage
,java.io.Serializable
- Direct Known Subclasses:
TranslationPackageDiff
public class BasicTranslationPackage extends java.lang.Object implements MutableTranslationPackage
A translation package holds the keys and one or more translations for the keys.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
BasicTranslationPackage.TranslationIterator
-
Constructor Summary
Constructors Constructor Description BasicTranslationPackage()
BasicTranslationPackage(TranslationPackage copy)
BasicTranslationPackage(java.util.Locale baseLocale, KeyHashRule hashRule)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
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()
java.util.Collection<java.lang.String>
getAvailableKeys()
java.util.Collection<java.util.Locale>
getAvailableLocales()
java.util.Locale
getBaseLocale()
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)
protected TermKey
getTermKey(java.lang.String term)
TranslationMap
getTranslationsFor(java.lang.String 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)
-
-
-
Constructor Detail
-
BasicTranslationPackage
public BasicTranslationPackage(TranslationPackage copy)
-
BasicTranslationPackage
public BasicTranslationPackage()
-
BasicTranslationPackage
public BasicTranslationPackage(java.util.Locale baseLocale, KeyHashRule hashRule)
-
-
Method Detail
-
hashKey
protected java.lang.String hashKey(java.lang.String term)
Returns the hashKey for the term *
-
getTermKey
protected TermKey getTermKey(java.lang.String term)
-
getOrCreateTermKey
protected TermKey getOrCreateTermKey(java.lang.String term)
-
getIndex
public java.util.Map<java.lang.String,TermKey> getIndex()
-
setIndex
public void setIndex(java.util.Map<java.lang.String,TermKey> index)
-
getKeyHashRule
public KeyHashRule getKeyHashRule()
Description copied from interface:TranslationPackage
The key hash rule dictates how term equivalency is calculated. Though this field should not be used to look up terms, it's important that derived translation packages use the same rule.- Specified by:
getKeyHashRule
in interfaceTranslationPackage
-
setKeyHashRule
public void setKeyHashRule(KeyHashRule rule)
-
getBaseLocale
public java.util.Locale getBaseLocale()
- Specified by:
getBaseLocale
in interfaceTranslationPackage
- Returns:
- the "base" locale, the language in which the terms are defined.
-
setBaseLocale
public void setBaseLocale(java.util.Locale baseLocale)
-
getAvailableKeys
public java.util.Collection<java.lang.String> getAvailableKeys()
- Specified by:
getAvailableKeys
in interfaceTranslationPackage
- Returns:
- all of the defined keys.
-
getAvailableLocales
public java.util.Collection<java.util.Locale> getAvailableLocales()
- Specified by:
getAvailableLocales
in interfaceTranslationPackage
- Returns:
- the locales for which translations are available. This will include the base locale.
-
ensureLocaleExists
public void ensureLocaleExists(java.util.Locale locale)
Description copied from interface:MutableTranslationPackage
Verifies that the locale is present, adding it if necessary.- Specified by:
ensureLocaleExists
in interfaceMutableTranslationPackage
-
isDefined
public boolean isDefined(java.lang.String key)
Description copied from interface:TranslationPackage
Returns whether the key is defined in the package. A key can be defined without any particular translations.- Specified by:
isDefined
in interfaceTranslationPackage
-
isDefined
public boolean isDefined(java.lang.String key, java.util.Locale l)
Description copied from interface:TranslationPackage
Returns whether there is a translation defined for the given key in the given locale.- Specified by:
isDefined
in interfaceTranslationPackage
-
get
public 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.- Specified by:
get
in interfaceTranslationPackage
key
- the key to find a match for, or return value if no value found- Returns:
- the translation of the key for the requested locale, or the key, if the translation is not available.
-
getStrict
public java.lang.String getStrict(java.util.Locale locale, java.lang.String key)
- Specified by:
getStrict
in interfaceTranslationPackage
- Parameters:
locale
- the locale to find a value forkey
- the key to find a match for- Returns:
- the translation, or null if the translation doesn't exist.
-
getOrNull
protected java.lang.String getOrNull(java.util.List<java.util.Locale> locales, java.lang.String key)
Returns the translation, or null. This is true even for the base locale, in which case we would be trying to look up the "alternate".
-
getBundle
public TranslationBundle getBundle(java.util.Locale l)
-
getOrCreateBundle
public TranslationBundle getOrCreateBundle(java.util.Locale l)
-
updateIndex
public void updateIndex(java.util.Collection<java.lang.String> keys)
-
createDiff
public TranslationPackageDiff createDiff()
- Specified by:
createDiff
in interfaceTranslationPackage
- Returns:
- an empty, modifiable diff that respects the same rules as the translation package.
-
applyPackage
public void applyPackage(TranslationPackage tp)
Can merge an existing translation package into this one. Also, if tp is a TranslationPackageDiff, will remove the removed terms as well.
-
getTranslationsFor
public TranslationMap getTranslationsFor(java.lang.String key)
- Specified by:
getTranslationsFor
in interfaceTranslationPackage
- Returns:
- a map of all of the translations available for a given key.
-
getAllTranslations
public java.util.Iterator<Translation> getAllTranslations()
- Specified by:
getAllTranslations
in interfaceTranslationPackage
- Returns:
- an iterator that goes through all of the translations. Does not include defined keys that have no translations.
-
addTranslation
public void addTranslation(java.lang.String term, java.util.Locale targetLocale, java.lang.String translation)
Description copied from interface:MutableTranslationPackage
Sets a translation for the specified key and locale.- Specified by:
addTranslation
in interfaceMutableTranslationPackage
-
removeTranslation
public void removeTranslation(java.lang.String term, java.util.Locale locale)
Description copied from interface:MutableTranslationPackage
Removes a translation for a specified key and locale. Used when someone had a translation and blanks it out.- Specified by:
removeTranslation
in interfaceMutableTranslationPackage
-
addTerm
public void addTerm(java.lang.String key)
Description copied from interface:MutableTranslationPackage
Ensures that the specified key is in the translation package.- Specified by:
addTerm
in interfaceMutableTranslationPackage
-
addTranslations
public void addTranslations(java.lang.String key, TranslationMap translations)
Description copied from interface:MutableTranslationPackage
Sets all of the translations for a specific key. Translation map can be null, in which case the key will simply be registered in the index.- Specified by:
addTranslations
in interfaceMutableTranslationPackage
-
removeKey
public boolean removeKey(java.lang.String key)
Description copied from interface:MutableTranslationPackage
Removes the specific key, and any translations.- Specified by:
removeKey
in interfaceMutableTranslationPackage
- Returns:
- true if key was present
-
removeLocale
public void removeLocale(java.util.Locale locale)
- Specified by:
removeLocale
in interfaceMutableTranslationPackage
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-