Class Translator


  • public class Translator
    extends java.lang.Object
    Translator class providing localization.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.PropertyResourceBundle dictionary
      Resource bundle representing appropriate dictionary of translations.
      private static java.lang.String DICTIONARY_PATH_FORMAT
      The path of the dictionary as used by Rachota for storing dictionaries.
      private static boolean dictionaryLookupDone
      Flag to indicate whether or not the dictionary has been looked up.
      private static java.lang.String FALLBACK_DICTIONARY
      The default dictionary to use with Rachota if none is found for your current locale.
      private static java.util.PropertyResourceBundle fallbackDictionary
      Resource bundle representing fallback/default dictionary of translations.
      private static java.util.logging.Logger log
      Logger used by the Translator class to log errors.
    • Constructor Summary

      Constructors 
      Constructor Description
      Translator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void findDictionary()
      Finds appropriate dictionary based on set country and language locales.
      static char getMnemonic​(java.lang.String word)
      Returns mnemonic char found in translated word.
      static java.lang.String getTranslation​(java.lang.String word)
      Returns translation of given word in default language.
      private static java.lang.String getTranslation​(java.lang.String word, boolean removeAnds)
      Returns translation of given word in default language.
      static java.lang.String getTranslation​(java.lang.String word, java.lang.String[] substitutions)
      Returns translation of given word in default language and replaces arguments.
      private static java.lang.String lookupWord​(java.lang.String key)
      Returns the translated string associated with the provided key either in the active dictionary, or the fallback dictionary.
      private static java.lang.String removeAnds​(java.lang.String word)
      Removes the & characters in the provided string.
      private static void setupFallback()
      Sets up the fallback dictionary.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • dictionary

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

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

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

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

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

        private static boolean dictionaryLookupDone
        Flag to indicate whether or not the dictionary has been looked up.
    • Constructor Detail

      • Translator

        public Translator()
    • Method Detail

      • 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 java.lang.String lookupWord​(java.lang.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 java.lang.String getTranslation​(java.lang.String word,
                                                       boolean removeAnds)
        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

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

        public static java.lang.String getTranslation​(java.lang.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 java.lang.String getTranslation​(java.lang.String word,
                                                      java.lang.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​(java.lang.String word)
        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.