eu.livotov.tpt.i18n
Class TM

java.lang.Object
  extended by eu.livotov.tpt.i18n.TM
All Implemented Interfaces:
java.io.Serializable

public class TM
extends java.lang.Object
implements java.io.Serializable

Translation manager - a front-end for toolkit-enabled application for getting locale-dependant strings for application messages. This static class should be used for both - translation queries and loading/changing dictionary files.

Typical use:

  • In application startup, load translation files for each language you want to support. Translation files are regular java .properties files you use for SWING application internationalization: TM.getDictionary().loadWords(...);
  • Use TM.get ( "xxx" ) instead of hardcoded string anywhere in your application code. xxx is an entry key. The method will return a valid translated text for the current application instance language or the key itself, if no translation for the current language is found.

    For more information please see the corresponding chapter in developer documentation.

    See Also:
    Serialized Form

    Field Summary
    protected static java.util.HashMap<java.lang.String,Dictionary> translationDictionaries
              Repository of dictionaries for all applications that are running.
     
    Constructor Summary
    TM()
               
     
    Method Summary
    static java.lang.String get(com.vaadin.Application app, java.lang.String key, java.lang.Object... params)
              Provides the translated string by the given key
    static java.lang.String get(java.lang.String key, java.lang.Object... params)
              Provides the translated string by the given key.
    static Dictionary getDictionary()
              Provides the dictionary object, used for all instances of the current application.
    static Dictionary getDictionary(com.vaadin.Application app)
              Provides the dictionary object, used for all instances of the specified application
    static void setDefaultLanguage(java.lang.String lang)
              Proxy method for easy setting the default language for the current app dictionary
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Field Detail

    translationDictionaries

    protected static java.util.HashMap<java.lang.String,Dictionary> translationDictionaries
    Repository of dictionaries for all applications that are running. Note, that single dictionary is used for all instances (sessions) of such application.

    Constructor Detail

    TM

    public TM()
    Method Detail

    get

    public static java.lang.String get(java.lang.String key,
                                       java.lang.Object... params)
    Provides the translated string by the given key. ote, that this method only works if your application extends ToolkitPlusApplication. For plain ITMill Toolkit applications please use another method, that accepts application instance as a parameter.

    Parameters:
    key - key to get string for
    params - - set of String.format parameters to parse
    Returns:
    key translation, for the current application instance language

    get

    public static java.lang.String get(com.vaadin.Application app,
                                       java.lang.String key,
                                       java.lang.Object... params)
    Provides the translated string by the given key

    Parameters:
    app - application to look for the keys in
    key - key to get string for
    params - - set of String.format parameters to parse
    Returns:
    key translation, for the current application instance language

    setDefaultLanguage

    public static void setDefaultLanguage(java.lang.String lang)
    Proxy method for easy setting the default language for the current app dictionary

    Parameters:
    lang -

    getDictionary

    public static Dictionary getDictionary()
    Provides the dictionary object, used for all instances of the current application. Note, that this method only works if your application extends ToolkitPlusApplication. For plain ITMill Toolkit applications please use another method, that accepts application instance as a parameter.

    Returns:
    dictionary object

    getDictionary

    public static Dictionary getDictionary(com.vaadin.Application app)
    Provides the dictionary object, used for all instances of the specified application

    Parameters:
    app - application
    Returns:
    dictionary object