Provides language name localization functions built on the Unicode CLDR repository.
Language display names are loaded on demand from the locale data provider. Each locale provides localized names for hundreds of language codes in one or more styles.
Styles
Language display names come in several styles:
:standard— the full display name (default).:short— a shorter form when available (e.g., "Azeri" instead of "Azerbaijani"). Falls back to:standardwhen unavailable.:long— a longer form when available (e.g., "Mandarin Chinese" instead of "Chinese"). Falls back to:standardwhen unavailable.:menu— a menu-friendly form with the language family first (e.g., "Chinese, Mandarin" instead of "Mandarin Chinese"). Falls back to:standardwhen unavailable.:variant— an alternative variant name (e.g., "Pushto" instead of "Pashto"). Falls back to:standardwhen unavailable.
Summary
Functions
Returns a sorted list of language codes available in a locale.
Returns the localized display name for a language code.
Same as display_name/2 but raises on error.
Returns a map of all language codes to their localized names in a locale.
Functions
@spec available_languages(Keyword.t()) :: {:ok, [String.t()]} | {:error, Exception.t()}
Returns a sorted list of language codes available in a locale.
Arguments
optionsis a keyword list of options.
Options
:localeis a locale identifier. The default isLocalize.get_locale().
Returns
{:ok, codes}wherecodesis a sorted list of language code strings.{:error, exception}if the locale data cannot be loaded.
Examples
iex> {:ok, codes} = Localize.Language.available_languages()
iex> "en" in codes
true
iex> {:ok, codes} = Localize.Language.available_languages(locale: :de)
iex> "en" in codes
true
@spec display_name(String.t() | Localize.LanguageTag.t(), Keyword.t()) :: {:ok, String.t()} | {:error, Exception.t()}
Returns the localized display name for a language code.
Arguments
languageis a language code string (e.g.,"de","en-GB") or aLocalize.LanguageTag.t/0.optionsis a keyword list of options.
Options
:localeis a locale identifier. The default isLocalize.get_locale().:styleis one of:standard,:short,:long,:menu, or:variant. The default is:standard. If the requested style is not available for a language, falls back to:standard.:fallbackis a boolean. Whentrueand the language is not found in the specified locale, falls back to the default locale. The default isfalse.
Returns
{:ok, name}wherenameis the localized language name.{:error, exception}if the language code is not found in the locale.
Examples
iex> Localize.Language.display_name("de")
{:ok, "German"}
iex> Localize.Language.display_name("en-GB", style: :short)
{:ok, "UK English"}
iex> Localize.Language.display_name("en", locale: :de)
{:ok, "Englisch"}
iex> Localize.Language.display_name("ja")
{:ok, "Japanese"}
@spec display_name!(String.t() | Localize.LanguageTag.t(), Keyword.t()) :: String.t()
Same as display_name/2 but raises on error.
Examples
iex> Localize.Language.display_name!("de")
"German"
iex> Localize.Language.display_name!("en-GB", style: :short)
"UK English"
@spec known_languages(Keyword.t()) :: {:ok, %{required(String.t()) => map()}} | {:error, Exception.t()}
Returns a map of all language codes to their localized names in a locale.
Arguments
optionsis a keyword list of options.
Options
:localeis a locale identifier. The default isLocalize.get_locale().
Returns
{:ok, languages_map}wherelanguages_mapis a map of%{language_code => %{standard: name, ...}}.{:error, exception}if the locale data cannot be loaded.
Examples
iex> {:ok, languages} = Localize.Language.known_languages()
iex> languages["de"]
%{standard: "German"}
iex> {:ok, languages} = Localize.Language.known_languages(locale: :de)
iex> languages["en"]
%{standard: "Englisch"}