Interface TranslationPackage
- All Known Subinterfaces:
MutableTranslationPackage
- All Known Implementing Classes:
BasicTranslationPackage, ClientLocalizationManager, ClientLocalizationManagerImpl, ComponentTranslationPanel.DelegateTranslationPackage, DesignerLocalizationManager, ImmutableTranslationPackage, TranslationPackageDiff
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionCreates an empty, modifiable diff that respects the same rules as this translation package.Translates the given key into the requested locale.@Nullable Iterator<Translation> @Nullable Collection<String> @Nullable KeyHashRuleThe 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 every translation for the requested locale, following the locale fallback chain (e.g.es_MXthenes) so a regional-variant request still picks up translations stored only under the base language.@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.
-
Field Details
-
NOTES_IDENTIFIER
Reserved pseudo-locale identifier under which per-key editorial notes are stored rather than a real locale's translations. The translation archive formats use it as a file/worksheet name (see theiopackage).- See Also:
-
BASE_LOCALE
The language in which translation keys are authored: English. Keys are effectively the source-language strings, so every package implicitly "contains" this locale even when no bundle /// is stored for it. Concretely, it is:
- always included in
getAvailableLocales(); - treated as defined by
isDefined(String, Locale)as soon as the key exists in the index, with no separate translation required; and - the locale assumed when a
nulllocale is passed to a bundle lookup.
This is a fixed constant, not a per-package setting. Note that lookups for other locales fall back to the raw key text, not to this locale's translations.
- always included in
-
-
Method Details
-
getKeyHashRule
@Nullable KeyHashRule getKeyHashRule()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. -
getAvailableLocales
Collection<Locale> getAvailableLocales()- Returns:
- the locales for which translations are available. This always includes
BASE_LOCALE, the language in which keys are defined.
-
isDefined
Returns whether the key is defined in the package. A key can be defined without any particular translations. -
isDefined
-
get
-
getStrict
Translates the given key into the requested locale, returning null if no translation exists.- 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.
-
getTranslationsFor
- Returns:
- a map of all the translations available for a given key.
-
getAvailableKeys
@Nullable Collection<String> getAvailableKeys()- Returns:
- all the defined keys.
-
getNote
-
getNotes
-
createDiff
TranslationPackageDiff createDiff()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.- Returns:
- a new
TranslationPackageDiff.
-
getAllTranslations
@Nullable Iterator<Translation> getAllTranslations()- Returns:
- an iterator that goes through all the translations. Does not include defined keys that have no translations.
-
getResolvedTranslations
Resolves every translation for the requested locale, following the locale fallback chain (e.g.
es_MXthenes) so a regional-variant request still picks up translations stored only under the base language. A more-specific locale's translation overrides its base-language fallback, and keys with no translation anywhere in the chain are omitted, so every value in the returned map is non-null.This default implementation is expressed purely in terms of
getAvailableKeys()andgetStrict(Locale, String); implementations that can resolve a whole locale more cheaply (for example by reading their per-locale storage directly) should override it.- 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.
-