Cldr.Locale.canonical_language_tag

You're seeing just the function canonical_language_tag, go back to Cldr.Locale module for more information.
Link to this function

canonical_language_tag(locale_name, backend, options \\ [])

View Source

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 by Cldr.Locale.new/2 or any locale_name returned by Cldr.known_locale_names/1

  • backend is any module that includes use Cldr and therefore is a Cldr backend module

  • options is a keyword list of options

Options

  • :add_likely_subtags is a boolean thatdetermines if subtags that are likely to be applicable to this language tag are added to the language tag. The default is true.

Returns

  • {:ok, language_tag} or

  • {:eror, reason}

Method

  1. The language tag is parsed in accordance with RFC5646

  2. Any language, script or region aliases are replaced. This will replace any obsolete elements with current versions.

  3. 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 is true (the default).

  4. 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: []
  }
}