public final class LocaleUtils extends Object
Locale
management
This class provides two methods:
parseLocale(String)
parses a string and builds a Locale
object (strangely enough, there is no such method in the JDK!);
getApplicable(Locale)
returns an ordered list of locales
"applicable" to the given locale.The getApplicable(Locale)
method emulates what the JDK's ResourceBundle
does when you look up a message in a locale; it returns an
ordered list from the most specific to the more general. For instance, given
the locale "ja_JP_JP"
, it will generate the following list:
"ja_JP_JP"
,"ja_JP"
,"ja"
,""
(the root locale, Locale.ROOT
).Modifier and Type | Method and Description |
---|---|
static Collection<Locale> |
getApplicable(Locale target)
Get a "decrementing" list of candidate locales for a given locale
|
static Locale |
parseLocale(String input)
Parse a string input as an argument and return a locale object
|
public static Locale parseLocale(String input)
Three things to note:
Locale.ROOT
is returned.input
- the input stringLocale
NullPointerException
- input is nullIllegalArgumentException
- input is malformed (see above)Locale
public static Collection<Locale> getApplicable(Locale target)
The order of locale returned is from the more specific to the less
specific (the latter being Locale.ROOT
).
target
- the locale