BeamLabCountries.Translations (beamlab_countries v2.0.1)

View Source

Module for looking up country names in different languages.

Supports 23 languages: ar, cs, de, en, es, et, fr, hi, id, it, ja, ko, nl, pl, pt, ro, ru, sv, th, tr, uk, vi, zh

Examples

iex> BeamLabCountries.Translations.get_name("PL", "de")
"Polen"

iex> BeamLabCountries.Translations.get_name("US", "ja")
"米国"

iex> BeamLabCountries.Translations.get_name("DE", "pl")
"Niemcy"

iex> BeamLabCountries.Translations.get_name("EE", "et")
"Eesti"

Summary

Functions

Returns the country name in all supported languages.

Returns the country name in the specified language.

Checks if a locale is supported.

Returns list of supported locale codes.

Functions

get_all_names(country_code)

@spec get_all_names(String.t()) :: %{optional(String.t()) => String.t()}

Returns the country name in all supported languages.

Examples

iex> names = BeamLabCountries.Translations.get_all_names("PL")
iex> names["en"]
"Poland"
iex> names["de"]
"Polen"

get_name(country_code, locale, opts \\ [])

@spec get_name(String.t(), String.t(), keyword()) :: String.t() | nil

Returns the country name in the specified language.

The locale is case-insensitive. A regional locale such as "de-AT" or "pt_BR" is reduced to its language ("de", "pt") when it is not supported as such.

Options

  • :fallback - a locale to use when the country has no name in locale (including when locale is not supported). Defaults to nil, which returns nil.

Examples

iex> BeamLabCountries.Translations.get_name("PL", "en")
"Poland"

iex> BeamLabCountries.Translations.get_name("PL", "de")
"Polen"

iex> BeamLabCountries.Translations.get_name("PL", "de-AT")
"Polen"

iex> BeamLabCountries.Translations.get_name("JP", "zh")
"日本"

iex> BeamLabCountries.Translations.get_name("XX", "en")
nil

iex> BeamLabCountries.Translations.get_name("PL", "xx")
nil

iex> BeamLabCountries.Translations.get_name("PL", "xx", fallback: "en")
"Poland"

locale_supported?(locale)

@spec locale_supported?(String.t()) :: boolean()

Checks if a locale is supported.

Examples

iex> BeamLabCountries.Translations.locale_supported?("en")
true

iex> BeamLabCountries.Translations.locale_supported?("xx")
false

supported_locales()

@spec supported_locales() :: [String.t()]

Returns list of supported locale codes.

Examples

iex> "en" in BeamLabCountries.Translations.supported_locales()
true

iex> "pl" in BeamLabCountries.Translations.supported_locales()
true