I18NBundle provides Locale-specific resources loaded from property files. A bundle contains a number of
named resources, whose names and values are Strings. A bundle may have a parent bundle, and when a resource is not
found in a bundle, the parent bundle is searched for the resource. If the fallback mechanism reaches the base bundle and still
can't find the resource it throws a MissingResourceException.
I18NBundle.I18NBundle.PREEURO where the currency of come countries changed. The country bundle would return the current currency (Euro)
and the PREEURO variant bundle would return the old currency (e.g. DM for Germany).PropertiesUtils
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static boolean | |
| private TextFormatter | formatter
The formatter used for argument replacement. |
| private Locale | locale
The locale for this bundle. |
| private I18NBundle | parent
The parent of this |
| private ObjectMap | properties
The properties for this bundle. |
| private static boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static boolean | |
| public static I18NBundle | Returns: a bundle for the given base file handle and the default localethe file handle to the base of the bundle baseFileHandle)Creates a new bundle using the specified |
| public static I18NBundle | Returns: a bundle for the given base file handle and localethe file handle to the base of the bundle baseFileHandle, Locale the locale for which a bundle is desired locale)Creates a new bundle using the specified |
| public static I18NBundle | Returns: a bundle for the given base file handle and localethe file handle to the base of the bundle baseFileHandle, String the character encoding encoding)Creates a new bundle using the specified |
| public static I18NBundle | Returns: a bundle for the given base file handle and localethe file handle to the base of the bundle baseFileHandle, Locale the locale for which a bundle is desired locale, String the character encoding encoding)Creates a new bundle using the specified |
| private static I18NBundle | |
| public void | |
| public String | Returns: the string for the given key formatted with the given argumentsthe key for the desired string key, Object... the arguments to be replaced in the string associated to the given key. args)Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur. |
| public String | Returns: the string for the given key or the key surrounded by??? if it cannot be found and
getExceptionOnMissingKey() returns falsethe key for the desired string key)Gets a string for the given key from this bundle or one of its parents. |
| private static List | Returns: aList of candidate Locales for the given localethe locale for which a resource bundle is desired locale)Returns a |
| public static boolean | getExceptionOnMissingKey()
Returns the flag indicating whether to throw a |
| private static Locale | Returns: aLocale for the fallback search, or null if no further fallback search is needed.the locale)Locale for which createBundle has been unable to find any resource bundles
(except for the base bundle)Returns a |
| public Locale | |
| public static boolean | getSimpleFormatter()
Returns the flag indicating whether to use the simplified message pattern syntax (default is false). |
| public Set | Returns: a key set of loaded properties. Never null, might be an empty setGets a key set of loaded properties. |
| protected void | |
| private static I18NBundle | |
| private static I18NBundle | loadBundleChain(FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales, int candidateIndex, I18NBundle baseBundle)
|
| public static void | setExceptionOnMissingKey(boolean enabled)
Sets the flag indicating whether to throw a |
| private void | |
| public static void | setSimpleFormatter(boolean enabled)
Sets the flag indicating whether to use the simplified message pattern. |
| private static FileHandle | Returns: the file handle for the bundlethe file handle to the base of the bundle baseFileHandle, Locale the locale for which a resource bundle should be loaded locale)Converts the given |
| DEFAULT_ENCODING | back to summary |
|---|---|
| private static final String DEFAULT_ENCODING | |
| exceptionOnMissingKey | back to summary |
|---|---|
| private static boolean exceptionOnMissingKey | |
| formatter | back to summary |
|---|---|
| private TextFormatter formatter The formatter used for argument replacement. | |
| locale | back to summary |
|---|---|
| private Locale locale The locale for this bundle. | |
| parent | back to summary |
|---|---|
| private I18NBundle parent The parent of this | |
| properties | back to summary |
|---|---|
| private ObjectMap<String, String> properties The properties for this bundle. | |
| simpleFormatter | back to summary |
|---|---|
| private static boolean simpleFormatter | |
| I18NBundle | back to summary |
|---|---|
| public I18NBundle() | |
| checkFileExistence | back to summary |
|---|---|
| private static boolean checkFileExistence(FileHandle fh) | |
| createBundle | back to summary |
|---|---|
| public static I18NBundle createBundle(FileHandle baseFileHandle) Creates a new bundle using the specified
| |
| createBundle | back to summary |
|---|---|
| public static I18NBundle createBundle(FileHandle baseFileHandle, Locale locale) Creates a new bundle using the specified
| |
| createBundle | back to summary |
|---|---|
| public static I18NBundle createBundle(FileHandle baseFileHandle, String encoding) Creates a new bundle using the specified
| |
| createBundle | back to summary |
|---|---|
| public static I18NBundle createBundle(FileHandle baseFileHandle, Locale locale, String encoding) Creates a new bundle using the specified
| |
| createBundleImpl | back to summary |
|---|---|
| private static I18NBundle createBundleImpl(FileHandle baseFileHandle, Locale locale, String encoding) | |
| debug | back to summary |
|---|---|
| public void debug(String placeholder) Sets the value of all localized strings to String placeholder so hardcoded, unlocalized values can be easily spotted. The I18NBundle won't be able to reset values after calling debug and should only be using during testing. | |
| format | back to summary |
|---|---|
| public String format(String key, Object... args) Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur.
| |
| get | back to summary |
|---|---|
| public String get(String key) Gets a string for the given key from this bundle or one of its parents.
| |
| getCandidateLocales | back to summary |
|---|---|
| private static List Returns a The sequence of the candidate locales also corresponds to the runtime resource lookup path (also known as the parent chain), if the corresponding resource bundles for the candidate locales exist and their parents are not defined by loaded resource bundles themselves. The last element of the list is always the root locale, meaning that the base bundle is the terminal of the parent chain.
If the given locale is equal to
This implementation returns a
Locale(language, country, variant)
Locale(language, country)
Locale(language)
Locale.ROOT
where language, country and variant are the language, country and variant values of
the given locale, respectively. Locales where the final component values are empty strings are omitted.
For example, if the given base name is "Messages" and the given
Locale("ja", "", "XX")
Locale("ja")
Locale.ROOT
is returned. And if the resource bundles for the "ja" and "" Locales are found, then the runtime resource
lookup path (parent chain) is:
Messages_ja -> Messages
| |
| getExceptionOnMissingKey | back to summary |
|---|---|
| public static boolean getExceptionOnMissingKey() Returns the flag indicating whether to throw a | |
| getFallbackLocale | back to summary |
|---|---|
| private static Locale getFallbackLocale(Locale locale) Returns a
This method returns the default
| |
| getLocale | back to summary |
|---|---|
| public Locale getLocale() Returns the locale of this bundle. This method can be used after a call to
| |
| getSimpleFormatter | back to summary |
|---|---|
| public static boolean getSimpleFormatter() Returns the flag indicating whether to use the simplified message pattern syntax (default is false). This flag is always assumed to be true on GWT backend. | |
| keys | back to summary |
|---|---|
| public Set Gets a key set of loaded properties. Keys will be copied into a new set and returned. | |
| load | back to summary |
|---|---|
| protected void load(Reader reader) throws IOException Load the properties from the specified reader.
| |
| loadBundle | back to summary |
|---|---|
| private static I18NBundle loadBundle(FileHandle baseFileHandle, String encoding, Locale targetLocale) | |
| loadBundleChain | back to summary |
|---|---|
| private static I18NBundle loadBundleChain(FileHandle baseFileHandle, String encoding, List<Locale> candidateLocales, int candidateIndex, I18NBundle baseBundle) | |
| setExceptionOnMissingKey | back to summary |
|---|---|
| public static void setExceptionOnMissingKey(boolean enabled) Sets the flag indicating whether to throw a | |
| setLocale | back to summary |
|---|---|
| private void setLocale(Locale locale) Sets the bundle locale. This method is private because a bundle can't change the locale during its life. | |
| setSimpleFormatter | back to summary |
|---|---|
| public static void setSimpleFormatter(boolean enabled) Sets the flag indicating whether to use the simplified message pattern. The flag must be set before calling the factory
methods | |
| toFileHandle | back to summary |
|---|---|
| private static FileHandle toFileHandle(FileHandle baseFileHandle, Locale locale) Converts the given
This implementation returns the baseFileHandle.name() + "_" + language + "_" + country + "_" + variant + ".properties"where language, country and variant are the language, country and variant values of
locale, respectively. Final component values that are empty Strings are omitted along with the preceding '_'.
If all of the values are empty strings, then baseFileHandle.name() is returned with ".properties" appended.
| |