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

@type count() :: binary() | float() | integer() | Decimal.t()

Functions

Link to this function

get_suffix(locale, count)

@spec get_suffix(String.t(), count()) :: String.t()

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"