translator
Class Translator

java.lang.Object
  extended by translator.Translator

public class Translator
extends java.lang.Object

Provides internationalization by translating messages. Requires an appropriate resource file containing the message translations.

Version:
1.1 2000-01-11
Author:
Guido Rößling ( roessling@acm.org)

Field Summary
static java.util.Locale DEFAULT_LOCALE
          The current locale, responsible for element translation
(package private)  java.lang.String resourceBaseName
          The base name of the resource to load
 
Constructor Summary
Translator()
           
Translator(java.lang.String resourceName, java.util.Locale targetLocale)
           
 
Method Summary
 java.util.Locale getCurrentLocale()
          Retrieve the current locale.
 TranslatableGUIElement getGenerator()
          returns the current TranslatableGUIElement instance for this Translator
 ExtendedResourceManagement getResourceBundle()
          Return the current ExtendedResourceBundle for translation purposes
 void listUnknownResources()
          Lists the unknown resources for all known locales to the standard output
 void setResourceBaseName(java.lang.String resourceName)
           
 void setTranslatorLocale(java.util.Locale targetLocale)
          Set the current locale to the one passed in This will also translate all GUI components if the state of the Translator is 'initialized'
 void setTranslatorLocale(java.util.Locale targetLocale, java.util.Vector<java.lang.String> additionalResources)
          Set the current locale to the one passed in This will also translate all GUI components if the state of the Translator is 'initialized'
 java.lang.String translateMessage(java.lang.String messageKey)
          Convenience wrapper the translated message of key messageKey.
 java.lang.String translateMessage(java.lang.String messageKey, java.lang.Object[] messageParams)
          Return the translated message of key messageKey using the message params Internally invokes generateMessage(messageKey, null);
 java.lang.String translateMessage(java.lang.String messageKey, java.lang.Object[] messageParams, boolean warnOnError)
          Return the translated message of key messageKey using the message params
 java.lang.String translateMessage(java.lang.String messageKey, java.lang.String... params)
          Return the translated message of key messageKey using the message params Internally invokes generateMessage(messageKey, null);
 java.lang.String translateMessageWithoutParameterExpansion(java.lang.String messageKey)
          Convenience wrapper the translated message of key messageKey.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOCALE

public static final java.util.Locale DEFAULT_LOCALE
The current locale, responsible for element translation


resourceBaseName

java.lang.String resourceBaseName
The base name of the resource to load

Constructor Detail

Translator

public Translator()

Translator

public Translator(java.lang.String resourceName,
                  java.util.Locale targetLocale)
Method Detail

getCurrentLocale

public java.util.Locale getCurrentLocale()
Retrieve the current locale. May be used to check whether elements have to be translated, e.g. this is not needed if getCurrentLocale().equals(new Locale)

Returns:
the current locale object

getGenerator

public TranslatableGUIElement getGenerator()
returns the current TranslatableGUIElement instance for this Translator

Returns:
the current TranslatableGUIElement handler

getResourceBundle

public ExtendedResourceManagement getResourceBundle()
Return the current ExtendedResourceBundle for translation purposes

Returns:
the current resource bundle

listUnknownResources

public void listUnknownResources()
Lists the unknown resources for all known locales to the standard output


setTranslatorLocale

public void setTranslatorLocale(java.util.Locale targetLocale)
Set the current locale to the one passed in This will also translate all GUI components if the state of the Translator is 'initialized'

Parameters:
targetLocale - the new locale for the application. If null, uses Locale.US instead

setTranslatorLocale

public void setTranslatorLocale(java.util.Locale targetLocale,
                                java.util.Vector<java.lang.String> additionalResources)
Set the current locale to the one passed in This will also translate all GUI components if the state of the Translator is 'initialized'

Parameters:
targetLocale - the new locale for the application. If null, uses Locale.US instead
additionalResources - the file names (without ".xx_YY") for additional language resources to be read in

setResourceBaseName

public void setResourceBaseName(java.lang.String resourceName)

translateMessageWithoutParameterExpansion

public java.lang.String translateMessageWithoutParameterExpansion(java.lang.String messageKey)
Convenience wrapper the translated message of key messageKey. Internally invokes generateMessage(messageKey, null);

Parameters:
messageKey - the key of the message to be displayed
See Also:
translateMessage(String, Object[], boolean)

translateMessage

public java.lang.String translateMessage(java.lang.String messageKey)
Convenience wrapper the translated message of key messageKey. Internally invokes generateMessage(messageKey, null);

Parameters:
messageKey - the key of the message to be displayed
See Also:
translateMessage(String, Object[], boolean)

translateMessage

public java.lang.String translateMessage(java.lang.String messageKey,
                                         java.lang.Object[] messageParams)
Return the translated message of key messageKey using the message params Internally invokes generateMessage(messageKey, null);

Parameters:
messageKey - the key of the message to be displayed
messageParams - the values to be substituted into the message.
See Also:
translateMessage(String, Object[], boolean)

translateMessage

public java.lang.String translateMessage(java.lang.String messageKey,
                                         java.lang.String... params)
Return the translated message of key messageKey using the message params Internally invokes generateMessage(messageKey, null);

Parameters:
messageKey - the key of the message to be displayed
params - the values to be substituted into the message.
See Also:
translateMessage(String, Object[], boolean)

translateMessage

public java.lang.String translateMessage(java.lang.String messageKey,
                                         java.lang.Object[] messageParams,
                                         boolean warnOnError)
Return the translated message of key messageKey using the message params

Parameters:
messageKey - the key of the message to be displayed
messageParams - the values to be substituted into the message.
warnOnError - if true, log warnings due to invalid accesses or unavailable keys.