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:
- if a Locale has been set by a call to setLocale(), use this Locale, else,
- if a Locale has been set by a call to the setDefaultLocale() method of a LocalizableSupport object in the current LocaleGroup, use this Locale, else,
- use the object returned by Locale.getDefault() (and set by Locale.setDefault()).
This offers the possibility to have a different Locale for each object, a Locale for a group of object and/or a Locale for the JVM instance.
Note: if no group is specified a LocalizableSupport object belongs to a default group common to each instance of LocalizableSupport.
@author Stephane Hillion
@version $Id: LocalizableSupport.java,v 1.7 2004/08/18 07:14:45 vhardy Exp $