org.xnap.commons.i18n
Class I18nFactory
java.lang.Object
org.xnap.commons.i18n.I18nFactory
public class I18nFactory
extends java.lang.Object
Factory class that creates and caches I18n instances.
Given a
Class
object the factory looks up the resource bundle
responsible for handling message translations. The bundle is returned with
an
I18n
object wrapped around it, which provides the translation
methods. The lookup is described at
getI18n(Class,String)
.
Use the factory for creating
I18n
objects to make sure no
extraneous objects are created.
- Felix Berger
- Tammo van Lessen
- Steffen Pingel
static String | DEFAULT_BASE_NAME - Default name for Message bundles, is "i18n.Messages".
|
static String | PROPS_FILENAME - Filename of the poperties file that contains the i18n properties,
is "i18n.properties".
|
DEFAULT_BASE_NAME
public static final String DEFAULT_BASE_NAME
Default name for Message bundles, is "i18n.Messages".
PROPS_FILENAME
public static final String PROPS_FILENAME
Filename of the poperties file that contains the i18n properties,
is "i18n.properties".
getI18n
public static I18n getI18n(Class clazz)
getI18n
public static I18n getI18n(Class clazz,
String baseName)
Returns the I18n instance responsible for translating messages in
the package specified by
clazz
.
Lookup works by iterating upwards in the package hierarchy: First the
internal cache is asked for an I18n object for a package, otherwise the
algorithm looks for an
i18n.properties
file in the
package. The properties file is queried for a key named
basename
whose value should be the fully qualified
resource/class name of the resource bundle, e.g
org.xnap.commons.i18n.Messages
.
If after the first iteration no I18n instance has been found, a second
search begins by looking for resource bundles having the name
baseName
.
clazz
- the package hierarchy of the clazz and its class loader
are used for resolving and loading the resource bundlebaseName
- the name of the underlying resource bundle
- created or cached
I18n
instance