Cldr.put_locale

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

put_locale(backend \\ nil, locale)

View Source

Specs

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

Set the current process's locale for a specified backend or for all backends.

Arguments

  • backend is any module that includes use Cldr and therefore is a Cldr backend module. The default is to set the locale for all backends.

  • locale is any valid locale name returned by Cldr.known_locale_names/1 or a Cldr.LanguageTag struct returned by Cldr.Locale.new!/2. It may also be a map that contains the keys "cldr_locale" and "cldr_backend" which is the shape of a Phoenix and Plug session making it easy to set the locale from a session.

Returns

  • {:ok, locale}

Behaviour

  1. If no backend is provided and the locale is a Cldr.LanguageTag.t then the the locale is set as the default for the current process

Notes

See rfc5646 for the specification of a language tag

Examples

iex> Cldr.put_locale(TestBackend.Cldr, "en")
{:ok,
 %Cldr.LanguageTag{
   backend: TestBackend.Cldr,
   canonical_locale_name: "en-Latn-US",
   cldr_locale_name: "en",
   language_subtags: [],
   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> Cldr.put_locale(TestBackend.Cldr, "invalid-locale!")
{:error, {Cldr.LanguageTag.ParseError,
  "Expected a BCP47 language tag. Could not parse the remaining \"!\" starting at position 15"}}