org.workingfrog.i18n.util
Class Localizer

java.lang.Object
  extended byorg.workingfrog.i18n.util.Localizer

public class Localizer
extends java.lang.Object

This class manages the resource bundle files needed to localize the application. All registered resource files are searched in order to find the localization of a given string.

Author:
Jean-Hugues de Raigniac

Constructor Summary
Localizer()
           
 
Method Summary
static void addResource(java.lang.String binding, java.lang.String resourceName)
          The method adds a new resource under the given name.
static boolean containsKey(java.lang.String binding, java.lang.String key)
           
static java.util.Locale getCurrentLocale()
          The method returns the current locale.
static java.util.Locale[] getLocales(java.lang.Object object)
           
static java.util.Map getResourcesFor(java.util.Locale locale)
          The method returns all resources for the given locale.
static javax.swing.KeyStroke getShortcut(java.lang.String binding, java.lang.String key)
          This function returns a localized menu shortcut key to the specified key.
static java.lang.String localize(java.lang.String binding, java.lang.String key)
          This function returns a localized string corresponding to the specified key.
static void switchCurrentLocale(java.util.Locale locale)
          The method changes the current Locale to the given one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Localizer

public Localizer()
Method Detail

switchCurrentLocale

public static void switchCurrentLocale(java.util.Locale locale)
The method changes the current Locale to the given one. The resources bound to the given Locale are also preloaded. If the given Locale is not already registered, it will be registered automatically.

See Also:
Locale

getCurrentLocale

public static java.util.Locale getCurrentLocale()
The method returns the current locale.

Returns:
The current locale

getResourcesFor

public static java.util.Map getResourcesFor(java.util.Locale locale)
The method returns all resources for the given locale.

Parameters:
locale - Resources are searched for this locale.
Returns:
Map of all resources and their names bound to the given locale.

addResource

public static void addResource(java.lang.String binding,
                               java.lang.String resourceName)
                        throws java.util.MissingResourceException
The method adds a new resource under the given name. The resource is preloaded and bound to a given Locale or to every registered Locale, if no Locale is given.

Parameters:
binding - Name under which the resource should be registered.
resourceName - Name of the resource to be registered.
Throws:
java.util.MissingResourceException - when resourceName is invalid

localize

public static java.lang.String localize(java.lang.String binding,
                                        java.lang.String key)
This function returns a localized string corresponding to the specified key. Searching goes through all registered ResourceBundles

Parameters:
binding - bundle binding
key - String to be localized
Returns:
First localization for the given string found in the registered ResourceBundles, the key itself if no localization has been found.

containsKey

public static boolean containsKey(java.lang.String binding,
                                  java.lang.String key)

getShortcut

public static javax.swing.KeyStroke getShortcut(java.lang.String binding,
                                                java.lang.String key)
This function returns a localized menu shortcut key to the specified key.

Parameters:
binding - Name of resource to be searched.
key - Shortcut string to be localized.
Returns:
Localized KeyStroke object.

getLocales

public static java.util.Locale[] getLocales(java.lang.Object object)