Class Translator

java.lang.Object
org.cesilko.rachota.core.Translator

public class Translator extends Object
Translator class providing localization.
  • Field Details

    • dictionary

      private static PropertyResourceBundle dictionary
      Resource bundle representing appropriate dictionary of translations.
    • fallbackDictionary

      private static PropertyResourceBundle fallbackDictionary
      Resource bundle representing fallback/default dictionary of translations.
    • log

      private static final Logger log
      Logger used by the Translator class to log errors.
    • DICTIONARY_PATH_FORMAT

      private static final String DICTIONARY_PATH_FORMAT
      The path of the dictionary as used by Rachota for storing dictionaries.
      See Also:
    • FALLBACK_DICTIONARY

      private static final String FALLBACK_DICTIONARY
      The default dictionary to use with Rachota if none is found for your current locale.
      See Also:
    • dictionaryLookupDone

      private static boolean dictionaryLookupDone
      Flag 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

      private static String lookupWord(String key)
      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

      private static String getTranslation(String word, boolean removeAnds)
      Returns translation of given word in default language. If required removes all invalid input: '&' chars in addition.
      Parameters:
      word - Word to be translated.
      removeAnds - Whether invalid input: '&' chars should be removed.
      Returns:
      Translation of given word in default language.
    • removeAnds

      private static String removeAnds(String word)
      Removes the invalid input: '&' characters in the provided string.
      Parameters:
      word - The string to remove invalid input: '&' characters in.
      Returns:
      the provided string without any invalid input: '&' characters.
    • getTranslation

      public static String getTranslation(String word)
      Returns translation of given word in default language.
      Parameters:
      word - Word to be translated.
      Returns:
      Translation of given word in default language.
    • getTranslation

      public static String getTranslation(String word, String[] substitutions)
      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

      public static char getMnemonic(String word)
      Returns mnemonic char found in translated word. As the mnemonic is considered the character after invalid input: '&' char. If invalid input: '&' 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 invalid input: '&' character in the translated word.