public class I18NBundle
extends java.lang.Object
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
Constructor and Description |
---|
I18NBundle() |
Modifier and Type | Method and Description |
---|---|
static I18NBundle |
createBundle(FileHandle baseFileHandle)
Creates a new bundle using the specified
baseFileHandle , the default locale and the default encoding "UTF-8". |
static I18NBundle |
createBundle(FileHandle baseFileHandle,
java.util.Locale locale)
Creates a new bundle using the specified
baseFileHandle and locale ; the default encoding "UTF-8"
is used. |
static I18NBundle |
createBundle(FileHandle baseFileHandle,
java.util.Locale locale,
java.lang.String encoding)
Creates a new bundle using the specified
baseFileHandle , locale and encoding . |
static I18NBundle |
createBundle(FileHandle baseFileHandle,
java.lang.String encoding)
Creates a new bundle using the specified
baseFileHandle and encoding ; the default locale is used. |
java.lang.String |
format(java.lang.String key,
java.lang.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.
|
java.lang.String |
get(java.lang.String key)
Gets a string for the given key from this bundle or one of its parents.
|
java.util.Locale |
getLocale()
Returns the locale of this bundle.
|
static boolean |
getSimpleFormatter()
Returns the flag indicating whether to use the simplified message pattern syntax (default is false).
|
protected void |
load(java.io.Reader reader)
Load the properties from the specified reader.
|
static void |
setSimpleFormatter(boolean enabled)
Sets the flag indicating whether to use the simplified message pattern.
|
public static boolean getSimpleFormatter()
public static void setSimpleFormatter(boolean enabled)
createBundle
. Notice that this method has no effect on the GWT backend where
it's always assumed to be true.public static I18NBundle createBundle(FileHandle baseFileHandle)
baseFileHandle
, the default locale and the default encoding "UTF-8".baseFileHandle
- the file handle to the base of the bundlejava.lang.NullPointerException
- if baseFileHandle
is null
java.util.MissingResourceException
- if no bundle for the specified base file handle can be foundpublic static I18NBundle createBundle(FileHandle baseFileHandle, java.util.Locale locale)
baseFileHandle
and locale
; the default encoding "UTF-8"
is used.baseFileHandle
- the file handle to the base of the bundlelocale
- the locale for which a bundle is desiredjava.lang.NullPointerException
- if baseFileHandle
or locale
is null
java.util.MissingResourceException
- if no bundle for the specified base file handle can be foundpublic static I18NBundle createBundle(FileHandle baseFileHandle, java.lang.String encoding)
baseFileHandle
and encoding
; the default locale is used.baseFileHandle
- the file handle to the base of the bundleencoding
- the charter encodingjava.lang.NullPointerException
- if baseFileHandle
or encoding
is null
java.util.MissingResourceException
- if no bundle for the specified base file handle can be foundpublic static I18NBundle createBundle(FileHandle baseFileHandle, java.util.Locale locale, java.lang.String encoding)
baseFileHandle
, locale
and encoding
.baseFileHandle
- the file handle to the base of the bundlelocale
- the locale for which a bundle is desiredencoding
- the charter encodingjava.lang.NullPointerException
- if baseFileHandle
, locale
or encoding
is
null
java.util.MissingResourceException
- if no bundle for the specified base file handle can be foundprotected void load(java.io.Reader reader) throws java.io.IOException
reader
- the readerjava.io.IOException
- if an error occurred when reading from the input stream.public java.util.Locale getLocale()
createBundle()
to determine whether
the resource bundle returned really corresponds to the requested locale or is a fallback.public final java.lang.String get(java.lang.String key)
key
- the key for the desired stringjava.lang.NullPointerException
- if key
is null
java.util.MissingResourceException
- if no string for the given key can be foundpublic java.lang.String format(java.lang.String key, java.lang.Object... args)
key
- the key for the desired stringargs
- the arguments to be replaced in the string associated to the given key.java.lang.NullPointerException
- if key
is null
java.util.MissingResourceException
- if no string for the given key can be found