Cldr v0.5.0 Cldr.Number.Cardinal View Source

Implements cardinal plural rules for numbers.

Link to this section Summary

Functions

The configured locales for which plural rules are defined

The locales for which cardinal rules are defined

Lookup the plural cardinal category for a given number in a given locale

The plural rules defined in CLDR

Return the plural rules for a locale

Pluralize a number using plural rules and a substition map

Link to this section Types

Link to this type operand() View Source
operand() :: non_neg_integer

Link to this section Functions

The configured locales for which plural rules are defined

This is the intersection of the Cldr.known_locales and the locales for which plural rules are defined. There are many Cldr locales which don’t have their own plural rules so this list is the intersection of Cldr’s configured locales and those that have rules.

The locales for which cardinal rules are defined

Link to this function plural_rule(number, locale \\ Cldr.get_current_locale(), rounding \\ Math.default_rounding()) View Source

Lookup the plural cardinal category for a given number in a given locale

Identify which category (zero, one, two, few, many or other) a given number in a given locale fits into. This category can then be used to format the number or currency

Link to this function plural_rules() View Source
plural_rules() :: Map.t

The plural rules defined in CLDR.

Link to this function plural_rules_for(locale) View Source
plural_rules_for(Cldr.locale) :: %{}

Return the plural rules for a locale.

The rules are returned in AST form after parsing.

Link to this function pluralize(number, locale, substitutions) View Source
pluralize(Cldr.Math.number_or_decimal, Locale.name, %{}) ::
  String.t |
  nil

Pluralize a number using plural rules and a substition map.

  • number is an integer, float or Decimal

  • locale is any locale returned by Cldr.known_locales()

  • substitutions is a map that maps plural keys to a string. Per the CLDR defintion of plural rules, the valid substitution keys are :zero, :one, :two, :few, :many and :other.

See also Cldr.Ordinal.plural_rule/3 and Cldr.Cardinal.plural_rule/3.

Examples

iex> Cldr.Number.Ordinal.pluralize 1, "en", %{one: "one"}
"one"

iex> Cldr.Number.Ordinal.pluralize 2, "en", %{one: "one"}
nil

iex> Cldr.Number.Ordinal.pluralize 2, "en", %{one: "one", two: "two"}
"two"

iex> Cldr.Number.Ordinal.pluralize 22, "en", %{one: "one", two: "two", other: "other"}
"other"

iex> Cldr.Number.Ordinal.pluralize Decimal.new(1), "en", %{one: "one"}
"one"

iex> Cldr.Number.Ordinal.pluralize Decimal.new(2), "en", %{one: "one"}
nil

iex> Cldr.Number.Ordinal.pluralize Decimal.new(2), "en", %{one: "one", two: "two"}
"two"