Plural category selection for numeric ranges.
Implements the TR35 plural ranges rules: the plural category of a range like "1–2 days" is derived from the categories of its endpoints using per-language range rules from the CLDR supplemental data. The primary functions are plural_rule/3 for endpoint categories and plural_rule_for/3 for endpoint numbers.
Summary
Functions
Returns the plural category for a range given the categories of its endpoints.
Returns the plural category for a range given the numbers of its endpoints.
Functions
@spec plural_rule(atom(), atom(), atom() | String.t() | Localize.LanguageTag.t()) :: {:ok, atom()} | {:error, Exception.t()}
Returns the plural category for a range given the categories of its endpoints.
Arguments
start_categoryis the plural category of the range start.end_categoryis the plural category of the range end.localeis a locale identifier atom, string, or aLocalize.LanguageTag.t/0struct.
Returns
{:ok, category}wherecategoryis one of:zero,:one,:two,:few,:many, or:other.{:error, exception}if the locale is invalid.
Examples
iex> Localize.Number.PluralRule.Range.plural_rule(:one, :other, "fr")
{:ok, :other}
iex> Localize.Number.PluralRule.Range.plural_rule(:one, :one, "fr")
{:ok, :one}
@spec plural_rule_for( number() | Decimal.t(), number() | Decimal.t(), atom() | String.t() | Localize.LanguageTag.t() ) :: {:ok, atom()} | {:error, Exception.t()}
Returns the plural category for a range given the numbers of its endpoints.
The endpoint categories are selected with the locale's cardinal plural rules, then combined with plural_rule/3.
Arguments
start_numberis the start of the range (integer, float, or Decimal).end_numberis the end of the range.localeis a locale identifier atom, string, or aLocalize.LanguageTag.t/0struct.
Returns
{:ok, category}wherecategoryis one of:zero,:one,:two,:few,:many, or:other.{:error, exception}if the locale is invalid.
Examples
iex> Localize.Number.PluralRule.Range.plural_rule_for(0, 1, "fr")
{:ok, :one}
iex> Localize.Number.PluralRule.Range.plural_rule_for(1, 2, "fr")
{:ok, :other}