|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object vmm.core.I18n
public class I18n
This class implements internationalization by providing facilites for getting strings from properties files. A single default property file is used, but other files can be added. All files that have been added are searched in the reverse of the order in which they were added. The default file is searched last. This class does not generate errors; if a property file cannot be found for a specified resource name, it is ignored. If no value can be found for a specified key, then either null or the key itself is returned rather than generating an error, depending on which method was called.
The default properties file name is "strings.properties" in the directory vmm/resources. Property files for other locales should be given names such as, for example, strings_fr.properties, ' and stored in the same location.
Constructor Summary | |
---|---|
I18n()
|
Method Summary | |
---|---|
static boolean |
addFile(java.lang.String fileName)
Adds a file to the list of property files that are searched when looking for a string. |
static java.util.Locale |
getLocale()
Returns the locale that is currently being used by this class. |
static void |
setLocale(java.util.Locale locale)
Sets a locale to use when searching for property files. |
static void |
setLocale(java.util.Locale locale,
boolean reload)
Sets a locale to use when searching for property files. |
static java.lang.String |
tr(java.lang.String key)
Finds the value associated with a specified key. |
static java.lang.String |
tr(java.lang.String key,
java.lang.Object... arg)
A convenience method that calls MessageFormat.format(tr(key), arg...). |
static java.lang.String |
trIfFound(java.lang.String key)
Does the same thing as I18n.tr(key), except that if no value is found for the key, the return value is null. |
static java.lang.String |
trIfFound(java.lang.String key,
java.lang.Object... arg)
Does the same thing as I18n.tr(key,arg...), except that if no value is found for the key, the return value is null. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public I18n()
Method Detail |
---|
public static void setLocale(java.util.Locale locale)
public static void setLocale(java.util.Locale locale, boolean reload)
reload
argument is
false, then this will not affect property files that have already been loaded; if reload
is true, then all property files that have already been loaded are discarded and new ones
are loaded using the new locale.
If the locale is null (which is the default), then the default locale will be used --
which is almost always what you want to do! It is not usually necessary to call this method. It could
be used, for example, to give the user a choice of languages.
public static java.util.Locale getLocale()
setLocale(Locale)
, then the default
locale for the Java Virtual Machine is returned.public static boolean addFile(java.lang.String fileName)
fileName
- The resource name for the property file to be added. The bundle is
obtained using the getBundle
method in the ResourceBundle
class.
If the file name is null, nothing is done. If the file name is a duplicate of
a name that was used previously, the bundle is NOT added to the search path for
a second time. Note that the file name should be given as a resource name, such
as "vmm.resources.strings", that can be used to locate the resource, rather than as an actual file name.
public static java.lang.String tr(java.lang.String key)
public static java.lang.String tr(java.lang.String key, java.lang.Object... arg)
key
- String to be translated, by calling tr(key). The translation can contain
substrings of the form {0}, {1}, {2}...arg
- The strings (or other objects) that are to be substituted for {0}, {1}, {2}, ...
public static java.lang.String trIfFound(java.lang.String key)
tr(String)
public static java.lang.String trIfFound(java.lang.String key, java.lang.Object... arg)
tr(String, Object[])
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |