public class LocalizableSupport extends 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 String |
bundleName
The resource bundle classname.
|
protected ClassLoader |
classLoader
The classloader to use to create the resource bundle.
|
protected Locale |
locale
The current locale.
|
protected LocaleGroup |
localeGroup
The locale group to which this object belongs.
|
protected Locale |
usedLocale
The locale in use.
|
Constructor and Description |
---|
LocalizableSupport(String s)
Same as LocalizableSupport(s, null).
|
LocalizableSupport(String s,
Class cls)
Same as LocalizableSupport(cls, null).
|
LocalizableSupport(String s,
Class cls,
ClassLoader cl)
Same as LocalizableSupport(cls, null).
|
LocalizableSupport(String s,
ClassLoader cl)
Creates a new Localizable object.
|
protected LocaleGroup localeGroup
protected String bundleName
protected ClassLoader classLoader
protected Locale locale
protected Locale usedLocale
public LocalizableSupport(String s, Class cls)
public LocalizableSupport(String s, Class cls, ClassLoader cl)
public LocalizableSupport(String s)
public LocalizableSupport(String s, 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(Locale l)
Localizable.setLocale(Locale)
.setLocale
in interface Localizable
l
- The locale to set.public Locale getLocale()
Localizable.getLocale()
.getLocale
in interface Localizable
public void setLocaleGroup(LocaleGroup lg)
ExtendedLocalizable.setLocaleGroup(LocaleGroup)
.public LocaleGroup getLocaleGroup()
ExtendedLocalizable.getLocaleGroup()
.public void setDefaultLocale(Locale l)
ExtendedLocalizable.setDefaultLocale(Locale)
.
Later invocations of the instance methods will lead to update the
resource bundle used.public Locale getDefaultLocale()
ExtendedLocalizable.getDefaultLocale()
.public String formatMessage(String key, 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 Locale getCurrentLocale()
protected boolean setUsedLocale()
public ResourceBundle getResourceBundle()
protected boolean hasNextResourceBundle(int i)
protected ResourceBundle lookupResourceBundle(String bundle, Class theClass)
protected ResourceBundle getResourceBundle(int i)
public String getString(String key) throws MissingResourceException
MissingResourceException
public int getInteger(String key) throws MissingResourceException
key
- a key of the resource bundleMissingResourceException
- if key is not the name of a resourcepublic int getCharacter(String key) throws MissingResourceException
MissingResourceException
Copyright © 2000–2023 Apache Software Foundation. All rights reserved.