Class LocaleProvider

    • Constructor Summary

      Constructors 
      Constructor Description
      LocaleProvider()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assertCurrentLocaleValid()
      Asserts that a thread local Locale is set.
      java.util.Locale getCurrentLocale()
      Gets the locale used by the current thread.
      java.util.Locale getEffectiveLocale()
      Gets the effective locale for the current locale.
      java.util.Locale getEffectiveLocale​(java.util.Locale locale)
      Gets the effective locale.
      This is application-specific and allows narrowing the locales to the effectively supported locales.
      static LocaleProvider getInstance()
      The singleton.
      java.util.Locale getLocale()
      Gets the locale.
      void setCurrentLocale​(java.util.Locale locale)
      Sets the session used by the current thread.
      The session is stored as ThreadLocal.
      • Methods inherited from class java.lang.Object

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

      • LocaleProvider

        public LocaleProvider()
    • Method Detail

      • getInstance

        public static LocaleProvider getInstance()
        The singleton.
        Returns:
        the singleton
      • getCurrentLocale

        public java.util.Locale getCurrentLocale()
        Gets the locale used by the current thread.
        Returns:
        the locale, null if no thread-local Locale set
      • getLocale

        public java.util.Locale getLocale()
        Gets the locale.

        If there is no thread-local Locale, the default Locale is returned.

        Returns:
        the current locale, never null
      • setCurrentLocale

        public void setCurrentLocale​(java.util.Locale locale)
        Sets the session used by the current thread.
        The session is stored as ThreadLocal.
        Parameters:
        locale - the locale
      • assertCurrentLocaleValid

        public void assertCurrentLocaleValid()
        Asserts that a thread local Locale is set.
        Throws:
        TentackleRuntimeException - if thread-local locale is null
      • getEffectiveLocale

        public java.util.Locale getEffectiveLocale​(java.util.Locale locale)
        Gets the effective locale.
        This is application-specific and allows narrowing the locales to the effectively supported locales. If, for example, the default language in all resource bundles is "en" and there is a second language "de", then all locales beginning with "de" will map to "de" and all others to "en".
        Parameters:
        locale - the requested locale
        Returns:
        the mapped locale
      • getEffectiveLocale

        public java.util.Locale getEffectiveLocale()
        Gets the effective locale for the current locale.
        Returns:
        the mapped locale