Package arc.util
Class I18NBundle
java.lang.Object
arc.util.I18NBundle
A
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
.
- All bundles for the same group of resources share a common base bundle. This base bundle acts as the root and is the last fallback in case none of its children was able to respond to a request.
- The first level contains changes between different languages. Only the differences between a language and the language of
the base bundle need to be handled by a language-specific
I18NBundle
. - The second level contains changes between different countries that use the same language. Only the differences between a
country and the country of the language bundle need to be handled by a country-specific
I18NBundle
. - The third level contains changes that don't have a geographic reason (e.g. changes that where made at some point in time
like
PREEURO
where the currency of come countries changed. The country bundle would return the current currency (Euro) and thePREEURO
variant bundle would return the old currency (e.g. DM for Germany).
- BaseName (base bundle)
- BaseName_de (german language bundle)
- BaseName_fr (french language bundle)
- BaseName_de_DE (bundle with Germany specific resources in german)
- BaseName_de_CH (bundle with Switzerland specific resources in german)
- BaseName_fr_CH (bundle with Switzerland specific resources in french)
- BaseName_de_DE_PREEURO (bundle with Germany specific resources in german of the time before the Euro)
- BaseName_fr_FR_PREEURO (bundle with France specific resources in french of the time before the Euro)
It's also possible to create variants for languages or countries. This can be done by just skipping the country or language abbreviation: BaseName_us__POSIX or BaseName__DE_PREEURO. But it's not allowed to circumvent both language and country: BaseName___VARIANT is illegal.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic I18NBundle
createBundle
(Fi baseFileHandle) Creates a new bundle using the specifiedbaseFileHandle
, the default locale and the default encoding "UTF-8".static I18NBundle
createBundle
(Fi baseFileHandle, String encoding) Creates a new bundle using the specifiedbaseFileHandle
andencoding
; the default locale is used.static I18NBundle
createBundle
(Fi baseFileHandle, Locale locale) Creates a new bundle using the specifiedbaseFileHandle
andlocale
; the default encoding "UTF-8" is used.static I18NBundle
createBundle
(Fi baseFileHandle, Locale locale, String encoding) Creates a new bundle using the specifiedbaseFileHandle
,locale
andencoding
.static I18NBundle
Returns an empty bundle with no keys.void
Sets the value of all localized strings to String placeholder so hardcoded, unlocalized values can be easily spotted.Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur.formatFloat
(String key, float value, int places) Format, but with a number with fixed decimal places.formatString
(String string, Object... args) final String
Gets a string for the given key from this bundle or one of its parents.Returns the string for this given key, or def.getKeys()
Returns all keys in this bundle.Returns the locale of this bundle.getNotNull
(String key) static boolean
Returns the flag indicating whether to use the simplified message pattern syntax (default is false).boolean
Checks whether a specified key is present in this bundle.void
setProperties
(ObjectMap<String, String> properties) static void
setSimpleFormatter
(boolean enabled) Sets the flag indicating whether to use the simplified message pattern.
-
Constructor Details
-
I18NBundle
public I18NBundle()
-
-
Method Details
-
getSimpleFormatter
public static boolean getSimpleFormatter()Returns the flag indicating whether to use the simplified message pattern syntax (default is false). -
setSimpleFormatter
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 methodscreateBundle
. -
createEmptyBundle
Returns an empty bundle with no keys. -
createBundle
Creates a new bundle using the specifiedbaseFileHandle
, the default locale and the default encoding "UTF-8".- Parameters:
baseFileHandle
- the file handle to the base of the bundle- Returns:
- a bundle for the given base file handle and the default locale
- Throws:
NullPointerException
- ifbaseFileHandle
isnull
MissingResourceException
- if no bundle for the specified base file handle can be found
-
createBundle
Creates a new bundle using the specifiedbaseFileHandle
andlocale
; the default encoding "UTF-8" is used.- Parameters:
baseFileHandle
- the file handle to the base of the bundlelocale
- the locale for which a bundle is desired- Returns:
- a bundle for the given base file handle and locale
- Throws:
NullPointerException
- ifbaseFileHandle
orlocale
isnull
MissingResourceException
- if no bundle for the specified base file handle can be found
-
createBundle
Creates a new bundle using the specifiedbaseFileHandle
andencoding
; the default locale is used.- Parameters:
baseFileHandle
- the file handle to the base of the bundleencoding
- the charter encoding- Returns:
- a bundle for the given base file handle and locale
- Throws:
NullPointerException
- ifbaseFileHandle
orencoding
isnull
MissingResourceException
- if no bundle for the specified base file handle can be found
-
createBundle
Creates a new bundle using the specifiedbaseFileHandle
,locale
andencoding
.- Parameters:
baseFileHandle
- the file handle to the base of the bundlelocale
- the locale for which a bundle is desiredencoding
- the charter encoding- Returns:
- a bundle for the given base file handle and locale
- Throws:
NullPointerException
- ifbaseFileHandle
,locale
orencoding
isnull
MissingResourceException
- if no bundle for the specified base file handle can be found
-
getLocale
Returns the locale of this bundle. This method can be used after a call tocreateBundle()
to determine whether the resource bundle returned really corresponds to the requested locale or is a fallback.- Returns:
- the locale of this bundle
-
get
Gets a string for the given key from this bundle or one of its parents.- Parameters:
key
- the key for the desired string- Returns:
- the string for the given key or the key surrounded by
???
if it cannot be found - Throws:
NullPointerException
- ifkey
isnull
-
get
Returns the string for this given key, or def. -
getOrNull
-
getNotNull
-
getKeys
Returns all keys in this bundle. Does not check parent bundles. -
getProperties
- Returns:
- the internal property map. Can be modified.
-
setProperties
-
has
Checks whether a specified key is present in this bundle. -
format
Gets the string with the specified key from this bundle or one of its parent after replacing the given arguments if they occur.- Parameters:
key
- the key for the desired stringargs
- the arguments to be replaced in the string associated to the given key.- Returns:
- the string for the given key formatted with the given arguments
- Throws:
NullPointerException
- ifkey
isnull
MissingResourceException
- if no string for the given key can be found
-
formatString
-
formatFloat
Format, but with a number with fixed decimal places. -
debug
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. -
getParent
- Returns:
- the parent bundle.
-