public class LocalizableSupport extends java.lang.Object implements Localizable
For example, to implement Localizable, the following code can be used:
package mypackage; ... public class MyClass implements Localizable { // This code fragment requires a file named // 'mypackage/resources/Messages.properties', or a // 'mypackage.resources.Messages' class which extends // java.util.ResourceBundle, accessible using the current // classpath. LocalizableSupport localizableSupport = new LocalizableSupport("mypackage.resources.Messages"); public void setLocale(Locale l) { localizableSupport.setLocale(l); } public Local getLocale() { return localizableSupport.getLocale(); } public String formatMessage(String key, Object[] args) { return localizableSupport.formatMessage(key, args); } }The algorithm for the Locale lookup in a LocalizableSupport object is:
Note: if no group is specified a LocalizableSupport object belongs to a default group common to each instance of LocalizableSupport.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
bundleName
The resource bundle classname.
|
protected java.lang.ClassLoader |
classLoader
The classloader to use to create the resource bundle.
|
protected java.util.Locale |
locale
The current locale.
|
protected LocaleGroup |
localeGroup
The locale group to which this object belongs.
|
protected java.util.Locale |
usedLocale
The locale in use.
|
Constructor and Description |
---|
LocalizableSupport(java.lang.String s)
Same as LocalizableSupport(s, null).
|
LocalizableSupport(java.lang.String s,
java.lang.Class cls)
Same as LocalizableSupport(cls, null).
|
LocalizableSupport(java.lang.String s,
java.lang.Class cls,
java.lang.ClassLoader cl)
Same as LocalizableSupport(cls, null).
|
LocalizableSupport(java.lang.String s,
java.lang.ClassLoader cl)
Creates a new Localizable object.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
formatMessage(java.lang.String key,
java.lang.Object[] args)
Implements
Localizable.formatMessage(String,Object[]) . |
int |
getCharacter(java.lang.String key) |
protected java.util.Locale |
getCurrentLocale() |
java.util.Locale |
getDefaultLocale()
Implements
ExtendedLocalizable.getDefaultLocale() . |
int |
getInteger(java.lang.String key)
Returns the integer mapped with the given string
|
java.util.Locale |
getLocale()
Implements
Localizable.getLocale() . |
LocaleGroup |
getLocaleGroup()
Implements
ExtendedLocalizable.getLocaleGroup() . |
java.util.ResourceBundle |
getResourceBundle()
Here for backwards compatability
|
protected java.util.ResourceBundle |
getResourceBundle(int i) |
java.lang.String |
getString(java.lang.String key) |
protected boolean |
hasNextResourceBundle(int i) |
protected java.util.ResourceBundle |
lookupResourceBundle(java.lang.String bundle,
java.lang.Class theClass) |
void |
setDefaultLocale(java.util.Locale l)
Implements
ExtendedLocalizable.setDefaultLocale(Locale) . |
void |
setLocale(java.util.Locale l)
Implements
Localizable.setLocale(Locale) . |
void |
setLocaleGroup(LocaleGroup lg)
Implements
ExtendedLocalizable.setLocaleGroup(LocaleGroup) . |
protected boolean |
setUsedLocale()
returns true if the locale is different from the previously
used locale.
|
protected LocaleGroup localeGroup
protected java.lang.String bundleName
protected java.lang.ClassLoader classLoader
protected java.util.Locale locale
protected java.util.Locale usedLocale
public LocalizableSupport(java.lang.String s, java.lang.Class cls)
public LocalizableSupport(java.lang.String s, java.lang.Class cls, java.lang.ClassLoader cl)
public LocalizableSupport(java.lang.String s)
public LocalizableSupport(java.lang.String s, java.lang.ClassLoader cl)
s
- must be the name of the class to use to get the appropriate
resource bundle given the current locale.cl
- is the classloader used to create the resource bundle,
or null.ResourceBundle
public void setLocale(java.util.Locale l)
Localizable.setLocale(Locale)
.setLocale
in interface Localizable
l
- The locale to set.public java.util.Locale getLocale()
Localizable.getLocale()
.getLocale
in interface Localizable
public void setLocaleGroup(LocaleGroup lg)
ExtendedLocalizable.setLocaleGroup(LocaleGroup)
.public LocaleGroup getLocaleGroup()
ExtendedLocalizable.getLocaleGroup()
.public void setDefaultLocale(java.util.Locale l)
ExtendedLocalizable.setDefaultLocale(Locale)
.
Later invocations of the instance methods will lead to update the
resource bundle used.public java.util.Locale getDefaultLocale()
ExtendedLocalizable.getDefaultLocale()
.public java.lang.String formatMessage(java.lang.String key, java.lang.Object[] args)
Localizable.formatMessage(String,Object[])
.formatMessage
in interface Localizable
key
- The key used to retreive the message from the resource
bundle.args
- The objects that compose the message.protected java.util.Locale getCurrentLocale()
protected boolean setUsedLocale()
public java.util.ResourceBundle getResourceBundle()
protected boolean hasNextResourceBundle(int i)
protected java.util.ResourceBundle lookupResourceBundle(java.lang.String bundle, java.lang.Class theClass)
protected java.util.ResourceBundle getResourceBundle(int i)
public java.lang.String getString(java.lang.String key) throws java.util.MissingResourceException
java.util.MissingResourceException
public int getInteger(java.lang.String key) throws java.util.MissingResourceException
key
- a key of the resource bundlejava.util.MissingResourceException
- if key is not the name of a resourcepublic int getCharacter(java.lang.String key) throws java.util.MissingResourceException
java.util.MissingResourceException
Copyright © 2022 Apache Software Foundation. All Rights Reserved.