Class Locales
java.lang.Object
org.apache.sis.util.Static
org.apache.sis.util.Locales
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final LocalesAll locales available on the JavaVM.private static final shortprivate static final short[]Mapping from 3-letters codes to 2-letters codes.private static final short[]Mapping from 3-letters codes to 2-letters codes.private static final shortA read-only map for canonicalizing the locales.static final LocalesOnly locales available in the Apache SIS library. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLocales()Do not allow instantiation of this class, except for the constants defined in this class. -
Method Summary
Modifier and TypeMethodDescriptionLocale[]Locale[]private static Locale[]getLanguages(Locale... locales) Returns the languages of the given locales, without duplicated values.static LocaleParses the given language code, optionally followed by country code and variant.static LocaleParses the given language code and optional complements (country, variant), starting at the given index.private static StringConverts a 3-letters ISO code to a 2-letters one.private static shortConverts the given 1-, 2- or 3- letters alpha code to a 15 bits numbers.static LocaleReturns a unique instance of the given locale, if one is available.
-
Field Details
-
POOL
-
LANGUAGE
-
COUNTRY
-
ISO3
private static final short[] ISO3Mapping from 3-letters codes to 2-letters codes. We useshorttype instead ofStringfor compactness (conversions is done bytoNumber(String, short)) and for avoiding references toStringinstances.Implementation note: Oracle JDK8 implementation computes the 3-letters codes on-the-fly instead of holding references to pre-existing strings. If we were holding string references here, we would prevent the garbage collector to collect the strings for all languages and countries. This would probably be a waste of resources. -
ISO2
private static final short[] ISO2Mapping from 3-letters codes to 2-letters codes. We useshorttype instead ofStringfor compactness (conversions is done bytoNumber(String, short)) and for avoiding references toStringinstances.Implementation note: Oracle JDK8 implementation computes the 3-letters codes on-the-fly instead of holding references to pre-existing strings. If we were holding string references here, we would prevent the garbage collector to collect the strings for all languages and countries. This would probably be a waste of resources. -
ALL
All locales available on the JavaVM. -
SIS
Only locales available in the Apache SIS library.
-
-
Constructor Details
-
Locales
private Locales()Do not allow instantiation of this class, except for the constants defined in this class.
-
-
Method Details
-
getAvailableLanguages
-
getAvailableLocales
-
getLanguages
-
parse
Parses the given language code, optionally followed by country code and variant. The given string can be either the 2 letters or the 3 letters ISO 639 code. It can optionally be followed by the'_'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
Localeconstants no matter if the language and country codes use 2 or 3 letters. This method tries to convert 3-letters codes to 2-letters code on a best effort basis.- Parameters:
code- the language code, optionally followed by country code and variant.- Returns:
- the language for the given code (never
null). - Throws:
IllformedLocaleException- if the given code is not valid.- See Also:
-
parse
Parses the given language code and optional complements (country, variant), starting at the given index. All characters beforefromIndexare ignored. Characters fromfromIndexto the end of the string are parsed as documented in theparse(String)method. In particular, this method tries to convert 3-letters codes to 2-letters code on a best effort basis.Example: This method is useful when language codes are appended to a base property or resource name. For example, a dictionary may define the"remarks"property by values associated to the"remarks_en"and"remarks_fr"keys, for English and French locales respectively.- Parameters:
code- the language code, which may be followed by country code.fromIndex- index of the first character to parse.- Returns:
- the language for the given code (never
null). - Throws:
IllformedLocaleException- if the given code is not valid.- See Also:
-
toISO2
Converts a 3-letters ISO code to a 2-letters one. If the given code is not recognized, then this method returnscodeunmodified. -
toNumber
Converts the given 1-, 2- or 3- letters alpha code to a 15 bits numbers. Each letter uses 5 bits. If an invalid character is found, then this method returns 0.This method does not use the sign bit. Callers can use it for differentiating language codes from country codes, using the
LANGUAGEorCOUNTRYbit masks. -
unique
-