Defines plural rule modules for cardinal and ordinal number categories according to the CLDR plural rules specification.
At compile time, this module generates two child modules:
Localize.Number.PluralRule.Cardinal— implements cardinal plural rules (used for counting: "1 item", "2 items").Localize.Number.PluralRule.Ordinal— implements ordinal plural rules (used for ordering: "1st", "2nd", "3rd").
Each generated module contains per-locale plural_rule/2
functions that classify a number into one of the CLDR plural
categories: :zero, :one, :two, :few, :many, or
:other.
Summary
Types
A plural rule definition before compilation.
The plural categories into which a number can be classified.
Functions
Returns the list of possible plural categories.
Returns the plural category for a given number.
Types
Functions
@spec known_plural_types() :: [plural_type(), ...]
Returns the list of possible plural categories.
Returns
- A list of plural type atoms.
Examples
iex> Localize.Number.PluralRule.known_plural_types()
[:zero, :one, :two, :few, :many, :other]
@spec plural_type(number() | Decimal.t(), Keyword.t()) :: plural_type() | {:error, Exception.t()}
Returns the plural category for a given number.
Arguments
numberis an integer, float, or Decimal number.optionsis a keyword list of options.
Options
:localeis any locale identifier string or aLocalize.LanguageTag.t/0. The default is"en".:typeis either:cardinalor:ordinal. The default is:cardinal.
Returns
A plural category atom:
:zero,:one,:two,:few,:many, or:other.{:error, exception}if no plural rules are available for the given locale.
Examples
iex> Localize.Number.PluralRule.plural_type(1, locale: "en")
:one
iex> Localize.Number.PluralRule.plural_type(2, locale: "en")
:other
iex> Localize.Number.PluralRule.plural_type(1, locale: "en", type: :ordinal)
:one
iex> Localize.Number.PluralRule.plural_type(2, locale: "en", type: :ordinal)
:two