View Source Bonfire.Common.Localise.Gettext.Plural (Bonfire v0.9.10-classic-beta.169)
Defines a plural forms module for Gettext that uses CLDR plural rules https://cldr.unicode.org/index/cldr-spec/plural-rules
Summary
Functions
Returns the number of plural forms for a given locale.
Returns the plural form of a number for a given locale.
Functions
@spec nplurals(Cldr.Locale.locale_name() | String.t()) :: pos_integer() | no_return()
Returns the number of plural forms for a given locale.
locale
is either a locale name in the list{:__aliases__, [counter: {Bonfire.Common.Localise.Gettext.Plural, 2}, line: 6, column: 42], [:Bonfire, :Common, :Localise, :Cldr]}.known_locale_names/0
or a%LanguageTag{}
as returned byCldr.Locale.new/2
Examples
iex> Bonfire.Common.Localise.Gettext.Plural.nplurals("pl")
4
iex> Bonfire.Common.Localise.Gettext.Plural.nplurals("en")
2
@spec plural(String.t() | Cldr.LanguageTag.t(), number()) :: 0 | pos_integer() | no_return()
Returns the plural form of a number for a given locale.
locale
is either a locale name in the list{:__aliases__, [counter: {Bonfire.Common.Localise.Gettext.Plural, 2}, line: 6, column: 42], [:Bonfire, :Common, :Localise, :Cldr]}.known_locale_names/0
or a%LanguageTag{}
as returned byCldr.Locale.new/2
Examples
iex> Bonfire.Common.Localise.Gettext.Plural.plural("pl", 1)
0
iex> Bonfire.Common.Localise.Gettext.Plural.plural("pl", 2)
1
iex> Bonfire.Common.Localise.Gettext.Plural.plural("pl", 5)
2
iex> Bonfire.Common.Localise.Gettext.Plural.plural("pl", 112)
2
iex> Bonfire.Common.Localise.Gettext.Plural.plural("en", 1)
0
iex> Bonfire.Common.Localise.Gettext.Plural.plural("en", 2)
1
iex> Bonfire.Common.Localise.Gettext.Plural.plural("en", 112)
1
iex> Bonfire.Common.Localise.Gettext.Plural.plural("en_GB", 112)
1