Cldr v0.10.0 Cldr.Locale View Source
Parse and process locale json as defined by Unicode
Link to this section Summary
Functions
Given a source locale X, return a locale Y where the empty subtags have been filled in by the most likely subtags
Normalize the casing of a locale name
Normalize the format of a territory code
Given a source locale X, to return a locale Y where the aliases have been substituted with their non-deprecated alternatives
Link to this section Types
The name of a locale in a string format
Link to this section Functions
Given a source locale X, return a locale Y where the empty subtags have been filled in by the most likely subtags.
This is written as X ⇒ Y (“X maximizes to Y”).
A subtag is called empty if it is a missing script or region subtag, or it is
a base language subtag with the value und
. In the description below,
a subscript on a subtag x indicates which tag it is from: xs is in the
source, xm is in a match, and xr is in the final result.
This operation is performed in the following way:
Lookup
Lookup each of the following in order, and stop on the first match:
- languages-scripts-regions
- languages-regions
- languages-scripts
- languages
- und-scripts
Return
If there is no match,either return
- an error value, or
- the match for
und
Otherwise there is a match = languagem-scriptm-regionm
Let xr = xs if xs is not empty, and xm otherwise.
Return the language tag composed of languager-scriptr-regionr + variants + extensions .
Example
iex> Cldr.Locale.add_likely_subtags Cldr.LanguageTag.parse!("zh-SG")
%Cldr.LanguageTag{extensions: %{}, language: "zh", locale: %{}, private_use: [],
region: "SG", script: "Hans", transform: %{}, variant: nil}
Normalize the casing of a locale name.
Locale names are case insensitive but certain common case is followed:
- lower case for a language
- capitalized for a script
- upper case for a region
Note this function is intended to support only the CLDR
names which have limited structure. For proper parsing
of local names and language tags, see Cldr.Locale.canonical_language_tag/1
Examples
iex> Cldr.Locale.normalize_locale_name "zh_hant"
"zh-Hant"
iex> Cldr.Locale.normalize_locale_name "en_us"
"en-US"
iex> Cldr.Locale.normalize_locale_name "EN"
"en"
iex> Cldr.Locale.normalize_locale_name "ca_es_valencia"
"ca-ES-VALENCIA"
Normalize the format of a territory code.
Given a source locale X, to return a locale Y where the aliases have been substituted with their non-deprecated alternatives.
Replace any deprecated subtags with their canonical values using the alias data. Use the first value in the replacement list, if it exists. Language tag replacements may have multiple parts, such as
sh
➞sr_Latn
ormo
➞ro_MD
. In such a case, the original script and/or region are retained if there is one. Thussh_Arab_AQ
➞sr_Arab_AQ
, notsr_Latn_AQ
.Remove the script code ‘Zzzz’ and the region code ‘ZZ’ if they occur.
Get the components of the cleaned-up source tag (languages, scripts, and regions), plus any variants and extensions.
Examples
iex> Cldr.Locale.substitute_aliases Cldr.LanguageTag.Parser.parse!("en-US")
%Cldr.LanguageTag{extensions: %{}, language: "en", locale: %{}, private_use: [],
region: "US", script: nil, transform: %{}, variant: nil}
iex> Cldr.Locale.substitute_aliases Cldr.LanguageTag.Parser.parse!("sh_Arab_AQ")
%Cldr.LanguageTag{extensions: %{}, language: "sr", locale: %{}, private_use: [],
region: "AQ", script: "Arab", transform: %{}, variant: nil}
iex> Cldr.Locale.substitute_aliases Cldr.LanguageTag.Parser.parse!("sh_AQ")
%Cldr.LanguageTag{extensions: %{}, language: "sr", locale: %{}, private_use: [],
region: "AQ", script: "Latn", transform: %{}, variant: nil}
iex> Cldr.Locale.substitute_aliases Cldr.LanguageTag.Parser.parse!("mo")
%Cldr.LanguageTag{extensions: %{}, language: "ro", locale: %{}, private_use: [],
region: "MD", script: nil, transform: %{}, variant: nil}