VerifiedTranslations.Plural (verified_translations v0.1.1)

Copy Markdown View Source

CLDR plural rules, compiled from the bundled priv/cldr/plurals.json (cardinal: 1 file, 2 files) and priv/cldr/ordinals.json (ordinal: 1st, 2nd), CLDR 49, Unicode License v3.

iex> VerifiedTranslations.Plural.category("fi", 1)
"one"
iex> VerifiedTranslations.Plural.category("ru", 22)
"few"
iex> VerifiedTranslations.Plural.category("en", 22, :ordinal)
"two"
iex> VerifiedTranslations.Plural.categories("ar")
["zero", "one", "two", "few", "many", "other"]

Counts may be integers, floats, Decimals or numeric strings ("1.50" keeps its two visible fraction digits, which matters in some languages).

Summary

Functions

CLDR plural categories of a CLDR language, in canonical order. type is :cardinal (1 file, 2 files) or :ordinal (1st, 2nd).

Plural category of count for a CLDR language (see language/1).

The CLDR language whose rules apply to locale ("pt_PT" -> "pt-PT", "fi_FI" -> "fi"), or nil when CLDR has no rules for it.

Functions

categories(lang, type \\ :cardinal)

@spec categories(String.t(), :cardinal | :ordinal) :: [String.t()]

CLDR plural categories of a CLDR language, in canonical order. type is :cardinal (1 file, 2 files) or :ordinal (1st, 2nd).

category(lang, count, type \\ :cardinal)

@spec category(String.t(), number() | String.t() | struct(), :cardinal | :ordinal) ::
  String.t()

Plural category of count for a CLDR language (see language/1).

language(locale)

@spec language(String.t()) :: String.t() | nil

The CLDR language whose rules apply to locale ("pt_PT" -> "pt-PT", "fi_FI" -> "fi"), or nil when CLDR has no rules for it.