ehsbe CommonsTM
Version 1.1.0rc3

com.ehsbe.commons.gui.wizard
Class TranslatorAdapter

java.lang.Object
  extended by com.ehsbe.commons.gui.wizard.TranslatorAdapter
All Implemented Interfaces:
Translator

public class TranslatorAdapter
extends Object
implements Translator

General purpose translator, which might be used to do l10n lookups for a task. It uses either resource bundles for lookups or appropriate component properties.

Version:
$Revision: 495 $
Author:
Jens Elkner

Constructor Summary
TranslatorAdapter(Class<?> clazz, String name, Locale locale)
          Creates a new translator.
TranslatorAdapter(JComponent wizardPage)
          Deduces a translator from the given component.
 
Method Summary
 Locale getLocale()
          Get the locale currently used for translations.
 void setLocale(Locale locale)
          Set the locale, which should be use for translations.
 String xlate(String prefix, String name)
          Translate the given name wrt. to the given prefix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TranslatorAdapter

public TranslatorAdapter(Class<?> clazz,
                         String name,
                         Locale locale)
Creates a new translator.

Parameters:
clazz - class to use to determine the package name, which contains the resource bundle in its /res/ sub directory.
name - the name of the resource bundle to lookup.
locale - initial locale to use.
See Also:
Misc.getResourcePath(Object)

TranslatorAdapter

public TranslatorAdapter(JComponent wizardPage)
Deduces a translator from the given component. It is expected, that at least the name of the component has been set to a none-null value.

NOTE: This variant ignores any locale settings made here since it queries the given component properties. Except the components name, all values are obtained by asking the component's client properties using the given prefix + name as key. If it contains no value for the Task.PREFIX_TT, its JComponent.getToolTipText() method will be used.

Parameters:
wizardPage - component to use to create the translator.
See Also:
Component.getName(), JComponent.getClientProperty(Object)
Method Detail

getLocale

public Locale getLocale()
Get the locale currently used for translations.

Specified by:
getLocale in interface Translator
Returns:
null if not set and default locale is used, the locale in use otherwise.

setLocale

public void setLocale(Locale locale)
Set the locale, which should be use for translations.

Specified by:
setLocale in interface Translator
Parameters:
locale - Locale to set. If null, the default locale should be used.
See Also:
Locale.getDefault()

xlate

public String xlate(String prefix,
                    String name)
Translate the given name wrt. to the given prefix. E.g. one may form the lookup key wrt. a ResourceBundle or HashMap by a simple concatenation of the prefix and the name.

One should never let an exception pass or throw here. Instead catch and log.

Specified by:
xlate in interface Translator
Parameters:
prefix - key prefix. Usually a purpose indicator.
name - key name. Usually an instance ID.
Returns:
a translation (might be null).

ehsbe CommonsTM
Version 1.1.0rc3

Copyright ©2005-2009 EHSBE, Walther-Rathenau-Str. 58, 39104 Magdeburg, Sachsen-Anhalt, Germany. All Rights Reserved.