com.denova.ui
Class LocaleTranslator

java.lang.Object
  |
  +--com.denova.ui.LocaleTranslator

public class LocaleTranslator
extends java.lang.Object

I18n for strings.

Author:
DeNova Copyright © 1997-2007 DeNova All rights reserved worldwide.

Field Summary
static java.lang.String DefaultExtension
           
static java.lang.String DutchResources
           
static java.lang.String EnglishResources
           
static java.lang.String FrenchResources
           
static java.lang.String GermanResources
           
static java.lang.String ItalianResources
           
static java.lang.String JapaneseResources
           
static java.lang.String LocaleLog
           
static java.lang.String PolishResources
           
static java.lang.String PortugueseResources
           
static java.lang.String SpanishResources
           
 
Constructor Summary
LocaleTranslator(java.lang.String extension)
          Constructor to configure localized resources.
 
Method Summary
 java.lang.String getActiveLanguage()
          Get the active language (for example, english, spanish).
 java.lang.String getCountry()
          Get the 2 letter ISO standard code for the active country.
 java.lang.String getDefaultLanguage()
          Returns the default language to use if the user's default language isn't available.
 java.lang.String getLanguage()
          Get the 2 letter ISO standard code for the active language.
 java.lang.String getLanguageExtension()
          Returns the extension for language resource files.
 java.lang.String getString(java.lang.String key)
          Get the value associated with key from the active language's resource.
 java.lang.String getString(java.lang.String key, java.lang.String variable)
          Get the value associated with key from the active language's resource.
 java.lang.String getString(java.lang.String key, java.lang.String[] variables)
          Get the value associated with key from the active language's resource.
 void setDefaultLanguage(java.lang.String newDefaultLanguage)
          Set the default language to use if the user's default language isn't available.
 void setLanguageExtension(java.lang.String newFileExtension)
          Set the file extension to use for the language files.
 void setLocale(java.lang.String newLanguage, java.lang.String newCountry)
          Set the language and country using the 2 letter ISO standard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EnglishResources

public static final java.lang.String EnglishResources
See Also:
Constant Field Values

SpanishResources

public static final java.lang.String SpanishResources
See Also:
Constant Field Values

GermanResources

public static final java.lang.String GermanResources
See Also:
Constant Field Values

FrenchResources

public static final java.lang.String FrenchResources
See Also:
Constant Field Values

PolishResources

public static final java.lang.String PolishResources
See Also:
Constant Field Values

JapaneseResources

public static final java.lang.String JapaneseResources
See Also:
Constant Field Values

PortugueseResources

public static final java.lang.String PortugueseResources
See Also:
Constant Field Values

ItalianResources

public static final java.lang.String ItalianResources
See Also:
Constant Field Values

DutchResources

public static final java.lang.String DutchResources
See Also:
Constant Field Values

DefaultExtension

public static final java.lang.String DefaultExtension
See Also:
Constant Field Values

LocaleLog

public static final java.lang.String LocaleLog
See Also:
Constant Field Values
Constructor Detail

LocaleTranslator

public LocaleTranslator(java.lang.String extension)
Constructor to configure localized resources.

"extension" should be set to the file extension for your resources names. instantiating this class with the extension and including the files, the localized phrases can be displayed.

Currently supported languages (the filename follows):
    English  (english)
    Dutch  (dutch)
    French  (french)
    German  (german)
    Italian  (italian)
    Japanese  (japanese)
    Polish  (polish)
    Portuguese  (portuguese)
    Spanish  (spanish)

You should create a key=value pair file for each language. The filename for each language must use the same extension, and that extension may not be .properties. Each filename is the name of the language in all lower case.

Parameters:
extension -
Method Detail

setLocale

public void setLocale(java.lang.String newLanguage,
                      java.lang.String newCountry)
Set the language and country using the 2 letter ISO standard.

If you're going to vary the language, you should do so at the very beginning of the application.

Parameters:
newLanguage - new locale
newCountry - new locale

getLanguage

public java.lang.String getLanguage()
Get the 2 letter ISO standard code for the active language.

Returns:
language

getCountry

public java.lang.String getCountry()
Get the 2 letter ISO standard code for the active country.

Returns:
country

setDefaultLanguage

public void setDefaultLanguage(java.lang.String newDefaultLanguage)
Set the default language to use if the user's default language isn't available.

If the language you set isn't available, then English is used.

Parameters:
newDefaultLanguage - new default language

getDefaultLanguage

public java.lang.String getDefaultLanguage()
Returns the default language to use if the user's default language isn't available.

Returns:
default language

getActiveLanguage

public java.lang.String getActiveLanguage()
Get the active language (for example, english, spanish).

Returns:
active language

setLanguageExtension

public void setLanguageExtension(java.lang.String newFileExtension)
Set the file extension to use for the language files.

Parameters:
newFileExtension - new language extension

getLanguageExtension

public java.lang.String getLanguageExtension()
Returns the extension for language resource files.

Returns:
language extension

getString

public java.lang.String getString(java.lang.String key)
Get the value associated with key from the active language's resource.

If the active language doesn't have a matching key, then it returns the key from the English resources (e.g., english.extension).

Parameters:
key -
Returns:
string

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String variable)
Get the value associated with key from the active language's resource.

Replace any %VARIABLE% strings with the variable.

If the active language doesn't have a matching key, then it returns the key from the English resources (e.g., english.extension).

Parameters:
key - attribute of the av pair of strings
variable - a string to use to replace %VARIABLE%
Returns:
value of the matching key with the variables substituting %VARIABLE% literals.

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String[] variables)
Get the value associated with key from the active language's resource.

Replace any %VARIABLE% strings with the list of variables. If there are multiple variables, then they are used in sequential order. If there are more %VARIABLE% literals than in the variables list, then the last variable in the list is used for the remaining literals.

If the active language doesn't have a matching key, then it returns the key from the English resources (e.g., english.extension).

Parameters:
key - attribute of the av pair of strings
variables - one or more strings to use to replace %VARIABLE%
Returns:
value of the matching key with the variables substituting %VARIABLE% literals.