Package org.cesilko.rachota.core
Class Translator
java.lang.Object
org.cesilko.rachota.core.Translator
Translator class providing localization.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static PropertyResourceBundle
Resource bundle representing appropriate dictionary of translations.private static final String
The path of the dictionary as used by Rachota for storing dictionaries.private static boolean
Flag to indicate whether or not the dictionary has been looked up.private static final String
The default dictionary to use with Rachota if none is found for your current locale.private static PropertyResourceBundle
Resource bundle representing fallback/default dictionary of translations.private static final Logger
Logger used by the Translator class to log errors. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
Finds appropriate dictionary based on set country and language locales.static char
getMnemonic
(String word) Returns mnemonic char found in translated word.static String
getTranslation
(String word) Returns translation of given word in default language.private static String
getTranslation
(String word, boolean removeAnds) Returns translation of given word in default language.static String
getTranslation
(String word, String[] substitutions) Returns translation of given word in default language and replaces arguments.private static String
lookupWord
(String key) Returns the translated string associated with the provided key either in the active dictionary, or the fallback dictionary.private static String
removeAnds
(String word) Removes the & characters in the provided string.private static void
Sets up the fallback dictionary.
-
Field Details
-
dictionary
Resource bundle representing appropriate dictionary of translations. -
fallbackDictionary
Resource bundle representing fallback/default dictionary of translations. -
log
Logger used by the Translator class to log errors. -
DICTIONARY_PATH_FORMAT
The path of the dictionary as used by Rachota for storing dictionaries.- See Also:
-
FALLBACK_DICTIONARY
The default dictionary to use with Rachota if none is found for your current locale.- See Also:
-
dictionaryLookupDone
private static boolean dictionaryLookupDoneFlag to indicate whether or not the dictionary has been looked up.
-
-
Constructor Details
-
Translator
public Translator()
-
-
Method Details
-
findDictionary
private static void findDictionary()Finds appropriate dictionary based on set country and language locales. -
setupFallback
private static void setupFallback()Sets up the fallback dictionary. -
lookupWord
Returns the translated string associated with the provided key either in the active dictionary, or the fallback dictionary. If the key is not associated with a translated string, the key is returned.- Parameters:
key
- the key to find the associated translated string for.- Returns:
- the translated string associated with the provided key either in the active dictionary, or the fallback dictionary.
-
getTranslation
Returns translation of given word in default language. If required removes all & chars in addition.- Parameters:
word
- Word to be translated.removeAnds
- Whether & chars should be removed.- Returns:
- Translation of given word in default language.
-
removeAnds
Removes the & characters in the provided string.- Parameters:
word
- The string to remove & characters in.- Returns:
- the provided string without any & characters.
-
getTranslation
Returns translation of given word in default language.- Parameters:
word
- Word to be translated.- Returns:
- Translation of given word in default language.
-
getTranslation
Returns translation of given word in default language and replaces arguments.- Parameters:
word
- Word to be translated containing ${0}, ${1} etc. elements.substitutions
- Words that will be used to replace ${0}, ${1} etc. elements.- Returns:
- Translation of given word in default language with substitutions.
-
getMnemonic
Returns mnemonic char found in translated word. As the mnemonic is considered the character after & char. If & is not found in the translation, invisible character is returned.- Parameters:
word
- Word to be translated and where mnemonic char will be searched for.- Returns:
- Mnemonic i.e. character right after first occurence of & character in the translated word.
-