MyApp.Cldr.validate_locale

You're seeing just the function validate_locale, go back to MyApp.Cldr module for more information.

Specs

validate_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) ::
  {:ok, Cldr.LanguageTag.t()} | {:error, {module(), String.t()}}

Normalise and validate a locale name.

Arguments

Returns

  • {:ok, language_tag}

  • {:error, reason}

Notes

See rfc5646 for the specification of a language tag and consult Cldr.Rfc5646.Parser for the specification as implemented that includes the CLDR extensions for "u" (locales) and "t" (transforms).

Examples

iex> MyApp.Cldr.validate_locale("en")
{:ok,
%Cldr.LanguageTag{
  backend: MyApp.Cldr,
  canonical_locale_name: "en-Latn-US",
  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_variant: nil
}}


iex> MyApp.Cldr.validate_locale MyApp.Cldr.default_locale()
{:ok,
%Cldr.LanguageTag{
  backend: MyApp.Cldr,
  canonical_locale_name: "en-Latn-001",
  cldr_locale_name: "en-001",
  extensions: %{},
  gettext_locale_name: "en",
  language: "en",
  locale: %{},
  private_use: [],
  rbnf_locale_name: "en",
  requested_locale_name: "en-001",
  script: "Latn",
  territory: :"001",
  transform: %{},
  language_variant: nil
}}

iex> MyApp.Cldr.validate_locale("zzz")
{:error, {Cldr.UnknownLocaleError, "The locale \"zzz\" is not known."}}