Class ImmutableTranslationPackage

java.lang.Object
com.inductiveautomation.ignition.common.i18n.translation.ImmutableTranslationPackage
All Implemented Interfaces:
TranslationPackage

public final class ImmutableTranslationPackage extends Object implements 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.

  • Method Details

    • copyOf

      public static ImmutableTranslationPackage copyOf(TranslationPackage source)
      Creates an immutable snapshot of the given package.
    • getKeyHashRule

      public KeyHashRule getKeyHashRule()
      Description copied from interface: TranslationPackage
      The 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:
      getKeyHashRule in interface TranslationPackage
    • getAvailableLocales

      public Collection<Locale> getAvailableLocales()
      Specified by:
      getAvailableLocales in interface TranslationPackage
      Returns:
      the locales for which translations are available. This always includes TranslationPackage.BASE_LOCALE, the language in which keys are defined.
    • getAvailableKeys

      public Collection<String> getAvailableKeys()
      Specified by:
      getAvailableKeys in interface TranslationPackage
      Returns:
      all the defined keys.
    • isDefined

      public boolean isDefined(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 interface TranslationPackage
    • isDefined

      public boolean isDefined(String key, 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 interface TranslationPackage
    • get

      public String get(Locale locale, String key)
      Description copied from interface: TranslationPackage
      Translates the given key into the requested locale.
      Specified by:
      get in interface TranslationPackage
      Parameters:
      locale - the locale to find a match for
      key - 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

      public @Nullable String getStrict(Locale locale, String key)
      Description copied from interface: TranslationPackage
      Translates the given key into the requested locale, returning null if no translation exists.
      Specified by:
      getStrict in interface TranslationPackage
      Parameters:
      locale - the locale to find a value for
      key - the key to find a match for
      Returns:
      the translation, or null if the translation doesn't exist.
    • getResolvedTranslations

      public Map<String,String> getResolvedTranslations(Locale locale)
      Resolves a whole locale directly from the per-locale bundles rather than the interface default's per-key getStrict(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:
      getResolvedTranslations in interface TranslationPackage
      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

      public @Nullable TranslationMap getTranslationsFor(String key)
      Specified by:
      getTranslationsFor in interface TranslationPackage
      Returns:
      a map of all the translations available for a given key.
    • getNote

      public @Nullable String getNote(String key)
      Description copied from interface: TranslationPackage
      Returns the editorial note associated with the given key, or null if there is none. Notes are per-key metadata keyed by the raw key string.
      Specified by:
      getNote in interface TranslationPackage
    • getNotes

      public Map<String,String> getNotes()
      Specified by:
      getNotes in interface TranslationPackage
      Returns:
      an unmodifiable view of all notes, keyed by the raw key string. Never null; may be empty.
    • createDiff

      public TranslationPackageDiff createDiff()
      Description copied from interface: TranslationPackage
      Creates 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:
      createDiff in interface TranslationPackage
      Returns:
      a new TranslationPackageDiff.
    • getAllTranslations

      public Iterator<Translation> getAllTranslations()
      Specified by:
      getAllTranslations in interface TranslationPackage
      Returns:
      an iterator that goes through all the translations. Does not include defined keys that have no translations.