Class Locales


  • public class Locales
    extends Object
    Keeps track of the preferred languages to use within the current thread and its children.

    If your server is configured with a LocalesFilter, this class enables access to the locales of an incoming request from anywhere on the server.

    Since:
    3.12.0
    • Method Detail

      • 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, returns a list with one default language to use. This default language is the default locale of the JVM, if it is part of the Options.ENABLED_LOCALES property of 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