Plural-sensitive number categorization, modelled on
Intl.PluralRules.
Returns the CLDR plural category (:zero, :one, :two, :few,
:many, or :other) for a given number and locale.
Delegates to Localize.Number.PluralRule for the underlying
plural rule evaluation.
Summary
Functions
Returns the plural category for a given number.
Returns the plural category, raising on error.
Returns the plural category for a range of numbers.
Returns the plural category for a range, raising on error.
Functions
Returns the plural category for a given number.
Arguments
numberis an integer, float, orDecimal.optionsis a keyword list of options.
Options
:localeis a locale identifier string or atom. The default is the current process locale.:typeis:cardinalor:ordinal. The default is:cardinal.
Returns
{:ok, category}wherecategoryis one of:zero,:one,:two,:few,:many, or:other.{:error, reason}if the locale or number is invalid.
Examples
iex> Intl.PluralRules.select(1, locale: "en")
{:ok, :one}
iex> Intl.PluralRules.select(2, locale: "en")
{:ok, :other}
iex> Intl.PluralRules.select(2, locale: "en", type: :ordinal)
{:ok, :two}
Returns the plural category, raising on error.
Same as select/2 but returns the category atom directly
or raises.
Arguments
numberis an integer, float, orDecimal.optionsis a keyword list of options.
Returns
- A plural category atom.
Examples
iex> Intl.PluralRules.select!(1, locale: "en")
:one
@spec select_range(number() | Decimal.t(), number() | Decimal.t(), Keyword.t()) :: {:ok, atom()} | {:error, term()}
Returns the plural category for a range of numbers.
Modelled on the JS Intl.PluralRules.selectRange(). The category
of a range like "1–2 days" is selected from the categories of the
endpoints using the CLDR plural-ranges data for the locale.
Arguments
start_numberis the start of the range.end_numberis the end of the range.optionsis a keyword list of options.
Options
:localeis a locale identifier string or atom. The default is the current process locale.
Returns
{:ok, category}wherecategoryis one of:zero,:one,:two,:few,:many, or:other.{:error, reason}if the locale or numbers are invalid.
Examples
iex> Intl.PluralRules.select_range(1, 2, locale: "fr")
{:ok, :other}
iex> Intl.PluralRules.select_range(0, 1, locale: "fr")
{:ok, :one}
iex> Intl.PluralRules.select_range(102, 201, locale: "en")
{:ok, :other}
@spec select_range!(number() | Decimal.t(), number() | Decimal.t(), Keyword.t()) :: atom() | no_return()
Returns the plural category for a range, raising on error.
Same as select_range/3 but returns the category atom directly
or raises.
Arguments
start_numberis the start of the range.end_numberis the end of the range.optionsis a keyword list of options.
Returns
- A plural category atom.
Examples
iex> Intl.PluralRules.select_range!(1, 2, locale: "fr")
:other