Cldr.Print.Backend.Number.Cardinal (ex_cldr_print v0.4.0) View Source
Implements cardinal plural rules for numbers.
Link to this section Summary
Functions
The locale names for which plural rules are defined.
The configured locales for which plural rules are defined.
Return the plural key for a given number in a given locale
Returns all the plural rules defined in CLDR.
Return the plural rules for a locale.
Pluralize a number using cardinal plural rules and a substition map.
Link to this section Functions
The locale names for which plural rules are defined.
Specs
known_locale_names() :: [Cldr.Locale.locale_name(), ...]
The configured locales for which plural rules are defined.
Returns the intersection of Cldr.Print.Backend.known_locale_names/0 and
the locales for which Cardinal 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.
Specs
plural_rule( Cldr.Math.number_or_decimal(), Cldr.Locale.locale_name() | Cldr.LanguageTag.t(), atom() | pos_integer() ) :: Cldr.Number.PluralRule.plural_type()
Return the plural key for a given number in a given locale
Returns which plural key (:zero, :one, :two, :few,
:many or :other) a given number fits into within the
context of a given locale.
Note that these key names should not be interpreted
literally. For example, the key returned from
Cldr.Number.Ordinal.plural_rule(0, "en") is actually
:other, not :zero.
This key can then be used to format a number, date, time, unit, list or other content in a plural-sensitive way.
Arguments
numberis anyinteger,floatorDecimallocaleis any locale returned byCldr.Locale.new!/2or anylocale_namereturned byCldr.Print.Backend.known_locale_names/0roundingis one of[:down, :up, :ceiling, :floor, :half_even, :half_up, :half_down]. The default is:half_even.
Examples
iex> Cldr.Print.Backend.Number.Cardinal.plural_rule 0, "fr"
:one
iex> Cldr.Print.Backend.Number.Cardinal.plural_rule 0, "en"
:other
Specs
plural_rules() :: map()
Returns all the plural rules defined in CLDR.
Specs
plural_rules_for(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) :: [ {atom(), list()}, ... ]
Return the plural rules for a locale.
Arguments
localeis any locale returned byCldr.Print.Backend.Locale.new!/1or anylocale_namereturned byCldr.Print.Backend.known_locale_names/0
The rules are returned in AST form after parsing.
Specs
pluralize( Cldr.Math.number_or_decimal() | %Range{first: term(), last: term()}, Cldr.LanguageTag.t() | Cldr.Locale.locale_name(), %{} ) :: any()
Pluralize a number using cardinal plural rules and a substition map.
Arguments
numberis an integer, float or Decimallocaleis any locale returned byCldr.Print.Backend.Locale.new!/1or anylocale_namereturned byCldr.Print.Backend.known_locale_names/0substitutionsis a map that maps plural keys to a string. The valid substitution keys are:zero,:one,:two,:few,:manyand:other.
See also Cldr.Print.Backend.Number.Cardinal.Cardinal.plural_rule/3.
Examples
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 1, "en", %{one: "one"}
"one"
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 2, "en", %{one: "one"}
nil
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 2, "en", %{one: "one", two: "two", other: "other"}
"other"
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 22, "en", %{one: "one", two: "two", other: "other"}
"other"
iex> Cldr.Print.Backend.Number.Cardinal.pluralize Decimal.new(1), "en", %{one: "one"}
"one"
iex> Cldr.Print.Backend.Number.Cardinal.pluralize Decimal.new(2), "en", %{one: "one"}
nil
iex> Cldr.Print.Backend.Number.Cardinal.pluralize Decimal.new(2), "en", %{one: "one", two: "two"}
nil
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 1..10, "ar", %{one: "one", few: "few", other: "other"}
"few"
iex> Cldr.Print.Backend.Number.Cardinal.pluralize 1..10, "en", %{one: "one", few: "few", other: "other"}
"other"