View Source Bonfire.Common.Localise.Cldr.Number.Cardinal (Bonfire v0.9.10-classic-beta.169)

Implements cardinal plural rules for numbers.

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 substitution map.

Functions

Link to this function

available_locale_names()

View Source

The locale names for which plural rules are defined.

@spec known_locale_names() :: [Cldr.Locale.locale_name(), ...]

The configured locales for which plural rules are defined.

Returns the intersection of Bonfire.Common.Localise.Cldr.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.

Link to this function

plural_rule(number, locale, rounding \\ Math.default_rounding())

View Source

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

Examples

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.plural_rule 0, "fr"
:one

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.plural_rule 0, "en"
:other
@spec plural_rules() :: %{
  required(Cldr.Locale.locale_name()) => [
    {plural_type :: Cldr.Number.PluralRule.plural_type(),
     plural_rules :: [Cldr.Number.PluralRule.plural_rule(), ...]},
    ...
  ]
}

Returns all the plural rules defined in CLDR.

Link to this function

plural_rules_for(locale_name)

View Source
@spec plural_rules_for(Cldr.Locale.locale_name() | Cldr.LanguageTag.t()) :: [
  {atom(), list()},
  ...
]

Return the plural rules for a locale.

Arguments

The rules are returned in AST form after parsing.

Link to this function

pluralize(number, locale_name, substitutions)

View Source

Pluralize a number using cardinal plural rules and a substitution map.

Arguments

See also Bonfire.Common.Localise.Cldr.Number.Cardinal.Cardinal.plural_rule/3.

Examples

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 1, "en", %{one: "one"}
"one"

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 2, "en", %{one: "one"}
nil

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 2, "en", %{one: "one", two: "two", other: "other"}
"other"

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 22, "en", %{one: "one", two: "two", other: "other"}
"other"

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize Decimal.new(1), "en", %{one: "one"}
"one"

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

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize Decimal.new(2), "en", %{one: "one", two: "two"}
nil

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 1..10, "ar", %{one: "one", few: "few", other: "other"}
"few"

iex> Bonfire.Common.Localise.Cldr.Number.Cardinal.pluralize 1..10, "en", %{one: "one", few: "few", other: "other"}
"other"