all Python 3gettextfunction
gettext.ngettext()
translation functions
Translates a phrase with a number, choosing the plural form by n, using the current global domain.
Syntax
text = gettext.ngettext(singular, plural, n, /)
A hand-made 'file' if n == 1 else 'files' cannot be translated into Russian, which has three forms (файл, файла, файлов) chosen by the last digits of n, so 21 takes the singular again. ngettext solves this with the catalog's rule. The number is not inserted for you — format a template with {n} separately. Without a catalog, 0 counts as plural.
Examples
import gettext
for n in (0, 1, 2):
print(gettext.ngettext('{n} file', '{n} files', n).format(n=n)) # → 0 files / 1 file / 2 files
See also
Open in the full glossarydocs.python.orgReport an inaccuracy