Cldr.Locale.add_likely_subtags

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

add_likely_subtags(language_tag)

View Source

Replace empty subtags within a Cldr.LanguageTag.t/0 with the most likely subtag.

Options

A subtag is called empty if it has a missing script or territory 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: x<sub>s</sub> is in the source, x<sub>m</sub> is in a match, and x<sub>r</sub> is in the final result.

Lookup

Lookup each of the following in order, and stops on the first match:

  • language<sub>s</sub>-script<sub>s</sub>-region<sub>s</sub>
  • language<sub>s</sub>-region<sub>s</sub>
  • language<sub>s</sub>-script<sub>s</sub>
  • language<sub>s</sub>
  • und-script<sub>s</sub>

Returns

  • If there is no match,either return

    • an error value, or
    • the match for und
  • Otherwise there is a match = language<sub>m</sub>-script<sub>m</sub>-region<sub>m</sub>

  • Let x<sub>r</sub> = x<sub>s</sub> if x<sub>s</sub> is not empty, and x<sub>m</sub> otherwise.

  • Return the language tag composed of language<sub>r</sub>-script<sub>r</sub>-region<sub>r</sub> + variants + extensions .

Example

iex> Cldr.Locale.add_likely_subtags Cldr.LanguageTag.parse!("zh-SG")
%Cldr.LanguageTag{
  backend: nil,
  canonical_locale_name: nil,
  cldr_locale_name: nil,
  language_subtags: [],
  extensions: %{},
  gettext_locale_name: nil,
  language: "zh",
  locale: %{},
  private_use: [],
  rbnf_locale_name: nil,
  requested_locale_name: "zh-SG",
  script: "Hans",
  territory: :SG,
  transform: %{},
  language_variant: nil
}