org.af.commons
Class Localizer

java.lang.Object
  extended by org.af.commons.Localizer

public class Localizer
extends Object

A Singleton that manages ResourceBundles and allows changing Locales and Languages.


Method Summary
 void addResourceBundle(String name)
          Adds a ResourceBundle to this Localizer.
 void clearAllAddedBundles()
          Deletes all currently set messages and the cached list of added bundles, but will add the afcommons bundle at the end.
static Localizer getInstance()
          Get singleton instance.
 String getLanguage()
          Returns the abbreviation of the current language, e.g.
 Locale getLocale()
          Returns the currently used Locale of the localizer.
 String getString(String key)
          Get a localized string, probably for some widget or message.
 void setLanguage(String lang)
          Sets the current language, e.g.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Localizer getInstance()
Get singleton instance.

Returns:
The singleton instance

addResourceBundle

public void addResourceBundle(String name)
Adds a ResourceBundle to this Localizer. If keys were already defined, they are overwritten.

Parameters:
name - Name of the ResourceBundle. Has to be on the class path.

getLocale

public Locale getLocale()
Returns the currently used Locale of the localizer. At the moment this is Locale.getDefault().

Returns:
The currently used Locale of the localizer.

getLanguage

public String getLanguage()
Returns the abbreviation of the current language, e.g. "en".

Returns:
The abbreviation of the current language.

setLanguage

public void setLanguage(String lang)
Sets the current language, e.g. "en". Note that this also sets the locale, will add the afcommons resource bundle and will reload all previously added resource bundles.

Parameters:
lang - Abbreviation of language.

getString

public String getString(String key)
                 throws MissingResourceException
Get a localized string, probably for some widget or message.

Parameters:
key - Key to access the string.
Returns:
Localized version of message string
Throws:
MissingResourceException - if no object for the given key can be found

clearAllAddedBundles

public void clearAllAddedBundles()
Deletes all currently set messages and the cached list of added bundles, but will add the afcommons bundle at the end.