org.homeunix.thecave.moss.i18n
Class Translator

java.lang.Object
  extended by org.homeunix.thecave.moss.i18n.Translator
Direct Known Subclasses:
BuddiTranslator

public class Translator
extends java.lang.Object


Field Summary
protected  java.util.Properties translations
           
 
Constructor Summary
Translator(java.lang.String translationSuffix)
           
 
Method Summary
 java.lang.String get(java.lang.Enum<?> key)
          Returns the translation, based on the given TranslateKey.
 java.lang.String get(java.lang.String key)
          Returns the translation, based on the given string.
 java.util.List<java.lang.String> getLanguageList(java.lang.String translation)
          Returns a list of languages to try to load, based on the given language.
 void loadLanguages(java.io.File languageDirectory, java.util.List<java.lang.String> languages)
          We try to load the languages specified in the list, in order of index.
 void loadLanguages(java.io.File jarFile, java.lang.String resourcePath, java.util.List<java.lang.String> languages)
          We try to load the languages specified in the list, in order of index.
 void loadLanguages(java.lang.String resourcePath, java.util.List<java.lang.String> languages)
          We try to load the languages specified in the list, in order of index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

translations

protected final java.util.Properties translations
Constructor Detail

Translator

public Translator(java.lang.String translationSuffix)
Method Detail

loadLanguages

public void loadLanguages(java.lang.String resourcePath,
                          java.util.List<java.lang.String> languages)
We try to load the languages specified in the list, in order of index. This allows languages to be a subset of another; for instance, if the entire program is translated into English, but the other languages or localizations are incomplete, you can load English first, and then load the localizations to overwrite all translated items. This gives us extreme flexibility and maintainability when creating locales - to change a single term, you only have to create a .lang file with that one term changed.

Parameters:
resourcePath - The path to the languages, inside of the current .jar file. Should be absolute (i.e., starting with a slash).
languages - A list of languages to load, in order of index.
translationSuffix - The suffix of the translation files, including the period if applicable.

loadLanguages

public void loadLanguages(java.io.File jarFile,
                          java.lang.String resourcePath,
                          java.util.List<java.lang.String> languages)
We try to load the languages specified in the list, in order of index. This allows languages to be a subset of another; for instance, if the entire program is translated into English, but the other languages or localizations are incomplete, you can load English first, and then load the localizations to overwrite all translated items. This gives us extreme flexibility and maintainability when creating locales - to change a single term, you only have to create a .lang file with that one term changed.

Parameters:
jarFile - The jar file to load the translations from.
resourcePath - The path to the languages, inside of the current .jar file. Should be absolute (i.e., starting with a slash).
languages - A list of languages to load, in order of index.
translationSuffix - The suffix of the translation files, including the period if applicable.

loadLanguages

public void loadLanguages(java.io.File languageDirectory,
                          java.util.List<java.lang.String> languages)
We try to load the languages specified in the list, in order of index. This allows languages to be a subset of another; for instance, if the entire program is translated into English, but the other languages or localizations are incomplete, you can load English first, and then load the localizations to overwrite all translated items. This gives us extreme flexibility and maintainability when creating locales - to change a single term, you only have to create a .lang file with that one term changed.

Parameters:
languageDirectory - The path to the languages, on the current file system.
languages - A list of languages to load, in order of index.
translationSuffix - The suffix of the translation files, including the period if applicable.

getLanguageList

public java.util.List<java.lang.String> getLanguageList(java.lang.String translation)
Returns a list of languages to try to load, based on the given language. This allows us to load partial translations and differences (dialects). This list can be passed directly to the loadLanguages() method in Translator.

Parameters:
translation - The localized language
Returns:

get

public java.lang.String get(java.lang.String key)
Returns the translation, based on the given string.

Parameters:
key - The key to translate
Returns:
The translation in currently loaded language

get

public java.lang.String get(java.lang.Enum<?> key)
Returns the translation, based on the given TranslateKey.

Parameters:
key - The key to translate
Returns:
The translation in currently loaded language