Intl.PluralRules (Intl v0.2.0)

Copy Markdown View Source

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.

Functions

select(number, options \\ [])

@spec select(number() | Decimal.t(), Keyword.t()) :: {:ok, atom()} | {:error, term()}

Returns the plural category for a given number.

Arguments

  • number is an integer, float, or Decimal.

  • options is a keyword list of options.

Options

  • :locale is a locale identifier string or atom. The default is the current process locale.

  • :type is :cardinal or :ordinal. The default is :cardinal.

Returns

  • {:ok, category} where category is 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}

select!(number, options \\ [])

@spec select!(number() | Decimal.t(), Keyword.t()) :: atom() | no_return()

Returns the plural category, raising on error.

Same as select/2 but returns the category atom directly or raises.

Arguments

  • number is an integer, float, or Decimal.

  • options is a keyword list of options.

Returns

  • A plural category atom.

Examples

iex> Intl.PluralRules.select!(1, locale: "en")
:one