Localize.Inputs.Number.Symbols (Localize.Inputs.Number v0.2.2)

Copy Markdown View Source

Locale-derived display data for number form inputs.

Returns the decimal/grouping separator characters, the active number system, the locale's minus sign and its digit grouping — everything a JS hook needs to render a number in the user's locale.

All locale lookups go through Localize.validate_locale/1; the resulting Localize.LanguageTag.t/0's :cldr_locale_id is the canonical id reported back. Number system resolution goes through Localize.Number.System.number_system_from_locale/1 so Arabic-Indic, Persian, and other non-Latin digit systems work out of the box.

Summary

Types

t()

Locale display data resolved by number_for_locale/1.

Functions

Resolves display data for the given locale.

Types

t()

@type t() :: %Localize.Inputs.Number.Symbols{
  decimal: String.t(),
  group: String.t(),
  grouping: %{first: non_neg_integer(), rest: non_neg_integer()},
  language_tag: Localize.LanguageTag.t(),
  locale: atom(),
  minus_sign: String.t(),
  number_system: atom()
}

Locale display data resolved by number_for_locale/1.

  • :locale — the canonical CLDR locale id (atom).

  • :language_tag — the full Localize.LanguageTag.t/0.

  • :number_system — the active number system (:latn, :arab, :arabext, …).

  • :decimal — the locale's decimal separator character.

  • :group — the locale's grouping separator character.

  • :minus_sign — the locale's minus sign character.

  • :grouping — the integer digit grouping of the locale's standard number format: :first is the size of the group next to the decimal separator and :rest the size of every group to its left (%{first: 3, rest: 3} for 1,234,567, %{first: 3, rest: 2} for 12,34,567).

Functions

number_for_locale(locale \\ nil)

@spec number_for_locale(Localize.LanguageTag.t() | atom() | String.t() | nil) ::
  {:ok, t()} | {:error, Exception.t()}

Resolves display data for the given locale.

Arguments

Returns

Examples

iex> {:ok, info} = Localize.Inputs.Number.Symbols.number_for_locale(:en)
iex> {info.decimal, info.group, info.number_system}
{".", ",", :latn}

iex> {:ok, info} = Localize.Inputs.Number.Symbols.number_for_locale(:de)
iex> {info.decimal, info.group}
{",", "."}

iex> {:ok, info} = Localize.Inputs.Number.Symbols.number_for_locale(:hi)
iex> info.grouping
%{first: 3, rest: 2}