Module tvbrowser
Package util.i18n

Class Localizer

  • Direct Known Subclasses:
    PooledLocalizer

    public class Localizer
    extends java.lang.Object
    Does the localization of texts.

    Each class that uses String that reach the user interface has its own Localizer. You can get a localized String by using one of the msg methods.

    The msg methods have all the same pattern:
    String msg(key, defaultValue, [args]);

    • The key is a String that identifies the message. Each class has its own namespace.
    • The defaultValue is the value you would expect on an English system. (But note: Even on an English system you may get a different String!)
    • The optional args are arguments that will be parsed into the message. See MessageFormat for details.
    Author:
    Til Schneider, www.murfman.de
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Localizer​(java.lang.Class<?> clazz)
      Creates a new instance of Localizer.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void addLocalizerToCache​(java.lang.Class<?> clazz, Localizer localizer)  
      java.lang.String ellipsis​(java.lang.String someString)
      return the given String with an ellipsis appended
      java.lang.String ellipsisMsg​(java.lang.String key, java.lang.String defaultMessage)
      get a localized message with an ellipsis as suffix
      java.lang.String ellipsisMsg​(java.lang.String key, java.lang.String defaultMsg, java.lang.Object arg1)
      Gets a localized message ending with ellipsis suffix
      static void emptyLocalizerCache()
      Clears the localizer cache.
      java.util.Locale[] getAllAvailableLocales()
      Scans all Language-Directories for different Versions of tvbrowser/tvbrowser.properties.
      protected static Localizer getCachedLocalizerFor​(java.lang.Class<?> clazz)  
      static java.lang.String getEllipsisLocalization​(java.lang.String key)
      get a standard localization with ellipsis as suffix
      static java.util.Locale getLocaleForString​(java.lang.String string)
      Get the Locale for a specific String.
      static java.lang.String getLocalization​(java.lang.String key)
      get a standard localization
      static Localizer getLocalizerFor​(java.lang.Class<?> clazz)
      Gets the Localizer for the specified Class.
      boolean hasMessage​(java.lang.String key)
      check if a given message key exists
      protected void initializeForClass​(java.lang.Class<?> clazz)  
      java.lang.String msg​(java.lang.String key, java.lang.String defaultMsg)
      Gets a localized message.
      java.lang.String msg​(java.lang.String key, java.lang.String defaultMsg, boolean warn)
      Gets a localized message.
      java.lang.String msg​(java.lang.String key, java.lang.String defaultMsg, java.lang.Object... args)
      Gets a localized message.
      • Methods inherited from class java.lang.Object

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

      • Localizer

        protected Localizer​(java.lang.Class<?> clazz)
        Creates a new instance of Localizer.
        Parameters:
        clazz - The Class to create the Localizer for.
    • Method Detail

      • initializeForClass

        protected void initializeForClass​(java.lang.Class<?> clazz)
      • getCachedLocalizerFor

        protected static Localizer getCachedLocalizerFor​(java.lang.Class<?> clazz)
      • getLocalizerFor

        public static Localizer getLocalizerFor​(java.lang.Class<?> clazz)
        Gets the Localizer for the specified Class.
        Parameters:
        clazz - The Class to get the localizer for.
        Returns:
        the Localizer for the specified Class.
      • addLocalizerToCache

        protected static void addLocalizerToCache​(java.lang.Class<?> clazz,
                                                  Localizer localizer)
      • emptyLocalizerCache

        public static void emptyLocalizerCache()
        Clears the localizer cache.
      • msg

        public java.lang.String msg​(java.lang.String key,
                                    java.lang.String defaultMsg,
                                    java.lang.Object... args)
        Gets a localized message.
        Parameters:
        key - The key of the message.
        defaultMsg - The default message. (English)
        args - The arguments that should replace the appropriate place holder. See MessageFormat for details.
        Returns:
        a localized message.
      • msg

        public java.lang.String msg​(java.lang.String key,
                                    java.lang.String defaultMsg)
        Gets a localized message.
        Parameters:
        key - The key of the message.
        defaultMsg - The default message (English)
        Returns:
        a localized message.
      • msg

        public java.lang.String msg​(java.lang.String key,
                                    java.lang.String defaultMsg,
                                    boolean warn)
        Gets a localized message.
        Parameters:
        key - The key of the message.
        defaultMsg - The default message (English)
        warn - If warnings should be logged if key is not found.
        Returns:
        a localized message.
        Since:
        2.5.1
      • getAllAvailableLocales

        public java.util.Locale[] getAllAvailableLocales()
        Scans all Language-Directories for different Versions of tvbrowser/tvbrowser.properties. This is faster than analyzing all Files
        Returns:
        all available Locales
        Since:
        2.3
      • getLocaleForString

        public static java.util.Locale getLocaleForString​(java.lang.String string)
        Get the Locale for a specific String. The String is in this format: "lang_country_variant"
        Parameters:
        string - String with Locale
        Returns:
        Locale
      • getLocalization

        public static java.lang.String getLocalization​(java.lang.String key)
        get a standard localization
        Parameters:
        key - one of the constant values defined in the Localizer class
        Returns:
        localized message for key
      • getEllipsisLocalization

        public static java.lang.String getEllipsisLocalization​(java.lang.String key)
        get a standard localization with ellipsis as suffix
        Parameters:
        key - one of the constant values defined in the Localizer class
        Returns:
        localized message for key
      • ellipsisMsg

        public java.lang.String ellipsisMsg​(java.lang.String key,
                                            java.lang.String defaultMessage)
        get a localized message with an ellipsis as suffix
        Parameters:
        key - localization key
        defaultMessage - default (English) message
        Returns:
        localized message
        Since:
        3.0
      • ellipsisMsg

        public java.lang.String ellipsisMsg​(java.lang.String key,
                                            java.lang.String defaultMsg,
                                            java.lang.Object arg1)
        Gets a localized message ending with ellipsis suffix
        Parameters:
        key - The key of the message.
        defaultMsg - The default message (English)
        arg1 - The argument that should replace {0}.
        Returns:
        a localized message.
      • hasMessage

        public boolean hasMessage​(java.lang.String key)
        check if a given message key exists
        Parameters:
        key - The key
        Returns:
        true if the given key exists
        Since:
        3.0
      • ellipsis

        public java.lang.String ellipsis​(java.lang.String someString)
        return the given String with an ellipsis appended
        Parameters:
        someString - The string.
        Returns:
        ellipsis appended String or null
        Since:
        3.0