View Source Bonfire.Common.Localise.Gettext.Plural (bonfire v0.3.5-classic-beta.6)

Defines a plural forms module for Gettext that uses CLDR plural rules https://cldr.unicode.org/index/cldr-spec/plural-rules

Link to this section Summary

Functions

Returns the number of plural forms for a given locale.

Returns the plural form of a number for a given locale.

Link to this section 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], [:Bonfire, :Common, :Localise, :Cldr]}.known_locale_names/0 or a %LanguageTag{} as returned by Cldr.Locale.new/2

examples

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], [:Bonfire, :Common, :Localise, :Cldr]}.known_locale_names/0 or a %LanguageTag{} as returned by Cldr.Locale.new/2

examples

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