View Source ExCatalog.Cldr.Number.System (ex_catalog v1.5.6)

Link to this section Summary

Functions

Returns the actual number system from a number system type.

Returns the number system from a language tag or locale name.

Returns the number systems available for a locale or {:error, message} if the locale is not known.

Returns the number systems available for a locale or {:error, message} if the locale is not known.

Returns a number system name for a given locale and number system reference.

Converts a number into the representation of a non-latin number system.

Converts a number into the representation of a non-latin number system. Returns a converted string or raises on error.

Link to this section Functions

Link to this function

number_system_for(locale, system_name)

View Source
@spec number_system_for(
  Cldr.Locale.locale_reference(),
  Cldr.Number.System.system_name()
) ::
  {:ok, [atom()]} | {:error, {module(), String.t()}}

Returns the actual number system from a number system type.

This function will decode a number system type into the actual number system. If the number system provided can't be decoded it is returned as is.

examples

Examples

iex> ExCatalog.Cldr.Number.System.number_system_for "th", :latn
{:ok, %{digits: "0123456789", type: :numeric}}

iex> ExCatalog.Cldr.Number.System.number_system_for "en", :default
{:ok, %{digits: "0123456789", type: :numeric}}

iex> ExCatalog.Cldr.Number.System.number_system_for "he", :traditional
{:ok, %{rules: "hebrew", type: :algorithmic}}

iex> ExCatalog.Cldr.Number.System.number_system_for "en", :native
{:ok, %{digits: "0123456789", type: :numeric}}

iex> ExCatalog.Cldr.Number.System.number_system_for "en", :finance
{
  :error,
  {Cldr.UnknownNumberSystemError,
    "The number system :finance is unknown for the locale named :en. Valid number systems are %{default: :latn, native: :latn}"}
}
Link to this function

number_system_from_locale(locale)

View Source
@spec number_system_from_locale(Cldr.Locale.locale_reference()) ::
  Cldr.Number.System.system_name()

Returns the number system from a language tag or locale name.

arguments

Arguments

returns

Returns

  • A number system name as an atom

examples

Examples

iex> ExCatalog.Cldr.Number.System.number_system_from_locale "en-US-u-nu-thai"
:thai

iex> ExCatalog.Cldr.Number.System.number_system_from_locale "en-US"
:latn
Link to this function

number_system_names_for(locale)

View Source
@spec number_system_names_for(Cldr.Locale.locale_reference()) ::
  {:ok, [atom()]} | {:error, {module(), String.t()}}

Returns the number systems available for a locale or {:error, message} if the locale is not known.

examples

Examples

iex> ExCatalog.Cldr.Number.System.number_system_names_for "en"
{:ok, [:latn]}

iex> ExCatalog.Cldr.Number.System.number_system_names_for "zz"
{:error, {Cldr.InvalidLanguageError, "The language \"zz\" is invalid"}}
Link to this function

number_system_names_for!(locale)

View Source
Link to this function

number_system_types_for(locale)

View Source
Link to this function

number_systems_for(locale)

View Source
@spec number_systems_for(Cldr.Locale.locale_reference()) ::
  {:ok, map()} | {:error, {module(), String.t()}}

Returns the number systems available for a locale or {:error, message} if the locale is not known.

examples

Examples

iex> ExCatalog.Cldr.Number.System.number_systems_for "en"
{:ok, %{default: :latn, native: :latn}}

iex> ExCatalog.Cldr.Number.System.number_systems_for "th"
{:ok, %{default: :latn, native: :thai}}

iex> ExCatalog.Cldr.Number.System.number_systems_for "zz"
{:error, {Cldr.InvalidLanguageError, "The language \"zz\" is invalid"}}
Link to this function

number_systems_for!(locale)

View Source
Link to this function

number_systems_like(locale, number_system)

View Source
@spec number_systems_like(
  Cldr.Locale.locale_reference(),
  Cldr.Number.System.system_name()
) ::
  {:ok, list()} | {:error, tuple()}
Link to this function

system_name_from(system_name, locale)

View Source
@spec system_name_from(
  Cldr.Number.System.system_name(),
  Cldr.Locale.locale_name() | Cldr.LanguageTag.t()
) :: {:ok, atom()} | {:error, {module(), String.t()}}

Returns a number system name for a given locale and number system reference.

Number systems can be references in one of two ways:

  • As a number system type such as :default, :native, :traditional and :finance. This allows references to a number system for a locale in a consistent fashion for a given use

  • WIth the number system name directly, such as :latn, :arab or any of the other 70 or so

This function dereferences the supplied system_name and returns the actual system name.

examples

Examples

ex> ExCatalog.Cldr.Number.System.system_name_from(:default, "en")
{:ok, :latn}

iex> ExCatalog.Cldr.Number.System.system_name_from("latn", "en")
{:ok, :latn}

iex> ExCatalog.Cldr.Number.System.system_name_from(:native, "en")
{:ok, :latn}

iex> ExCatalog.Cldr.Number.System.system_name_from(:nope, "en")
{
  :error,
  {Cldr.UnknownNumberSystemError, "The number system :nope is unknown"}
}

Note that return value is not guaranteed to be a valid number system for the given locale as demonstrated in the third example.

Link to this function

to_system(number, system)

View Source

Converts a number into the representation of a non-latin number system.

This function converts numbers to a known number system only, it does not provide number formatting.

There are two types of number systems in CLDR:

  • :numeric in which the number system defines a direct mapping between the latin digits 0..9 into a the number system equivalent. In this case, to_system/2 invokes Cldr.Number.Transliterate.transliterate_digits/3 for the given number.

  • :algorithmic in which the number system does not have the same structure as the :latn number system and therefore the conversion is done algorithmically. For CLDR the algorithm is implemented through Cldr.Rbnf rulesets. These rulesets are considered by CLDR to be less rigorous than the :numeric number systems and caution and testing for a specific use case is recommended.

examples

Examples

iex> ExCatalog.Cldr.Number.System.to_system 123456, :hebr
{:ok, "קכ״ג׳תנ״ו"}

iex> ExCatalog.Cldr.Number.System.to_system 123, :hans
{:ok, "一百二十三"}

iex> ExCatalog.Cldr.Number.System.to_system 123, :hant
{:ok, "一百二十三"}

iex> ExCatalog.Cldr.Number.System.to_system 123, :hansfin
{:ok, "壹佰贰拾叁"}
Link to this function

to_system!(number, system_name)

View Source

Converts a number into the representation of a non-latin number system. Returns a converted string or raises on error.

See ExCatalog.Cldr.Number.System.to_system/2 for further information.

examples

Examples

iex> ExCatalog.Cldr.Number.System.to_system! 123, :hans
"一百二十三"

iex> ExCatalog.Cldr.Number.System.to_system! 123, :hant
"一百二十三"

iex> ExCatalog.Cldr.Number.System.to_system! 123, :hansfin
"壹佰贰拾叁"