Package org.forgerock.util.i18n
Class PreferredLocales
java.lang.Object
org.forgerock.util.i18n.PreferredLocales
This class encapsulates an ordered list of preferred locales, and the logic
to use those to retrieve i18n
ResourceBundle
s.
ResourceBundle
s are found by iterating over the preferred locales
and returning the first resource bundle for which a non-ROOT locale is
available, that is not listed later in the list, or the ROOT locale if no
better match is found.
For example, given available locales of en
and fr
:
-
Preferred locales of
fr-FR, en
, resource bundle for localefr
is returned. -
Preferred locales of
fr-FR, en, fr
, resource bundle for localeen
is returned (fr
is listed lower thanen
). -
Preferred locales of
de
, resource bundle for the ROOT locale is returned.
MyBundle.properties
) is en-US
. If this is not the case for an
application, it can be changed by setting the
org.forgerock.defaultBundleLocale
system property.-
Constructor Summary
ConstructorDescriptionCreate a new, empty preference of locales.PreferredLocales
(List<Locale> locales) Create a new preference of locales by copying the provided locales list. -
Method Summary
Modifier and TypeMethodDescriptiongetBundleInPreferredLocale
(String bundleName, ClassLoader classLoader) Get aResourceBundle
using the preferred locale list and using the providedClassLoader
.The ordered list of preferred locales.The preferred locale, i.e.static boolean
Checks if the candidate locale the best match for the requested locale? ExcludeLocale.ROOT
, as it should be the fallback only when all locales are tried.
-
Constructor Details
-
PreferredLocales
Create a new preference of locales by copying the provided locales list.- Parameters:
locales
- The list of locales that are preferred, with the first item the most preferred.
-
PreferredLocales
public PreferredLocales()Create a new, empty preference of locales.
-
-
Method Details
-
getPreferredLocale
The preferred locale, i.e. the head of the preferred locales list.- Returns:
- The most-preferred locale.
-
getLocales
The ordered list of preferred locales.- Returns:
- A immutable copy of the preferred locales list.
-
getBundleInPreferredLocale
Get aResourceBundle
using the preferred locale list and using the providedClassLoader
.- Parameters:
bundleName
- The name of the bundle to load.classLoader
- TheClassLoader
to use to load the bundle.- Returns:
- The bundle in the best matching locale.
-
matches
Checks if the candidate locale the best match for the requested locale? ExcludeLocale.ROOT
, as it should be the fallback only when all locales are tried.- Parameters:
requested
- The requested Localecandidate
- The candidate LocaleremainingLocales
- The remaining locales- Returns:
- The candidate is beast match for requested locale
-