public final class Locales extends Static
Locale
instances. While this class is documented as
providing static methods, a few methods are actually non-static. Those methods need to be
invoked on the ALL
or SIS
instance in order to specify the scope.
Examples:
Locales[] lc1 = Locales.ALL.getAvailableLanguages(); // All languages installed on the JavaVM. Locales[] lc2 = Locales.SIS.getAvailableLanguages(); // Only the languages known to Apache SIS.
Defined in the sis-utility module
Modifier and Type | Field and Description |
---|---|
static Locales |
ALL
All locales available on the JavaVM.
|
static Locales |
SIS
Only locales available in the Apache SIS library.
|
Modifier and Type | Method and Description |
---|---|
Locale[] |
getAvailableLanguages()
|
Locale[] |
getAvailableLocales()
|
String[] |
getAvailableLocales(Locale locale)
Returns the list of available locales formatted
as strings in the specified locale.
|
static Locale[] |
getLanguages(Locale... locales)
Returns the languages of the given locales, without duplicated values.
|
static Locale |
parse(String code)
Parses the given locale.
|
static Locale |
parseSuffix(String prefix,
String key)
Parses the locale encoded in the suffix of a property key.
|
static Locale |
unique(Locale locale)
Returns a unique instance of the given locale, if one is available.
|
public static final Locales ALL
public static final Locales SIS
org.apache.sis.util.resources
package.public Locale[] getAvailableLanguages()
ALL
) or to the Apache SIS library
(SIS
). In the later case, this method returns only the languages for which
localized resources are provided in the org.apache.sis.util.resources
package.public Locale[] getAvailableLocales()
ALL
) or to the Apache SIS library
(SIS
). In the later case, this method returns only the locales for which
localized resources are provided in the org.apache.sis.util.resources
package.public String[] getAvailableLocales(Locale locale)
locale
- The locale to use for formatting the strings to be returned.public static Locale[] getLanguages(Locale... locales)
locales
- The locales from which to get the languages.public static Locale parse(String code) throws IllegalArgumentException
'_'
character and the
country code (again either as 2 or 3 letters), optionally followed by '_'
and
the variant.
This method can be used when the caller wants the same Locale
constants no
matter if the language and country codes use 2 or 3 letters. Apache SIS usually don't
distinguish those two cases since ISO 19139 documents have to use the 3 letters codes
anyway.
code
- The language code, which may be followed by country code.IllegalArgumentException
- If the given code doesn't seem to be a valid locale.Locale.forLanguageTag(String)
public static Locale parseSuffix(String prefix, String key) throws IllegalArgumentException
Map
may have many localized variants.
For example the "remarks"
property may be defined by values associated to the
"remarks_en"
and "remarks_fr"
keys, for English and French locales
respectively.
This method infers the Locale
from the property key
with the following steps:
key
is exactly equals to prefix
,
then this method returns Locale.ROOT
.key
does not start with the specified prefix
followed by the '_'
character, then this method returns null
.'_'
are parsed as an ISO language
and country code by the parse(String)
method.prefix
- The prefix to skip at the beginning of the key
.key
- The property key from which to extract the locale.true
if the key has been recognized, or false
otherwise.IllegalArgumentException
- if the locale after the prefix is an illegal code.Copyright © 2010–2013 The Apache Software Foundation. All rights reserved.