Class Locales

java.lang.Object
com.sodius.oslc.server.util.Locales

public class Locales extends Object
Keeps track of the preferred languages to use within the current thread and its children. This class enables access to the locales of an incoming request from anywhere on the server, as tracked by RequestContextProvider class.
Since:
3.12.0
  • Method Details

    • getLocales

      public static List<Locale> getLocales()
      Gets the list of preferred languages to use within the current thread. The returned list is known to never be empty.

      If the list was not set with setLocales(List) before calling this method, the locales of the incoming servlet request are returned, if any. If none was found, a list with one default language to use is returned. This default language is the default locale of the JVM, if it is part of the Options.ENABLED_LOCALES property or if this property is not set. Otherwise it is the first language in the Options.ENABLED_LOCALES list.

      Returns:
      the preferred languages to use within the current thread
    • getLocale

      public static Locale getLocale()
      Gets the preferred language to use within the current thread. The preferred language is the first one returned by getLocales().

      This method shall be used when calling a Java method that expects one Locale instance. When message translations are desired, prefer using getLocales(), as there might not be translations for the first language in the list.

      Returns:
      the preferred language to use within the current thread
    • setLocales

      public static void setLocales(List<Locale> locales)
      Sets the list of preferred languages to use within the current thread.
      Parameters:
      locales - the preferred languages to use within the current thread