public class PreferredLocales extends Object
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
:
fr-FR, en
, resource bundle for locale
fr
is returned.
fr-FR, en, fr
, resource bundle for locale
en
is returned (fr
is listed lower than en
).
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 and Description |
---|
PreferredLocales()
Create a new, empty preference of locales.
|
PreferredLocales(List<Locale> locales)
Create a new preference of locales by copying the provided locales list.
|
Modifier and Type | Method and Description |
---|---|
ResourceBundle |
getBundleInPreferredLocale(String bundleName,
ClassLoader classLoader)
Get a
ResourceBundle using the preferred locale list and using the provided
ClassLoader . |
List<Locale> |
getLocales()
The ordered list of preferred locales.
|
Locale |
getPreferredLocale()
The preferred locale, i.e.
|
static boolean |
matches(Locale requested,
Locale candidate,
List<Locale> remainingLocales)
Checks if the candidate locale the best match for the requested locale?
Exclude
Locale.ROOT , as it should be the fallback only when all locales are tried. |
public PreferredLocales(List<Locale> locales)
locales
- The list of locales that are preferred, with the first item the most preferred.public PreferredLocales()
public Locale getPreferredLocale()
public List<Locale> getLocales()
public ResourceBundle getBundleInPreferredLocale(String bundleName, ClassLoader classLoader)
ResourceBundle
using the preferred locale list and using the provided
ClassLoader
.bundleName
- The name of the bundle to load.classLoader
- The ClassLoader
to use to load the bundle.public static boolean matches(Locale requested, Locale candidate, List<Locale> remainingLocales)
Locale.ROOT
, as it should be the fallback only when all locales are tried.requested
- The requested Localecandidate
- The candidate LocaleremainingLocales
- The remaining localesCopyright © 2010-2018, ForgeRock All Rights Reserved.