net.sf.jaxodraw.util
Class JaxoLanguage

java.lang.Object
  extended by net.sf.jaxodraw.util.JaxoLanguage

public final class JaxoLanguage
extends Object

A convenience class to deal with I18N issues.

Since:
2.0

Field Summary
static String ENGLISH
          English.
static String FRENCH
          French.
static String GERMAN
          German.
static String ITALIAN
          Italian.
static String SPANISH
          Spanish.
 
Method Summary
static String bundleMessage(String key, String bundleId, Object argument)
          Translates the given string into the current default language.
static String bundleMessage(String key, String bundleId, Object[] arguments)
          Translates the given string.
static String bundleMessage(String key, String bundleId, Object argument1, Object argument2)
          Translates the given string into the current default language.
static String bundleTranslate(String akey, String abundleId)
          Translates the given string into the current default language.
static String getLanguageFor(int mode)
          Returns the language string for the given mode.
static String[] knownLanguages()
          Returns the languages known by this version of JaxoDraw.
static String label(String key)
          Translate 'key' as a label (typically, by appending ": " to the default translation).
static void languageChanged(String language)
          Updates the current locale and associated language bundle.
static Locale locale()
          Locale corresponding to the current language.
static String message(String key, Object argument)
          Translates the given string into the current default language, interpolating a single argument.
static String message(String key, Object[] arguments)
          Translates the given string into the current default language, interpolating arguments.
static String message(String key, Object argument1, Object argument2)
          Translates the given string into the current default language, interpolating two arguments.
static void registerBundle(Class<?> c)
          Register a custom bundle for the class c.
static void registerBundle(Class<?> c, JaxoDictionary d)
          Register a custom bundle for the class c, ('c' may also be in the core).
static void removeBundle(Class<?> c)
          Removes the previously registered bundle for the class c.
static String translate(String key)
          Translates the given string into the current default language.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENGLISH

public static final String ENGLISH
English.

See Also:
Constant Field Values

GERMAN

public static final String GERMAN
German.

See Also:
Constant Field Values

FRENCH

public static final String FRENCH
French.

See Also:
Constant Field Values

ITALIAN

public static final String ITALIAN
Italian.

See Also:
Constant Field Values

SPANISH

public static final String SPANISH
Spanish.

See Also:
Constant Field Values
Method Detail

registerBundle

public static void registerBundle(Class<?> c)
Register a custom bundle for the class c. The name of the class, ie c.getName(), is registered as an identifier, which can be used in the methods bundleMessage() and bundleTranslate() to translate messages. The bundle must be named 'language' and will be looked for in c.getName()/resources/properties (using the class loader of 'c') where dots in the class name are replaced by '/'.

Parameters:
c - The class for which a bundle should be registered.

registerBundle

public static void registerBundle(Class<?> c,
                                  JaxoDictionary d)
Register a custom bundle for the class c, ('c' may also be in the core). Also setup the dictionary to translate with the given bundle.

Parameters:
c - The class for which a bundle should be registered.
d - The dictionary to bind to the given class.
See Also:
registerBundle(Class)

removeBundle

public static void removeBundle(Class<?> c)
Removes the previously registered bundle for the class c. The name of the class, ie c.getName(), is used as the key.

Parameters:
c - The class for which a bundle should be removed.

languageChanged

public static void languageChanged(String language)
Updates the current locale and associated language bundle.

Parameters:
language - The new language.

locale

public static Locale locale()
Locale corresponding to the current language.

Returns:
The current locale.

label

public static String label(String key)
Translate 'key' as a label (typically, by appending ": " to the default translation).

Parameters:
key - The key to translate.
Returns:
The translation.

message

public static String message(String key,
                             Object argument)
Translates the given string into the current default language, interpolating a single argument. Equivalent to message(String,Object[]) with second argument new Object[] { argument }.

Parameters:
key - The key to translate.
argument - An object.
Returns:
The translated string.

bundleMessage

public static String bundleMessage(String key,
                                   String bundleId,
                                   Object argument)
Translates the given string into the current default language.

Parameters:
key - The key to translate.
bundleId - An identifier for an external language bundle, if null, the default JaxoDraw bundle will be used.
argument - An object.
Returns:
The translated string.
See Also:
message(String,Object)

message

public static String message(String key,
                             Object argument1,
                             Object argument2)
Translates the given string into the current default language, interpolating two arguments. Equivalent to message(String,Object[]) with second argument new Object[] { argument1, argument2 }.

Parameters:
key - The key to translate.
argument1 - A first object.
argument2 - A second object.
Returns:
The translated string.

bundleMessage

public static String bundleMessage(String key,
                                   String bundleId,
                                   Object argument1,
                                   Object argument2)
Translates the given string into the current default language.

Parameters:
key - The key to translate.
bundleId - An identifier for an external language bundle, if null, the default JaxoDraw bundle will be used.
argument1 - A first object.
argument2 - A second object.
Returns:
The translated string.
See Also:
message(String,Object,Object)

message

public static String message(String key,
                             Object[] arguments)
Translates the given string into the current default language, interpolating arguments.

If arguments is not empty, the translation of key is used as a MessageFormat pattern, the arguments array is then used as the argument for Format.format(Object).

See the language.properties for notes on the parsing of MessageFormat patterns.

If however, arguments is empty, the key translation is not parsed as MessageFormat pattern (That way, the message methods can be used generically.)

By convention, the keys for MessageFormat pattern (and only them) contain percentage signs, followed by a number (starting from zero, as MessageFormat), to denote the occurrence of arguments (e.g. JaxoIO.read%0ReadFailed=File "{0}" could not be read.). Then:

Parameters:
key - The key to translate.
arguments - An array of objects (arguments for MessageFormat).
Returns:
The translated string.

bundleMessage

public static String bundleMessage(String key,
                                   String bundleId,
                                   Object[] arguments)
Translates the given string.

Parameters:
key - The key to translate.
bundleId - An identifier for an external language bundle, if null, the default JaxoDraw bundle will be used.
arguments - An array of objects (arguments for MessageFormat).
Returns:
The translated string.
See Also:
message(String,Object[])

translate

public static String translate(String key)
Translates the given string into the current default language.

Parameters:
key - The key to translate.
Returns:
The translated string, or an empty string if key itself is empty.

bundleTranslate

public static String bundleTranslate(String akey,
                                     String abundleId)
Translates the given string into the current default language.

Parameters:
akey - The key to translate.
abundleId - An identifier for an external language bundle, if null, the default JaxoDraw bundle will be used.
Returns:
The translated string, or an empty string if key itself is empty.

getLanguageFor

public static String getLanguageFor(int mode)
Returns the language string for the given mode.

Parameters:
mode - The language mode as defined in JaxoConstants.
Returns:
The corresponding language string or empty if mode is not a language mode.

knownLanguages

public static String[] knownLanguages()
Returns the languages known by this version of JaxoDraw.

Returns:
The known languages.


Copyright © 2003-2011 The JaxoDraw team. All Rights Reserved.