Cldr v0.5.0 Cldr.Number.System View Source

Functions to manage number systems which describe the numbering characteristics for a locale.

A number system defines the digits (if they exist in this number system) or or rules (if the number system does not have decimal digits).

The system name is also used as a key to define the separators that are used when formatting a number is this number_system. See Cldr.Number.Symbol.number_symbols_for/2.

Link to this section Summary

Functions

Return the default number system type name

Generate a transliteration map between two character classes

Returns {:ok, digits} for a number system, or an {:error, message} if the number system is not know

Returns digits for a number system, or raises an exception if the number system is not know

Returns the actual number system from a number system type

The unique Cldr number systems names,

Returns the names of the number systems available for a locale or an {:error, message} tuple if the locale is not known

Returns the names of the number systems available for a locale or an {:error, message} tuple if the locale is not known

Returns a list of the known number system types

Return a map of all CLDR number systems and definitions

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 raises if the locale is not known

Returns locale and number systems that have the same digits and separators as the supplied one

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

Returns a number system name for a given locale and number system reference and raises if the number system is not available for the given locale

Number systems that have their own digit characters defined

Link to this section Types

Link to this type types() View Source
types() :: :default | :native | :traditional | :finance

Link to this section Functions

Link to this function default_number_system_type() View Source

Return the default number system type name.

Currently this is :default. Note that this is not the number system itself but the type of the number system. It can be used to find the default number system for a given locale with number_systems_for(locale)[default_number_system()].

Example

iex> Cldr.Number.System.default_number_system_type
:default
Link to this function generate_transliteration_map(from, to) View Source

Generate a transliteration map between two character classes

Link to this function number_system_digits(system_name) View Source

Returns {:ok, digits} for a number system, or an {:error, message} if the number system is not know.

Examples

iex> Cldr.Number.System.number_system_digits(:latn)
{:ok, "0123456789"}

iex> Cldr.Number.System.number_system_digits(:nope)
{:error, {Cldr.UnknownNumberSystemError, "The number system :nope is not known or does not have digits"}}
Link to this function number_system_digits!(system) View Source

Returns digits for a number system, or raises an exception if the number system is not know.

Examples

iex> Cldr.Number.System.number_system_digits! :latn
"0123456789"

Cldr.Number.System.number_system_digits! :nope
** (Cldr.UnknownNumberSystemError) The number system :nope is not known or does not have digits
Link to this function number_system_digits_error(system_name) View Source
Link to this function number_system_for(locale, system_name) View Source

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

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

iex> Cldr.Number.System.number_system_for "th", :native
{:ok, %{digits: "๐๑๒๓๔๕๖๗๘๙", type: :numeric}}

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

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

iex> Cldr.Number.System.number_system_for "en", :finance
{:error, {Cldr.UnknownNumberSystemError, "The number system :finance is not known"}}

iex> Cldr.Number.System.number_system_for "en", :native
{:ok, %{digits: "0123456789", type: :numeric}}
Link to this function number_system_names() View Source
number_system_names() :: [String.t]

The unique Cldr number systems names,

Example

iex> Cldr.Number.System.number_system_names
[:adlm, :ahom, :arab, :arabext, :armn, :armnlow, :bali,
:beng, :bhks, :brah, :cakm, :cham, :cyrl, :deva, :ethi,
:fullwide, :geor, :grek, :greklow, :gujr, :guru, :hanidays,
:hanidec, :hans, :hansfin, :hant, :hantfin, :hebr, :hmng,
:java, :jpan, :jpanfin, :kali, :khmr, :knda, :lana, :lanatham,
:laoo, :latn, :lepc, :limb, :mathbold, :mathdbl, :mathmono,
:mathsanb, :mathsans, :mlym, :modi, :mong, :mroo, :mtei,
:mymr, :mymrshan, :mymrtlng, :newa, :nkoo, :olck, :orya,
:osma, :roman, :romanlow, :saur, :shrd, :sind, :sinh, :sora,
:sund, :takr, :talu, :taml, :tamldec, :telu, :thai, :tibt,
:tirh, :vaii, :wara]
Link to this function number_system_names_for(locale) View Source
number_system_names_for(%Cldr.Locale{currencies: term, date_fields: term, dates: term, list_formats: term, minimum_grouping_digits: term, name: term, number_formats: term, number_symbols: term, number_systems: term, rbnf: term, units: term} | Cldr.Locale.name) :: [String.t]

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

  • locale is any valid locale returned by Cldr.known_locales()

