View Source Bonfire.Common.Localise.Cldr.LocaleDisplay (Bonfire v0.9.10-classic-beta.169)
Manages the display name data for language tags and presents a public API for rendering display names for locales.
Summary
Functions
Returns a localised display name for a locale.
Returns a localised display name for a locale.
Returns the localised display names data for a locale name.
Returns the localised time zone names data for a locale name.
Functions
@spec display_name( Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), Cldr.LocaleDisplay.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 anyt: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 istrue
.: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 at:Cldr.LanguageTag
or any valid locale name returned byCldr.known_locale_names/1
.
Returns
{:ok, string}
representing a name suitable for presentation purposes or{:error, {exception, reason}}
Examples
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "en"
{:ok, "English"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "en-US"
{:ok, "American English"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "en-US", compound_locale: false
{:ok, "English (United States)"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "en-US-u-ca-gregory-cu-aud"
{:ok, "American English (Gregorian Calendar, Currency: A$)"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "en-US-u-ca-gregory-cu-aud", locale: "fr"
{:ok, "anglais américain (calendrier grégorien, devise : A$)"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "nl-BE"
{:ok, "Flemish"}
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name "nl-BE", compound_locale: false
{:ok, "Dutch (Belgium)"}
@spec display_name!( Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), Cldr.LocaleDisplay.display_options() ) :: String.t() | no_return()
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 anyt: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 istrue
.: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 at:Cldr.LanguageTag
or any valid locale name returned byCldr.known_locale_names/1
.:backend
is any module that includesuse Cldr
and therefore is aCldr
backend module. The default isCldr.default_backend!/0
.
Returns
a string representation of the language tag suitable for presentation purposes or
raises an exception.
Examples
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name! "en"
"English"
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name! "en-US"
"American English"
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name! "en-US", compound_locale: false
"English (United States)"
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name! "en-US-u-ca-gregory-cu-aud"
"American English (Gregorian Calendar, Currency: A$)"
iex> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_name! "en-US-u-ca-gregory-cu-aud", locale: "fr"
"anglais américain (calendrier grégorien, devise : A$)"
@spec display_names(Cldr.LanguageTag.t() | Cldr.Locale.locale_name()) :: {:ok, map()} | {:error, {module(), String.t()}}
Returns the localised display names data for a locale name.
Arguments
locale
is any language tag returned byBonfire.Common.Localise.Cldr.LocaleDisplay.new/1
or a locale name in the list returned byBonfire.Common.Localise.Cldr.known_locale_names/0
Returns
- A map of locale display names
Examples
=> Bonfire.Common.Localise.Cldr.LocaleDisplay.display_names("en")
@spec time_zone_names(Cldr.LanguageTag.t() | Cldr.Locale.locale_name()) :: {:ok, map()} | {:error, {module(), String.t()}}
Returns the localised time zone names data for a locale name.
Arguments
locale
is any language tag returned byBonfire.Common.Localise.Cldr.LocaleDisplay.new/1
or a locale name in the list returned byBonfire.Common.Localise.Cldr.known_locale_names/0
Returns
- A map of locale time zone names
Examples
=> Bonfire.Common.Localise.Cldr.LocaleDisplay.time_zone_names("en")