Notes
All messages and menu-entries in JabRef are stored in escaped form like "This_is_a_message". This message
serves as key inside the l10n properties files that hold the translation for many languages. When a message
is accessed, it needs to be unescaped and possible parameters that can appear in a message need to be filled with
values.
This implementation loads the appropriate language by importing all keys/values from the correct bundle and stores
them in unescaped form inside a LocalizationBundle which provides fast access because it caches the key-value
pairs.
The access to this is given by the functions lang(String, Object. and
that developers should use whenever they use strings for the e.g. GUI that need to be translatable.
| Modifier and Type | Class and Description |
|---|---|
| private static class | Localization.
A bundle for caching localized strings. |
| Modifier and Type | Field and Description |
|---|---|
| private static Locale | |
| private static Localization. | |
| pack-priv static final String |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static Map | Returns: Lookup map for the baseBundle.JabRef language bundle with keys and values for translations. baseBundle)Helper function to create a Map from the key/value pairs of a bundle. |
| private static void | createResourceBundles(Locale
Localization to use. locale)Creates and caches the language bundles used in JabRef for a particular language. |
| public static Localization. | Returns: The internally cashed bundle.Returns the messages bundle, e.g. to load FXML files correctly translated. |
| public static String | |
| private static String | Returns: The final message with replaced parameters.The bundle,LocalizationBundle which is usually Localization#localizedMessages.The lookup key. key, String... The parameters that should be inserted into the message params)This looks up a key in the bundle and replaces parameters %0, ..., %9 with the respective params given. |
| public static void | setLanguage(Language
Language identifier like "en", "de", etc. language)Sets the language and loads the appropriate translations. |
| locale | back to summary |
|---|---|
| private static Locale locale | |
| localizedMessages | back to summary |
|---|---|
| private static Localization. | |
| RESOURCE_PREFIX | back to summary |
|---|---|
| pack-priv static final String RESOURCE_PREFIX | |
| Localization | back to summary |
|---|---|
| private Localization() | |
| createLookupMap | back to summary |
|---|---|
| private static Map Helper function to create a Map from the key/value pairs of a bundle.
| |
| createResourceBundles | back to summary |
|---|---|
| private static void createResourceBundles(Locale locale) Creates and caches the language bundles used in JabRef for a particular language. This function first loads
correct version of the "escaped" bundles that are given in
| |
| getMessages | back to summary |
|---|---|
| public static Localization. Returns the messages bundle, e.g. to load FXML files correctly translated.
| |
| lang | back to summary |
|---|---|
| public static String lang(String key, Object... params) Public access to all messages that are not menu-entries | |
| lookup | back to summary |
|---|---|
| private static String lookup(@NonNull Localization. This looks up a key in the bundle and replaces parameters %0, ..., %9 with the respective params given. Note that the keys are the "unescaped" strings from the bundle property files.
| |
| setLanguage | back to summary |
|---|---|
| public static void setLanguage(Language language) Sets the language and loads the appropriate translations. Note, that this function should be called before any other function of this class.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Map |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | containsKey(String key)
Overrides java. Determines whether the given |
| public Enumeration | |
| public final Object | handleGetObject(@NonNull String key)
Implements abstract java. Gets an object for the given key from this resource bundle. |
| protected Set | handleKeySet()
Overrides java. Returns a |
| lookup | back to summary |
|---|---|
| private final Map<String, String> lookup | |
| LocalizationBundle | back to summary |
|---|---|
| pack-priv LocalizationBundle(Map<String, String> lookupMap) | |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(String key) Overrides java. Doc from java. Determines whether the given
| |
| getKeys | back to summary |
|---|---|
| public Enumeration Implements abstract java. Doc from java. Returns an enumeration of the keys.
| |
| handleGetObject | back to summary |
|---|---|
| public final Object handleGetObject(@NonNull String key) Implements abstract java. Doc from java. Gets an object for the given key from this resource bundle. Returns null if this resource bundle does not contain an object for the given key.
| |
| handleKeySet | back to summary |
|---|---|
| protected Set Overrides java. Doc from java. Returns a The default implementation returns a
| |