nl.knowledgeplaza.util
Class Internationalization

java.lang.Object
  extended by nl.knowledgeplaza.util.Internationalization

public class Internationalization
extends java.lang.Object

Translate a id to a locale specific value by searching multiple locations in this order: - Classname.internationalization.xml - internationalization.xml in the package of the class - internationalization.xml anywhere on the classpath (TODO: all internationalization.xml files anywhere in the classpath, random order) - resource bundle of the class (old style resources) Each translation consists of thee parameters: - context, the object where in the translation takes place - id, the id of the translation - locale, for which is translated The context is used to determine which internationalization.xml files should be examined for the indicated id / locale. But if the examined internationalization.xml file is more generic (package or classpath level), it is allowed to append the context to the id like: id@context. In this way the context can always be a factor when searching for an id. Usage will show that it is convenient to have some more technical translations place in these files also, for example a color. These translations may / should / could be placed in a ConfigurationProperties setup, but that would make things not easier to maintain. So "language-less" translates are also supported, and also its shorter form: translation nodes with a translate attribute. Some examples: Beoordelingsmodule voorkeuren Beoordelingsmodule voorkeuren 4FDF4F When this class is used to generate XML and newlines (
) must be inserted into the ending XML, use this: ... ...

Author:
user

Constructor Summary
Internationalization()
           
 
Method Summary
static java.util.List generateLocalePermutations(java.util.Locale locale)
          Translate
static Internationalization get()
           
 java.util.Locale getDefaultLocale()
          DefaultLocale
static Internationalization getInternationalization()
          Singleton
 void setDefaultLocale(java.util.Locale value)
           
 java.lang.String translate(java.lang.Object context, java.lang.String id)
          Translate, this method tries to find files where the translation could be, based on the context.
 java.lang.String translate(java.lang.Object context, java.lang.String id, java.util.Locale locale)
          Translate, this method tries to find files where the translation could be, based on the context.
 java.lang.String translate(java.lang.Object context, java.lang.String id, java.util.Locale locale, java.lang.String defaultTranslation)
          Translate, this method tries to find files where the translation could be, based on the context.
 boolean translateExists(java.lang.Object context, java.lang.String id)
          Translate, this method tries to find files where the translation could be, based on the context.
 boolean translateExists(java.lang.Object context, java.lang.String id, java.util.Locale locale)
          Translate, this method tries to find files where the translation could be, based on the context.
 boolean translateExists(java.lang.Object context, java.lang.String id, java.util.Locale locale, java.lang.String defaultTranslation)
          Translate, this method tries to find files where the translation could be, based on the context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Internationalization

public Internationalization()
Method Detail

getInternationalization

public static Internationalization getInternationalization()
Singleton

Returns:

get

public static Internationalization get()

getDefaultLocale

public java.util.Locale getDefaultLocale()
DefaultLocale


setDefaultLocale

public void setDefaultLocale(java.util.Locale value)

translate

public java.lang.String translate(java.lang.Object context,
                                  java.lang.String id)
Translate, this method tries to find files where the translation could be, based on the context. This method uses the default locale! The first hit is returned.

Parameters:
context -
id -
Returns:

translate

public java.lang.String translate(java.lang.Object context,
                                  java.lang.String id,
                                  java.util.Locale locale)
Translate, this method tries to find files where the translation could be, based on the context. The first hit is returned.

Parameters:
context -
id -
localeId -
Returns:

translate

public java.lang.String translate(java.lang.Object context,
                                  java.lang.String id,
                                  java.util.Locale locale,
                                  java.lang.String defaultTranslation)
Translate, this method tries to find files where the translation could be, based on the context. The first hit is returned.

Parameters:
context -
id -
localeId -
defaultTranslation -
Returns:

translateExists

public boolean translateExists(java.lang.Object context,
                               java.lang.String id)
Translate, this method tries to find files where the translation could be, based on the context. This method uses the default locale! The first hit is returned.

Parameters:
context -
id -
Returns:

translateExists

public boolean translateExists(java.lang.Object context,
                               java.lang.String id,
                               java.util.Locale locale)
Translate, this method tries to find files where the translation could be, based on the context. The first hit is returned.

Parameters:
context -
id -
localeId -
Returns:

translateExists

public boolean translateExists(java.lang.Object context,
                               java.lang.String id,
                               java.util.Locale locale,
                               java.lang.String defaultTranslation)
Translate, this method tries to find files where the translation could be, based on the context. The first hit is returned.

Parameters:
context -
id -
localeId -
defaultTranslation -
Returns:

generateLocalePermutations

public static java.util.List generateLocalePermutations(java.util.Locale locale)
Translate

Parameters:
id -
locale -
Returns:


Copyright © 2010. All Rights Reserved.