Cldr v0.5.0 Cldr View Source

Cldr provides functions to localise numbers, currencies, lists and dates/times to an appropriate locale as defined by the CLDR data maintained by the ICU.

The most commonly used functions are:

  • Cldr.Number.to_string/2 for formatting numbers

  • Cldr.Currency.to_string/2 for formatting currencies

  • Cldr.List.to_string/2 for formatting lists

Link to this section Summary

Functions

Returns a list of all the locales defined in the CLDR repository

Returns the directory path name where the CLDR json data is kept

Returns the default locale name

Return the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied

Returns a boolean indicating if the specified locale is configured and available in Cldr

Returns a list of the known locales

Extract the language part from a locale

Returns a boolean indicating if the specified locale is available in CLDR

Returns a list of all requested locales

Set the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied

Returns a list of the locales that are configured, but not known in CLDR

Returns an {:ok, locale} or {:error, {exception, message}} tuple depending on whether the locale is valid and exists in the current configuration

Returns the version of the CLDR repository as a tuple

Link to this section Functions

Link to this function all_locales() View Source
all_locales() :: [Cldr.Locale.t]

Returns a list of all the locales defined in the CLDR repository.

Note that not necessarily all of these locales are available since functions are only generated for configured locales which is most cases will be a subset of locales defined in CLDR.

See also: requested_locales/0 and known_locales/0

Returns the directory path name where the CLDR json data is kept.

Link to this function default_locale() View Source
default_locale() :: [Cldr.Locale.t]

Returns the default locale name.

Example

iex> Cldr.default_locale()
"en"
Link to this function get_current_locale() View Source
get_current_locale() :: Cldr.Locale.t

Return the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied.

Link to this function known_locale?(locale) View Source
known_locale?(Cldr.Locale.t) :: boolean

Returns a boolean indicating if the specified locale is configured and available in Cldr.

Examples

iex> Cldr.known_locale?("en")
true

iex> Cldr.known_locale?("!!")
false
Link to this function known_locales() View Source
known_locales() :: [Cldr.Locale.t] | []

Returns a list of the known locales.

Known locales are those locales which are the subset of all CLDR locales that have been configured for use either directly in the config.exs file or in Gettext.

Link to this function language_from_locale(locale \\ get_current_locale()) View Source

Extract the language part from a locale.

Link to this function locale_exists?(locale) View Source
locale_exists?(Cldr.Locale.t) :: boolean

Returns a boolean indicating if the specified locale is available in CLDR.

The return value depends on whether the locale is defined in the CLDR repository. It does not necessarily mean the locale is configured for Cldr. See also Cldr.known_locale?/1.

Examples

iex> Cldr.locale_exists? "en-AU"
true

iex> Cldr.locale_exists? "en-SA"
false
Link to this function requested_locales() View Source
requested_locales() :: [Cldr.Locale.t] | []

Returns a list of all requested locales.

The list is the combination of configured locales, Gettext locales and the default locale.

See also known_locales/0 and all_locales/0

Link to this function set_current_locale(locale) View Source
set_current_locale(Cldr.Locale.t) :: Cldr.Locale.t

Set the current locale to be used for Cldr functions that take an optional locale parameter for which a locale is not supplied.

Link to this function territory_from_locale(locale \\ get_current_locale()) View Source
Link to this function unknown_locales() View Source
unknown_locales() :: [Cldr.Locale.t] | []

Returns a list of the locales that are configured, but not known in CLDR.

Since we check at compile time for any unknown locales and raise and exception this function should always return an empty list.

Returns an {:ok, locale} or {:error, {exception, message}} tuple depending on whether the locale is valid and exists in the current configuration.

valid_locale/1 is like locale_exists?/1 except that this function returns an :ok or :error tuple which is useful when building a with cascade.

Returns the version of the CLDR repository as a tuple

Example

iex> Cldr.version
{"31", "0", "1"}