Examples

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

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

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

iex> Cldr.Number.System.number_system_names_for "zz"
{:error, {Cldr.UnknownLocaleError, "The locale \"zz\" is not known."}}
Link to this function number_system_names_for!(locale) View Source

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

  • locale is any valid locale returned by Cldr.known_locales()

Examples

iex> Cldr.Number.System.number_system_names_for! "en"
[:latn]

iex> Cldr.Number.System.number_system_names_for! "th"
[:latn, :thai]

iex> Cldr.Number.System.number_system_names_for! "he"
[:latn, :hebr]

Returns a list of the known number system types.

Note that not all locales support all number system types. :default is available for all locales, the other types configured only in certain locales.

Example

iex> Cldr.Number.System.number_system_types
[:default, :native, :traditional, :finance]
Link to this function number_systems() View Source
number_systems() :: %{}

Return a map of all CLDR number systems and definitions.

Example

iex> Cldr.Number.System.number_systems |> Enum.count
77
Link to this function number_systems_for(locale \\ Cldr.get_current_locale()) View Source
number_systems_for(Cldr.Locale.name | %Cldr.Locale{currencies: term, date_fields: term, dates: term, list_formats: term, minimum_grouping_digits: term, name: term, number_formats: term, number_symbols: term, number_systems: term, rbnf: term, units: term}) :: Map.t

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

  • locale is any valid locale returned by Cldr.known_locales()

Examples

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

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

iex> Cldr.Number.System.number_systems_for "zz"
{:error, {Cldr.UnknownLocaleError, "The locale \"zz\" is not known."}}
Link to this function number_systems_for!(locale) View Source
number_systems_for!(%Cldr.Locale{currencies: term, date_fields: term, dates: term, list_formats: term, minimum_grouping_digits: term, name: term, number_formats: term, number_symbols: term, number_systems: term, rbnf: term, units: term}) :: Map.t

Returns the number systems available for a locale or raises if the locale is not known.

  • locale is any valid locale returned by Cldr.known_locales()

Examples

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

iex> Cldr.Number.System.number_systems_for! "th"
%{default: :latn, native: :thai}
Link to this function number_systems_like(locale, number_system) View Source
number_systems_like(Cldr.Locale.name, binary | atom) ::
  {:ok, List.t} |
  {:error, tuple}

Returns locale and number systems that have the same digits and separators as the supplied one.

Transliterating between locale & number systems is expensive. To avoid unncessary transliteration we look for locale and number systems that have the same digits and separators. Typically we are comparing to locale “en” and number system “latn” since this is what the number formatting routines use as placeholders.

Link to this function system_name_from(system_name, locale \\ Cldr.get_current_locale()) View Source
system_name_from(binary | atom, Cldr.Locale.name | %Cldr.Locale{currencies: term, date_fields: term, dates: term, list_formats: term, minimum_grouping_digits: term, name: term, number_formats: term, number_symbols: term, number_systems: term, rbnf: term, units: term}) :: atom

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

  • system_name is any name of name type

  • locale is any valid locale returned by Cldr.known_locales()

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

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

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

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

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

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 system_name_from!(system_name, locale \\ Cldr.get_current_locale()) View Source

Returns a number system name for a given locale and number system reference and raises if the number system is not available for the given locale.

See Cldr.Number.System.system_name_from/2 for further information.

Number systems that have their own digit characters defined.