Cldr v2.2.7 MyApp.Cldr View Source
Provides the core functions to retrieve and manage the CLDR data that supports formatting and localisation.
It provides the core functions to access formatted CLDR data, set and retrieve a current locale and validate certain core data types such as locales, currencies and territories.
Link to this section Summary
Functions
Returns the default locale
Returns the default territory when a locale does not specify one and none can be inferred
Return the current locale to be used for Cldr
functions that
take an optional locale parameter for which a locale is not supplied
Returns either the Gettext locale_name
in Cldr format or
false
based upon whether the locale name is configured in
Gettext
Returns a boolean indicating if the specified locale name is configured and available in Gettext
Returns a list of GetText locale names but in CLDR format with
underscore replaced by hyphen in order to facilitate comparisons
with Cldr
locale names
Returns either the locale_name
or false
based upon
whether the locale name is configured in Cldr
Returns a boolean indicating if the specified locale name is configured and available in Cldr
Returns a list of the known locale names
Returns a list of atoms representing the number systems types known to Cldr
Returns either the RBNF locale_name
or false
based upon
whether the locale name is configured in Cldr
and has RBNF rules defined
Returns a boolean indicating if the specified locale name is configured and available in Cldr and supports rules based number formats (RBNF)
Returns a list of locale names which have rules-based number formats (RBNF)
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 names that are configured, but not known in CLDR
Normalise and validate a locale name
Normalise and validate a number system type
Link to this section Functions
available_locale_name?(locale_name) View Source
default_locale()
View Source
default_locale() :: Cldr.LanguageTag.t()
default_locale() :: Cldr.LanguageTag.t()
Returns the default locale
.
Example
iex> MyApp.Cldr.default_locale()
%Cldr.LanguageTag{
canonical_locale_name: "en-Latn-001",
cldr_locale_name: "en-001",
language_subtags: [],
extensions: %{},
gettext_locale_name: "en",
language: "en",
locale: %{},
private_use: [],
rbnf_locale_name: "en",
requested_locale_name: "en-001",
script: "Latn",
territory: "001",
transform: %{},
language_variant: nil
}
default_territory()
View Source
default_territory() :: atom()
default_territory() :: atom()
Returns the default territory when a locale does not specify one and none can be inferred.
Example
iex> MyApp.Cldr.default_territory()
:"001"
get_locale()
View Source
get_locale() :: Cldr.LanguageTag.t()
get_locale() :: Cldr.LanguageTag.t()
Return the current locale to be used for Cldr
functions that
take an optional locale parameter for which a locale is not supplied.
Example
iex> MyApp.Cldr.put_locale("pl")
iex> MyApp.Cldr.get_locale
%Cldr.LanguageTag{
canonical_locale_name: "pl-Latn-PL",
cldr_locale_name: "pl",
extensions: %{},
language: "pl",
locale: %{},
private_use: [],
rbnf_locale_name: "pl",
territory: "PL",
requested_locale_name: "pl",
script: "Latn",
transform: %{},
language_variant: nil
}
known_calendars() View Source
known_currencies() View Source
known_gettext_locale_name(locale_name)
View Source
known_gettext_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
known_gettext_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
Returns either the Gettext locale_name
in Cldr format or
false
based upon whether the locale name is configured in
Gettext
.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_gettext_locale_names/0
Examples
iex> MyApp.Cldr.known_gettext_locale_name "en"
"en"
iex> MyApp.Cldr.known_gettext_locale_name "en-SA"
false
known_gettext_locale_name?(locale_name)
View Source
known_gettext_locale_name?(Cldr.Locale.locale_name()) :: boolean()
known_gettext_locale_name?(Cldr.Locale.locale_name()) :: boolean()
Returns a boolean indicating if the specified locale name is configured and available in Gettext.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
Examples
iex> MyApp.Cldr.known_gettext_locale_name?("en")
true
iex> MyApp.Cldr.known_gettext_locale_name?("!!")
false
known_gettext_locale_names()
View Source
known_gettext_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
known_gettext_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
Returns a list of GetText locale names but in CLDR format with
underscore replaced by hyphen in order to facilitate comparisons
with Cldr
locale names.
known_locale_name(locale_name)
View Source
known_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
known_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
Returns either the locale_name
or false
based upon
whether the locale name is configured in Cldr
.
This is helpful when building a list of or
expressions
to return the first known locale name from a list.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
Examples
iex> MyApp.Cldr.known_locale_name "en-AU"
"en-AU"
iex> MyApp.Cldr.known_locale_name "en-SA"
false
known_locale_name?(locale_name)
View Source
known_locale_name?(Cldr.Locale.locale_name()) :: boolean()
known_locale_name?(Cldr.Locale.locale_name()) :: boolean()
Returns a boolean indicating if the specified locale name is configured and available in Cldr.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
Examples
iex> MyApp.Cldr.known_locale_name?("en")
true
iex> MyApp.Cldr.known_locale_name?("!!")
false
known_locale_names() View Source
Returns a list of the known locale names.
Known locales are those locales which
are the subset of all CLDR locales that
have been configured for use either
in this module or in Gettext
.
known_number_system_types() View Source
Returns a list of atoms representing the number systems types known to Cldr
.
Example
iex> MyApp.Cldr.known_number_system_types
[:default, :finance, :native, :traditional]
known_number_systems() View Source
known_rbnf_locale_name(locale_name)
View Source
known_rbnf_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
known_rbnf_locale_name(Cldr.Locale.locale_name()) :: String.t() | false
Returns either the RBNF locale_name
or false
based upon
whether the locale name is configured in Cldr
and has RBNF rules defined.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
Examples
iex> MyApp.Cldr.known_rbnf_locale_name "en"
"en"
iex> MyApp.Cldr.known_rbnf_locale_name "en-SA"
false
known_rbnf_locale_name?(locale_name)
View Source
known_rbnf_locale_name?(Cldr.Locale.locale_name()) :: boolean()
known_rbnf_locale_name?(Cldr.Locale.locale_name()) :: boolean()
Returns a boolean indicating if the specified locale name is configured and available in Cldr and supports rules based number formats (RBNF).
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
Examples
iex> MyApp.Cldr.known_rbnf_locale_name?("en")
true
iex> MyApp.Cldr.known_rbnf_locale_name?("!!")
false
known_rbnf_locale_names()
View Source
known_rbnf_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
known_rbnf_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
Returns a list of locale names which have rules-based number formats (RBNF).
known_territories() View Source
put_locale(locale_name)
View Source
put_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) ::
{:ok, Cldr.LanguageTag.t()} | {:error, {module(), String.t()}}
put_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) :: {:ok, Cldr.LanguageTag.t()} | {:error, {module(), String.t()}}
Set the current locale to be used for Cldr
functions that
take an optional locale parameter for which a locale is not supplied.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byMyApp.Cldr.Locale.new!/1
See rfc5646 for the specification
of a language tag and consult Cldr.Rfc5646.Parser
for the
specification as implemented that includes the CLDR extensions for
"u" (locales) and "t" (transforms).
Examples
iex> MyApp.Cldr.put_locale("en")
{:ok,
%Cldr.LanguageTag{
canonical_locale_name: "en-Latn-US",
cldr_locale_name: "en",
language_subtags: [],
extensions: %{},
gettext_locale_name: "en",
language: "en",
locale: %{},
private_use: [],
rbnf_locale_name: "en",
requested_locale_name: "en",
script: "Latn",
territory: "US",
transform: %{},
language_variant: nil
}}
iex> MyApp.Cldr.put_locale("invalid-locale")
{:error, {Cldr.LanguageTag.ParseError,
"Expected a BCP47 language tag. Could not parse the remaining \"le\" starting at position 13"}}
unknown_locale_names()
View Source
unknown_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
unknown_locale_names() :: [Cldr.Locale.locale_name(), ...] | []
Returns a list of the locales names that are configured, but not known in CLDR.
Since there is a compile-time exception raised if there are any unknown locales this function should always return an empty list.
validate_calendar(calendar) View Source
validate_currency(currency) View Source
validate_locale(locale)
View Source
validate_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) ::
{:ok, String.t()} | {:error, {module(), String.t()}}
validate_locale(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) :: {:ok, String.t()} | {:error, {module(), String.t()}}
Normalise and validate a locale name.
Arguments
locale
is any valid locale name returned byMyApp.Cldr.known_locale_names/0
or aCldr.LanguageTag
struct returned byMyApp.Cldr.Locale.new!/1
Returns
{:ok, language_tag}
{:error, reason}
Notes
See rfc5646 for the specification
of a language tag and consult Cldr.Rfc5646.Parser
for the
specification as implemented that includes the CLDR extensions for
"u" (locales) and "t" (transforms).
Examples
iex> MyApp.Cldr.validate_locale("en")
{:ok,
%Cldr.LanguageTag{
canonical_locale_name: "en-Latn-US",
cldr_locale_name: "en",
extensions: %{},
gettext_locale_name: "en",
language: "en",
locale: %{},
private_use: [],
rbnf_locale_name: "en",
requested_locale_name: "en",
script: "Latn",
territory: "US",
transform: %{},
language_variant: nil
}}
iex> MyApp.Cldr.validate_locale MyApp.Cldr.default_locale()
{:ok,
%Cldr.LanguageTag{
canonical_locale_name: "en-Latn-001",
cldr_locale_name: "en-001",
extensions: %{},
gettext_locale_name: "en",
language: "en",
locale: %{},
private_use: [],
rbnf_locale_name: "en",
requested_locale_name: "en-001",
script: "Latn",
territory: "001",
transform: %{},
language_variant: nil
}}
iex> MyApp.Cldr.validate_locale("zzz")
{:error, {Cldr.UnknownLocaleError, "The locale \"zzz\" is not known."}}
validate_number_system(number_system) View Source
validate_number_system_type(number_system_type) View Source
Normalise and validate a number system type.
Arguments
number_system_type
is any number system type returned byCldr.known_number_system_types/1
Returns
{:ok, normalized_number_system_type}
or{:error, {exception, message}}
Examples
iex> MyApp.Cldr.validate_number_system_type :default
{:ok, :default}
iex> MyApp.Cldr.validate_number_system_type :traditional
{:ok, :traditional}
iex> MyApp.Cldr.validate_number_system_type :latn
{
:error,
{Cldr.UnknownNumberSystemTypeError, "The number system type :latn is unknown"}
}
iex> MyApp.Cldr.validate_number_system_type "bork"
{
:error,
{Cldr.UnknownNumberSystemTypeError, "The number system type \"bork\" is invalid"}
}