Class BasicTranslationPackage
java.lang.Object
com.inductiveautomation.ignition.common.i18n.translation.BasicTranslationPackage
- All Implemented Interfaces:
MutableTranslationPackage, TranslationPackage
- Direct Known Subclasses:
TranslationPackageDiff
A translation package implementation that manages an index of keys and multiple
TranslationBundle objects for different locales.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Locale, TranslationBundle> protected KeyHashRuleFields inherited from interface TranslationPackage
BASE_LOCALE, NOTES_IDENTIFIER -
Constructor Summary
ConstructorsConstructorDescriptionNo arg constructor usesKeyHashRule.IDENTITYautomatically.BasicTranslationPackage(@Nullable KeyHashRule hashRule) -
Method Summary
Modifier and TypeMethodDescriptionvoidEnsures that the specified key is in the translation package.voidDeprecated.voidaddTranslation(String key, Locale targetLocale, @Nullable String translation) Sets a translation for the specified key and locale.voidaddTranslations(String key, @Nullable TranslationMap translations) Sets all of the translations for a specific key.voidMerges another package's translations into this one.Creates an empty, modifiable diff that respects the same rules as this translation package.voidensureLocaleExists(Locale locale) Verifies that the locale is present, adding it if necessary.booleanReturns the translation of the key for the requested locale, or the key, if the translation is not available.@Nullable TranslationBundleprotected @Nullable HashedKeygetHashedKey(String key) getIndex()The key hash rule dictates how key equivalency is calculated.@Nullable StringReturns the editorial note associated with the given key, ornullif there is none.getNotes()protected HashedKeyprotected @Nullable StringReturns the translation, or null.@Nullable StringTranslates the given key into the requested locale, returning null if no translation exists.@Nullable TranslationMapgetTranslationsFor(String key) protected @Nullable StringReturns the hashKey for the keybooleanReturns whether the key is defined in the package.booleanReturns whether there is a translation defined for the given key in the given locale.booleanRemoves the specific key, and any translations.voidremoveLocale(Locale locale) voidremoveTranslation(String key, Locale locale) Removes a translation for a specified key and locale.voidvoidsetKeyHashRule(KeyHashRule rule) Deprecated.Since 2027.2.0.voidSets or clears the editorial note for the given key.voidupdateIndex(@Nullable Collection<String> keys) Methods inherited from class Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TranslationPackage
getResolvedTranslations
-
Field Details
-
index
-
hashRule
-
bundles
-
notes
-
-
Constructor Details
-
BasicTranslationPackage
-
BasicTranslationPackage
public BasicTranslationPackage()No arg constructor usesKeyHashRule.IDENTITYautomatically. -
BasicTranslationPackage
-
-
Method Details
-
hashKey
-
getHashedKey
-
getOrCreateHashedKey
-
getIndex
-
setIndex
-
getKeyHashRule
Description copied from interface:TranslationPackageThe key hash rule dictates how key equivalency is calculated. Though this field should not be used to look up keys, it's important that derived translation packages use the same rule.- Specified by:
getKeyHashRulein interfaceTranslationPackage
-
setKeyHashRule
Deprecated.Since 2027.2.0.KeyHashRule should be considered immutable once a BasicTranslationPackage is constructed and populated. This method is kept purely for backwards compatibility with Vision deserialization; in new code, always useBasicTranslationPackage(com.inductiveautomation.ignition.common.i18n.translation.@org.jspecify.annotations.Nullable KeyHashRule)- Throws:
IllegalStateException- If called while index is not empty
-
getAvailableKeys
- Specified by:
getAvailableKeysin interfaceTranslationPackage- Returns:
- all the defined keys.
-
getAvailableLocales
- Specified by:
getAvailableLocalesin interfaceTranslationPackage- Returns:
- the locales for which translations are available. This always includes
TranslationPackage.BASE_LOCALE, the language in which keys are defined.
-
ensureLocaleExists
Description copied from interface:MutableTranslationPackageVerifies that the locale is present, adding it if necessary.- Specified by:
ensureLocaleExistsin interfaceMutableTranslationPackage
-
isDefined
Description copied from interface:TranslationPackageReturns whether the key is defined in the package. A key can be defined without any particular translations.- Specified by:
isDefinedin interfaceTranslationPackage
-
isDefined
Description copied from interface:TranslationPackageReturns whether there is a translation defined for the given key in the given locale.- Specified by:
isDefinedin interfaceTranslationPackage
-
get
Returns the translation of the key for the requested locale, or the key, if the translation is not available.- Specified by:
getin interfaceTranslationPackage- Parameters:
locale- the locale to find a match forkey- the key to find a match for- Returns:
- the translation of the key for the requested locale, or the key itself if no translation is available.
-
getStrict
Description copied from interface:TranslationPackageTranslates the given key into the requested locale, returning null if no translation exists.- Specified by:
getStrictin 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
-
getBundle
-
getOrCreateBundle
-
updateIndex
-
createDiff
Description copied from interface:TranslationPackageCreates an empty, modifiable diff that respects the same rules as this translation package. A diff is used to track changes relative to this package.- Specified by:
createDiffin interfaceTranslationPackage- Returns:
- a new
TranslationPackageDiff.
-
applyPackage
Merges another package's translations into this one. If the provided package is aTranslationPackageDiff, it will also process any removals.- Parameters:
tp- The package to apply.
-
getNote
Description copied from interface:TranslationPackageReturns the editorial note associated with the given key, ornullif there is none. Notes are per-key metadata keyed by the raw key string.- Specified by:
getNotein interfaceTranslationPackage
-
getNotes
- Specified by:
getNotesin interfaceTranslationPackage- Returns:
- an unmodifiable view of all notes, keyed by the raw key string. Never null; may be empty.
-
setNote
Description copied from interface:MutableTranslationPackageSets or clears the editorial note for the given key. A null or blank note clears any existing note.- Specified by:
setNotein interfaceMutableTranslationPackage- Parameters:
key- The key the note applies to.note- The note text, or null/blank to clear.
-
getTranslationsFor
- Specified by:
getTranslationsForin interfaceTranslationPackage- Returns:
- a map of all the translations available for a given key.
-
getAllTranslations
- Specified by:
getAllTranslationsin interfaceTranslationPackage- Returns:
- an iterator that goes through all the translations. Does not include defined keys that have no translations.
-
addTranslation
Description copied from interface:MutableTranslationPackageSets a translation for the specified key and locale.- Specified by:
addTranslationin interfaceMutableTranslationPackage- Parameters:
key- The key to translate.targetLocale- The target locale.translation- The translated string.
-
removeTranslation
Description copied from interface:MutableTranslationPackageRemoves a translation for a specified key and locale. Used when someone had a translation and blanks it out. This removes the specific translation but keeps the key in the package.- Specified by:
removeTranslationin interfaceMutableTranslationPackage- Parameters:
key- The key to modify.locale- The locale for which to remove the translation.
-
addKey
Description copied from interface:MutableTranslationPackageEnsures that the specified key is in the translation package. This registers a key without necessarily providing a translation immediately.- Specified by:
addKeyin interfaceMutableTranslationPackage- Parameters:
key- The key to add.
-
addTerm
Deprecated.As of 2027.2.0, preferaddKey(String)Cover method for Vision serialization/deserialization by method name. -
addTranslations
Description copied from interface:MutableTranslationPackageSets 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:
addTranslationsin interfaceMutableTranslationPackage
-
removeKey
Description copied from interface:MutableTranslationPackageRemoves the specific key, and any translations.- Specified by:
removeKeyin interfaceMutableTranslationPackage- Returns:
- true if key was present
-
removeLocale
- Specified by:
removeLocalein interfaceMutableTranslationPackage
-
equals
-
addKey(String)