Idiom.Plural (idiom v0.4.1)
Functionality for handling plurals and plural suffixes.
Idiom handles plurals by adding suffixes to keys. These suffixes are as defined by the Unicode CLDR plural rules:
zero
one
two
few
many
other
Used suffixes differ greatly by language. In order to support them all, and also make this module easier to keep up-to-date, the PluralPreprocess
module
parses them and generates ASTs for cond
expressions. This module reads the definition file at compile time, and generates helper functions for each
language.
Summary
Functions
Returns the appropriate plural suffix based on a given locale and count.
Types
count()
Functions
get_suffix(locale, count)
Returns the appropriate plural suffix based on a given locale and count.
The function will determine the correct plural form to use based on the count
parameter.
It supports different types of count values, including binary, float, integer and Decimal types.
When the count is nil
, the function will default to other
.
Examples
iex> Idiom.Plural.get_suffix("en", 1)
"one"
iex> Idiom.Plural.get_suffix("en", 2)
"other"
iex> Idiom.Plural.get_suffix("ar", 0)
"zero"
iex> Idiom.Plural.get_suffix("ar", "5")
"few"
iex> Idiom.Plural.get_suffix("ar", Decimal.new(5))
"few"