MyApp.Gettext.Plural (Cldr v2.29.0) View Source

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

Specs

Returns the number of plural forms for a given locale.

  • locale is either a locale name in the list {:__aliases__, [counter: {MyApp.Gettext.Plural, 1}, line: 4], [:MyApp, :Cldr]}.known_locale_names/0 or a %LanguageTag{} as returned by Cldr.Locale.new/2

Examples

iex> MyApp.Gettext.Plural.nplurals("pl")
4

iex> MyApp.Gettext.Plural.nplurals("en")
2

Specs

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: {MyApp.Gettext.Plural, 1}, line: 4], [:MyApp, :Cldr]}.known_locale_names/0 or a %LanguageTag{} as returned by Cldr.Locale.new/2

Examples

iex> MyApp.Gettext.Plural.plural("pl", 1)
0

iex> MyApp.Gettext.Plural.plural("pl", 2)
1

iex> MyApp.Gettext.Plural.plural("pl", 5)
2

iex> MyApp.Gettext.Plural.plural("pl", 112)
2

iex> MyApp.Gettext.Plural.plural("en", 1)
0

iex> MyApp.Gettext.Plural.plural("en", 2)
1

iex> MyApp.Gettext.Plural.plural("en", 112)
1