Package com.sodius.oslc.server.util
Class Locales
java.lang.Object
com.sodius.oslc.server.util.Locales
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 Summary
Modifier and TypeMethodDescriptionstatic LocaleGets the preferred language to use within the current thread.Gets the list of preferred languages to use within the current thread.static voidsetLocales(List<Locale> locales) Sets the list of preferred languages to use within the current thread.
-
Method Details
-
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 thedefault localeof the JVM, if it is part of theOptions.ENABLED_LOCALESproperty or if this property is not set. Otherwise it is the first language in theOptions.ENABLED_LOCALESlist.- Returns:
- the preferred languages to use within the current thread
-
getLocale
Gets the preferred language to use within the current thread. The preferred language is the first one returned bygetLocales().This method shall be used when calling a Java method that expects one
Localeinstance. When message translations are desired, prefer usinggetLocales(), as there might not be translations for the first language in the list.- Returns:
- the preferred language to use within the current thread
-
setLocales
Sets the list of preferred languages to use within the current thread.- Parameters:
locales- the preferred languages to use within the current thread
-