Cldr.LocaleDisplay (Cldr Locale Display v1.1.0) View Source

Implements the CLDR locale display name algorithm to format a t:Cldr.LanguageTag structs for presentation uses.

Link to this section Summary

Functions

Returns a localised display name for a locale.

Returns a localised display name for a locale.

Link to this section Types

Specs

display_options() :: [
  compound_locale: boolean(),
  prefer: atom(),
  locale: Cldr.Locale.locale_name() | Cldr.LanguageTag.t(),
  backend: Cldr.backend()
]

Link to this section Functions

Link to this function

display_name(language_tag, options \\ [])

View Source

Specs

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

Returns a localised display name for a locale.

UI applications often have a requirement to present locale choices to an end user.

This function takes a t.Cldr.LanguageTag and using the CLDR locale display name algorithm produces a string suitable for presentation.

Arguments

  • language_tag is any t:Cldr.LanguageTag or a binary locale name.

  • options is a keyword list of options.

Options

  • :compound_locale is a boolean indicating if the combination of language, script and territory should be used to resolve a language name. The default is true.

  • :prefer signals the preferred name for a subtag when there are alternatives. The default is :default. Few subtags provide alternative renderings. Some of the alternative preferences are:short, :long, :menu and :variant.

  • :locale is a t:Cldr.LanguageTag or any valid locale name returned by Cldr.known_locale_names/1.

  • :backend is any module that includes use Cldr and therefore is a Cldr backend module. The default is Cldr.default_backend!/0.

Returns

  • {:ok, string} representating a name suitable for presentation purposes or

  • {:error, {exception, reason}}

Examples

iex> Cldr.LocaleDisplay.display_name "en"
{:ok, "English"}

iex> Cldr.LocaleDisplay.display_name "en-US"
{:ok, "American English"}

iex> Cldr.LocaleDisplay.display_name "en-US", compound_locale: false
{:ok, "English (United States)"}

iex> Cldr.LocaleDisplay.display_name "en-US-u-ca-gregory-cu-aud"
{:ok, "American English (Gregorian Calendar, Currency: A$)"}

iex> Cldr.LocaleDisplay.display_name "en-US-u-ca-gregory-cu-aud", locale: "fr"
{:ok, "anglais américain (calendrier grégorien, devise : A$)"}

iex> Cldr.LocaleDisplay.display_name "nl-BE"
{:ok, "Flemish"}

iex> Cldr.LocaleDisplay.display_name "nl-BE", compound_locale: false
{:ok, "Dutch (Belgium)"}
Link to this function

display_name!(language_tag, options \\ [])

View Source

Specs

Returns a localised display name for a locale.

UI applications often have a requirement to present locale choices to an end user.

This function takes a t.Cldr.LanguageTag and using the CLDR locale display name algorithm produces a string suitable for presentation.

Arguments

  • language_tag is any t:Cldr.LanguageTag or a binary locale name.

  • options is a keyword list of options.

Options

  • :compound_locale is a boolean indicating if the combination of language, script and territory should be used to resolve a language name. The default is true.

  • :prefer signals the preferred name for a subtag when there are alternatives. The default is :default. Few subtags provide alternative renderings. Some of the alternative preferences are:short, :long, :menu and :variant.

  • :locale is a t:Cldr.LanguageTag or any valid locale name returned by Cldr.known_locale_names/1.

  • :backend is any module that includes use Cldr and therefore is a Cldr backend module. The default is Cldr.default_backend!/0.

Returns

  • a string representation of the language tag suitable for presentation purposes or

  • raises an exception.

Examples

iex> Cldr.LocaleDisplay.display_name! "en"
"English"

iex> Cldr.LocaleDisplay.display_name! "en-US"
"American English"

iex> Cldr.LocaleDisplay.display_name! "en-US", compound_locale: false
"English (United States)"

iex> Cldr.LocaleDisplay.display_name! "en-US-u-ca-gregory-cu-aud"
"American English (Gregorian Calendar, Currency: A$)"

iex> Cldr.LocaleDisplay.display_name! "en-US-u-ca-gregory-cu-aud", locale: "fr"
"anglais américain (calendrier grégorien, devise : A$)"