module documentation

Plural form definitions.

Unknown Field: copyright
  1. 2013-2021 by the Babel Team.
Unknown Field: license
BSD, see LICENSE for more details.
Constant DEFAULT​_PLURAL Undocumented
Constant LC​_CTYPE Undocumented
Constant PLURALS Undocumented
Class _​Plural​Tuple A tuple with plural information.
Function get​_plural A tuple with the information catalogs need to perform proper pluralization. The first item of the tuple is the number of plural forms, the second the plural expression.
DEFAULT_PLURAL: tuple =

Undocumented

Value
(2, '(n != 1)')
LC_CTYPE =

Undocumented

Value
default_locale('LC_CTYPE')
PLURALS: dict[str, tuple] =

Undocumented

Value
{'af': (2, '(n != 1)'),
 'ar': (6,
        '(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=0 
&& n%100<=2 ? 4 : 5)'),
 'be': (3,
        '(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=2
0) ? 1 : 2)'),
...
def get_plural(locale=LC_CTYPE):

A tuple with the information catalogs need to perform proper pluralization. The first item of the tuple is the number of plural forms, the second the plural expression.

>>> get_plural(locale='en')
(2, '(n != 1)')
>>> get_plural(locale='ga')
(5, '(n==1 ? 0 : n==2 ? 1 : n>=3 && n<=6 ? 2 : n>=7 && n<=10 ? 3 : 4)')

The object returned is a special tuple with additional members:

>>> tup = get_plural("ja")
>>> tup.num_plurals
1
>>> tup.plural_expr
'0'
>>> tup.plural_forms
'nplurals=1; plural=0;'

Converting the tuple into a string prints the plural forms for a gettext catalog:

>>> str(tup)
'nplurals=1; plural=0;'