Cldr.Locale.canonical_language_tag
canonical_language_tag
, go back to Cldr.Locale module for more information.
Specs
canonical_language_tag( locale_name() | Cldr.LanguageTag.t(), Cldr.backend(), Keyword.t() ) :: {:ok, Cldr.LanguageTag.t()} | {:error, {module(), String.t()}}
Parses a locale name and returns a Cldr.LanguageTag
struct
that represents a locale.
Arguments
language_tag
is any language tag returned byCldr.Locale.new/2
or anylocale_name
returned byCldr.known_locale_names/1
backend
is any module that includesuse Cldr
and therefore is aCldr
backend moduleoptions
is a keyword list of options
Options
:add_likely_subtags
is aboolean
thatdetermines if subtags that are likely to be applicable to this language tag are added to the language tag. The default istrue
.
Returns
{:ok, language_tag}
or{:eror, reason}
Method
The language tag is parsed in accordance with RFC5646
Any language, script or region aliases are replaced. This will replace any obsolete elements with current versions.
If a territory, script or language variant is not specified, then a default is provided using the CLDR information returned by
Cldr.Locale.likely_subtags/1
if the option:add_likely_subtags
istrue
(the default).A
Cldr
locale name is selected that is the nearest fit to the requested locale.
Example
iex> Cldr.Locale.canonical_language_tag("en", TestBackend.Cldr)
{
:ok,
%Cldr.LanguageTag{
backend: TestBackend.Cldr,
canonical_locale_name: "en",
cldr_locale_name: "en",
extensions: %{},
gettext_locale_name: "en",
language: "en",
locale: %{},
private_use: [],
rbnf_locale_name: "en",
requested_locale_name: "en",
script: :Latn,
territory: :US,
transform: %{},
language_variants: []
}
}