Class LocaleProvider

java.lang.Object
org.tentackle.common.LocaleProvider

@Service(LocaleProvider.class) public class LocaleProvider extends Object
A provider for the Locale.
Author:
harald
  • Constructor Details

    • LocaleProvider

      public LocaleProvider()
  • Method Details

    • getInstance

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

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

      public 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(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 Locale getEffectiveLocale(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 Locale getEffectiveLocale()
      Gets the effective locale for the current locale.
      Returns:
      the mapped locale