Package com.ilib

Class ResBundle


  • public class ResBundle
    extends java.lang.Object
    ResBundle
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ResBundle.MissingType  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsSource​(java.lang.String source)
      Examines if source string has already been translated or not
      protected java.lang.String escape​(java.lang.String str)
      Replaces all xml and html tags occurences with corresponding replacements
      IlibLocale getLocale()
      Returns target locale object in BCP47 format
      ResBundle.MissingType getMissing()
      Returns missing option - that option specifies behavior in case when translation is not found by given key or value.
      java.lang.String getName()
      Returns given name for resources location which are seeking for for translations
      protected java.lang.String getPseudoCharacter​(java.lang.String character)
      Returns string with pseudo character that corresponds to the input one
      static IlibLocale getSourceLocale()
      Returns source locale for all threads in current process
      IString getString​(java.lang.String source)  
      IString getString​(java.lang.String source, java.lang.String key)
      Returns translation for given source and key strings in IString format
      java.lang.String getStringJ​(java.lang.String source)
      Return the translation for the given source string in a Java "String" instead of a formattable "IString".
      IString getStringPseudo​(java.lang.String source)  
      protected java.lang.String getTranslation​(java.lang.String source, java.lang.String key)  
      java.lang.String getType()
      Returns type of text information which ResBundle is being operating with (default type: raw)
      protected void initPseudoMap()  
      protected void initResources()  
      protected boolean isHTML_XML_Type()  
      boolean isLengthen()
      Returns lengthen option that allows to lengthen potential length for translated string (for UI/UX issues) using pseudo-localization.
      protected void loadAllTranslations​(java.lang.String filename)  
      protected void loadTranslationsFromFile​(java.lang.String filename)  
      protected java.lang.String makeKey​(java.lang.String source)
      Creates a unique key from given source string
      protected java.lang.String pseudo​(java.lang.String source)
      Returns pseudo string from input one using appropriate pseudomap
      void setLengthen​(boolean lengthen)
      Specifies lengthen option to lengthen potential length for translated string (for UI/UX issues) using pseudo-localization.
      void setMissingType​(ResBundle.MissingType type)
      Specifies missing option - option, that specifies behavior in case when translation is not found by given key or value.
      void setResourceFileName​(java.lang.String filename)
      Specifies resources filename; default file is strings.json
      static void setSourceLocale​(IlibLocale locale)
      Specifies source locale for all threads in current process
      void setType​(java.lang.String type)
      Specifies type of text information which ResBundle is being operating with
      protected java.lang.String unescape​(java.lang.String str)
      Invokes retroaction for escape(String)
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_RESOURCES

        protected static final java.lang.String DEFAULT_RESOURCES
        See Also:
        Constant Field Values
      • DEFAULT_TEXT_TYPE

        protected static final java.lang.String DEFAULT_TEXT_TYPE
        See Also:
        Constant Field Values
      • DEFAULT_RES_FILE

        protected static final java.lang.String DEFAULT_RES_FILE
        See Also:
        Constant Field Values
      • sourceResources

        protected static java.util.Map<java.lang.String,​java.lang.String> sourceResources
      • sourceLocale

        protected static volatile IlibLocale sourceLocale
      • name

        protected java.lang.String name
      • type

        protected java.lang.String type
      • translations

        protected java.util.Map<java.lang.String,​java.lang.String> translations
      • pseudoCharacters

        protected java.util.Map<java.lang.String,​java.lang.String> pseudoCharacters
      • lengthen

        protected boolean lengthen
      • resourceFilename

        protected java.lang.String resourceFilename
    • Constructor Detail

      • ResBundle

        public ResBundle()
      • ResBundle

        public ResBundle​(java.lang.String name)
        Parameters:
        name -
      • ResBundle

        public ResBundle​(java.lang.String name,
                         IlibLocale locale)
        Parameters:
        name -
        locale -
      • ResBundle

        public ResBundle​(java.lang.String name,
                         IlibLocale locale,
                         java.lang.String type)
        Parameters:
        name -
        locale -
        type -
      • ResBundle

        public ResBundle​(java.lang.String name,
                         IlibLocale locale,
                         java.lang.String type,
                         java.lang.String resFileName)
        Parameters:
        name -
        locale -
        type -
        resFileName -
    • Method Detail

      • initResources

        protected void initResources()
      • loadAllTranslations

        protected void loadAllTranslations​(java.lang.String filename)
                                    throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • loadTranslationsFromFile

        protected void loadTranslationsFromFile​(java.lang.String filename)
      • initPseudoMap

        protected void initPseudoMap()
      • setSourceLocale

        public static void setSourceLocale​(IlibLocale locale)
        Specifies source locale for all threads in current process
        Parameters:
        locale - source locale
      • getSourceLocale

        public static IlibLocale getSourceLocale()
        Returns source locale for all threads in current process
        Returns:
        source locale
      • setResourceFileName

        public void setResourceFileName​(java.lang.String filename)
        Specifies resources filename; default file is strings.json
        Parameters:
        filename - resource filename of JSON file to look up for translations
      • getLocale

        public IlibLocale getLocale()
        Returns target locale object in BCP47 format
        Returns:
        target locale instance
      • containsSource

        public boolean containsSource​(java.lang.String source)
        Examines if source string has already been translated or not
        Parameters:
        source - source string to be examined
        Returns:
        true if source string is found in translations, otherwise - false
      • getName

        public java.lang.String getName()
        Returns given name for resources location which are seeking for for translations
        Returns:
        given name for resources with translations
      • getType

        public java.lang.String getType()
        Returns type of text information which ResBundle is being operating with (default type: raw)
        Returns:
        input text type: html, xml, raw
      • setType

        public void setType​(java.lang.String type)
        Specifies type of text information which ResBundle is being operating with
        Parameters:
        type - input text specified type (default type: raw).
      • isLengthen

        public boolean isLengthen()
        Returns lengthen option that allows to lengthen potential length for translated string (for UI/UX issues) using pseudo-localization.
        Returns:
        true if lengthen option is specified, false otherwise
      • setLengthen

        public void setLengthen​(boolean lengthen)
        Specifies lengthen option to lengthen potential length for translated string (for UI/UX issues) using pseudo-localization.
        Parameters:
        lengthen - option allows to lengthen potential translated string length using pseudo string as returned instead.
      • getMissing

        public ResBundle.MissingType getMissing()
        Returns missing option - that option specifies behavior in case when translation is not found by given key or value. Possible values: SOURCE - return source string if translation is not found; PSEUDO - return pseudo localized string from source string if translation is not found; EMPTY - return empty string if translation is not found.
        Returns:
        missing option value
      • setMissingType

        public void setMissingType​(ResBundle.MissingType type)
        Specifies missing option - option, that specifies behavior in case when translation is not found by given key or value. Possible values: SOURCE - return source string if translation is not found; PSEUDO - return pseudo localized string from source string if translation is not found; EMPTY - return empty string if translation is not found.
        Parameters:
        type -
      • pseudo

        protected java.lang.String pseudo​(java.lang.String source)
        Returns pseudo string from input one using appropriate pseudomap
        Parameters:
        source - input string needed to be pseudo localized
        Returns:
        pseudo localized string
      • getPseudoCharacter

        protected java.lang.String getPseudoCharacter​(java.lang.String character)
        Returns string with pseudo character that corresponds to the input one
        Parameters:
        character - input character string
        Returns:
        string with pseudo character if input character is found in appropriate pseudoMap, otherwise - input character
      • escape

        protected java.lang.String escape​(java.lang.String str)
        Replaces all xml and html tags occurences with corresponding replacements
        Parameters:
        str - input string
        Returns:
        string with no html- and xml-style tags
      • unescape

        protected java.lang.String unescape​(java.lang.String str)
        Invokes retroaction for escape(String)
        Parameters:
        str - input string
        Returns:
        string with html- and xml-style tags
        See Also:
        escape(String str);
      • makeKey

        protected java.lang.String makeKey​(java.lang.String source)
        Creates a unique key from given source string
        Parameters:
        source - input source string
        Returns:
        unique key that contains no spaces, and modified equals and colon signs
      • getString

        public IString getString​(java.lang.String source,
                                 java.lang.String key)
        Returns translation for given source and key strings in IString format
        Parameters:
        source - source string
        key - key item, if null - then unique key will be generated
        Returns:
        translation for target locale if it is exists, otherwise the source string
        See Also:
        makeKey(String), ResBundle.MissingType
      • getTranslation

        protected java.lang.String getTranslation​(java.lang.String source,
                                                  java.lang.String key)
        Parameters:
        source -
        key -
        Returns:
        the translation for the given source string/key combination
      • isHTML_XML_Type

        protected boolean isHTML_XML_Type()
      • getString

        public IString getString​(java.lang.String source)
        Parameters:
        source -
        Returns:
        the translation for the given source string
      • getStringJ

        public java.lang.String getStringJ​(java.lang.String source)
        Return the translation for the given source string in a Java "String" instead of a formattable "IString".
        Parameters:
        source -
        Returns:
        the translation for the given source string as a Java "String"
      • getStringPseudo

        public IString getStringPseudo​(java.lang.String source)
        Parameters:
        source -
        Returns:
        the pseudo-translated version of the source string