Class LocaleUtils
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classData class representing a locale item in configuration files.static classData element describing a configuration file for Locales. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConfiguration file location for this classstatic final StringMatch-all entries regardless of country.static final StringMatch-all non-empty countries.static final StringReserved country codes to be used if ISO mappings are not enough.Cache for country codes.static final StringA four letter code for script (writing system) (in title case).static final StringA two uppercase letter code for countries.static final StringA two lowercase letter code for languages.static final StringA three lowercase letter code for languages.static final StringMatch-all entries regardless of language.static final StringMatch-all non-empty languages.static final StringReserved language codes to be used if ISO mappings are not enough.Cache for lang codes.static final StringMatch-all entries regardless of script.static final StringMatch-all non-empty scripts.static final StringReserved script code to be used if ISO mappings are not enough.Cache for script codes. -
Method Summary
Modifier and TypeMethodDescriptionstatic String[]static List<LocaleUtils.LocaleItem>static List<LocaleUtils.LocaleItem>getCountryItems(String code) static StringgetCustomCountry(String country, String code) Get external country code (if code scheme is supported) from internal country code.static StringgetCustomLanguage(String language, String code) Get external language code from internal language code if the code scheme is supported.static StringgetCustomScript(String script, String code) Get external script code (if code scheme is supported) from internal script code.static String[]static List<LocaleUtils.LocaleItem>static List<LocaleUtils.LocaleItem>getLanguageItems(String code) static StringgetPubServerCountry(String country, String code) Translates an external country code into pubserver internal representation (ISO_3166_1_Alpha2).static StringgetPubServerLanguage(String language, String code) Get internal language code from any supported language code scheme.static StringgetPubServerScript(String script, String code) Translates an external script code into pubserver internal representation (ISO_15924).static String[]Parse language and country part from a string in the format <lang>delimiter<country>static String[]parseLanguageAndCountry(String in, String delimiter) Parse language and country part from a string in the format <lang>delimiter<country>static intrefresh(PluginConfig config) Refreshes the cache of supported language and country codes from the server.static intrefresh(LocaleUtils.LocaleItems items) Refreshes the cache of supported language and country codes from the server.
-
Field Details
-
CONFIG_FILE_PATH
Configuration file location for this class- See Also:
-
LANGUAGE_NONE_EMPTY
Match-all non-empty languages.See https://tools.ietf.org/html/bcp47
2.2.1 The subtags in the range 'qaa' through 'qtz' are reserved for private use in language tags.Value is existing as extension of ISO_639_3_Alpha3 codes.
- See Also:
-
LANGUAGE_IGNORE
Match-all entries regardless of language.See https://tools.ietf.org/html/bcp47
2.2.1 The subtags in the range 'qaa' through 'qtz' are reserved for private use in language tags.Value is existing as extension of ISO_639_3_Alpha3 codes.
- See Also:
-
LANGUAGE_RESERVE
Reserved language codes to be used if ISO mappings are not enough. Other language codes can be added by config file.Values are existing as extension of ISO_639_3_Alpha3 codes.
- See Also:
-
COUNTRY_NONE_EMPTY
Match-all non-empty countries.See https://tools.ietf.org/html/bcp47
2.2.4 The region subtags 'AA', 'QM'-'QZ', 'XA'-'XZ', and 'ZZ' are reserved for private use in language tags.Value is existing as extension of ISO_3166_1_Alpha2 codes.
- See Also:
-
COUNTRY_IGNORE
Match-all entries regardless of country.See https://tools.ietf.org/html/bcp47
2.2.4 The region subtags 'AA', 'QM'-'QZ', 'XA'-'XZ', and 'ZZ' are reserved for private use in language tags.Value is existing as extension of ISO_3166_1_Alpha2 codes.
- See Also:
-
COUNTRY_RESERVE
Reserved country codes to be used if ISO mappings are not enough. Other country codes can be added by config file.Values are existing as extension of ISO_3166_1_Alpha2 codes.
- See Also:
-
SCRIPT_NONE_EMPTY
Match-all non-empty scripts.See https://tools.ietf.org/html/bcp47
2.2.3 The script subtags 'Qaaa' through 'Qabx' are reserved for private use in language tags. Value is existing as extension of ISO_15924 codes.- See Also:
-
SCRIPT_IGNORE
Match-all entries regardless of script.See https://tools.ietf.org/html/bcp47
2.2.3 The script subtags 'Qaaa' through 'Qabx' are reserved for private use in language tags. Value is existing as extension of ISO_15924 codes.- See Also:
-
SCRIPT_RESERVE
Reserved script code to be used if ISO mappings are not enough. Other script codes can be added by config file.Value is existing as extension of ISO_15924 codes.
- See Also:
-
ISO_3166_1_Alpha2
A two uppercase letter code for countries.E.g. "DE" for Germany, "GB" for United Kingdom
- Since:
- 4.0.0
- See Also:
-
ISO_639_1_Alpha2
A two lowercase letter code for languages.E.g. "de" for German and "en" for English
- Since:
- 4.0.0
- See Also:
-
ISO_639_3_Alpha3
A three lowercase letter code for languages.E.g. "deu" for German, "eng" for English, "sgg" for Swiss-German Sign Language
- Since:
- 4.0.0
- See Also:
-
ISO_15924
A four letter code for script (writing system) (in title case).E.g. "Latn" for Latin and "Cyrl" for Cyrillic
- Since:
- 4.0.0
- See Also:
-
languageCodes
Cache for lang codes.Key is [source-name]+[delimiter]+[code-constant], value is [target-name].
E.g. key="de>ISO_3166_1_Alpha2", value="deu"
-
countryCodes
Cache for country codes.Key is [source-name]+[delimiter]+[code-constant], value is [target-name].
E.g. key="de>IANA_TDL", value="DE" (if IANA_TDL is supported by configuration)
-
scriptCodes
Cache for script codes.
-
-
Method Details
-
getPubServerLanguage
Get internal language code from any supported language code scheme.E.g.
getPubServerLanguage("de", ISO_639_1_Alpha2)will return "deu".E.g.
getPubServerLanguage("ger", "ISO_639_2_B")will return "deu" (if ISO_639_2_B is suported by configuration)- Parameters:
language- Name of language according to code.code- Name of external code.
If code is an empty string the lang argument has to be a valid ISO 639‑Alpha-2, or ISO 639‑Alpha-3 lang name- Returns:
- A PubServer language name (i.e. ISO 639‑3 three letter code) or empty string
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching language key could be found- Since:
- 4.0.0
-
getCustomLanguage
Get external language code from internal language code if the code scheme is supported.E.g.
getCustomLanguage("deu", ISO_639_1_Alpha2)will return "de".- Parameters:
language- A PubServer language name (i.e. ISO 639‑3 three letter code)code- Name of external code.- Returns:
- Name of language according to external code.
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching language key could be found- Since:
- 4.0.0
-
getPubServerCountry
Translates an external country code into pubserver internal representation (ISO_3166_1_Alpha2).- Parameters:
country-code-- Returns:
- pubserver country code from ISO_3166_1_Alpha2 scheme or empty string
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching country key could be found- Since:
- 4.0.0
-
getCustomCountry
Get external country code (if code scheme is supported) from internal country code.E.g.
getCustomCountry("GB", "IANA_TDL")will return "uk" (if IANA_TDL is supported by configuration).- Parameters:
country- A PubServer country name (i.e. ISO_3166_1_Alpha2 two letter code)code- Name of external code.- Returns:
- Name of country according to external code or empty string.
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching country key could be found- Since:
- 4.0.0
-
getPubServerScript
Translates an external script code into pubserver internal representation (ISO_15924).- Parameters:
script-code-- Returns:
- pubserver script code from ISO_15924 scheme or empty string
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching script key could be found- Since:
- 4.0.0
-
getCustomScript
Get external script code (if code scheme is supported) from internal script code.E.g.
getCustomScript("Latn", "MYSCHEME")might return "west" (if MYSCHEME is supported by configuration).- Parameters:
script- A PubServer script name (i.e. ISO_15924 four letter code)code- Name of external code.- Returns:
- Name of script according to external code or empty string.
- Throws:
NullArgumentException- if any of the input arguments is nullIllegalArgumentException- if no matching script key could be found- Since:
- 4.0.0
-
refresh
Refreshes the cache of supported language and country codes from the server.- Parameters:
config- PluginConfig- Returns:
- the joined size of the language codes, country codes and script codes
-
refresh
Refreshes the cache of supported language and country codes from the server.- Parameters:
items- locale items- Returns:
- the joined size of the language codes, country codes and script codes
-
getLanguageCodes
- Returns:
- array of language codes (ISO_639_3_Alpha3 plus optional extensions)
-
getCountryCodes
- Returns:
- array of country codes (ISO_3166_1_Alpha2 plus optional extensions)
-
getCountryItems
- Returns:
- list of country items (ISO_3166_1_Alpha2 plus optional extensions)
-
getLanguageItems
- Returns:
- list of language items (ISO_639_3_Alpha3 plus optional extensions)
-
getCountryItems
- Parameters:
code- constant likeISO_3166_1_Alpha2- Returns:
- array of custom country items
-
getLanguageItems
- Parameters:
code- constant likeISO_639_1_Alpha2- Returns:
- array of custom language items
-
parseLanguageAndCountry
Parse language and country part from a string in the format <lang>delimiter<country>
Parse language and country part from a string in the format <lang>[_- ]<country>.
If the input matches the expected format, a String array is returned with first element set to language and second to country; otherwise null is returned.- Parameters:
in- a locale, e.g. "deu_DE"- Returns:
- String array, first element is language, second is country or null
-
parseLanguageAndCountry
Parse language and country part from a string in the format <lang>delimiter<country>
Parse language and country part from a string in the format <lang>delimiter<country>.
If the input matches the expected format, a String array is returned with first element set to language and second to country; otherwise null is returned.- Parameters:
in- a locale code, e.g. "deu_DE"delimiter- a delimiter, e.g. "_"- Returns:
- String array, first element is language, second is country or null
-