Class ImmutableTranslationPackage
java.lang.Object
com.inductiveautomation.ignition.common.i18n.translation.ImmutableTranslationPackage
- All Implemented Interfaces:
TranslationPackage
An immutable, thread-safe implementation of
TranslationPackage. All internal data
structures are deeply copied and wrapped in unmodifiable views at construction time, making
instances safe to share across threads without synchronization.
Instances are created via copyOf(TranslationPackage), which takes a snapshot of a
mutable package.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classGSON adapter that serializes in the same wire format asBasicTranslationPackagefor backwards compatibility with existing clients. -
Field Summary
Fields inherited from interface TranslationPackage
BASE_LOCALE, NOTES_IDENTIFIER -
Method Summary
Modifier and TypeMethodDescriptionstatic ImmutableTranslationPackagecopyOf(TranslationPackage source) Creates an immutable snapshot of the given package.Creates an empty, modifiable diff that respects the same rules as this translation package.Translates the given key into the requested locale.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()getResolvedTranslations(Locale locale) Resolves a whole locale directly from the per-locale bundles rather than the interface default's per-keygetStrict(Locale, String)loop.@Nullable StringTranslates the given key into the requested locale, returning null if no translation exists.@Nullable TranslationMapgetTranslationsFor(String key) booleanReturns whether the key is defined in the package.booleanReturns whether there is a translation defined for the given key in the given locale.
-
Method Details
-
copyOf
Creates an immutable snapshot of the given package. -
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
-
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.
-
getAvailableKeys
- Specified by:
getAvailableKeysin interfaceTranslationPackage- Returns:
- all the defined keys.
-
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
Description copied from interface:TranslationPackageTranslates the given key into the requested locale.- 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.
-
getResolvedTranslations
Resolves a whole locale directly from the per-locale bundles rather than the interface default's per-keygetStrict(Locale, String)loop. Bundles are merged from least- to most-specific in the fallback chain, so a more-specific translation overrides its base-language fallback; the per-locale maps omit untranslated keys, so a more-specific locale never erases a base value with a null.- Specified by:
getResolvedTranslationsin interfaceTranslationPackage- Parameters:
locale- the locale to resolve, including its fallback chain.- Returns:
- a fresh, mutable map of raw source key to translation. Never null; may be empty.
-
getTranslationsFor
- Specified by:
getTranslationsForin interfaceTranslationPackage- Returns:
- a map of all the translations available for a given key.
-
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.
-
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.
-
getAllTranslations
- Specified by:
getAllTranslationsin interfaceTranslationPackage- Returns:
- an iterator that goes through all the translations. Does not include defined keys that have no translations.
-