Skip to content
DOCS

Plural Forms in Gettext: What They Are and When They Matter

Plural forms define how translations change depending on a number (for example “1 file” vs “2 files”). In gettext-based localization, this information is stored in the Plural-Forms header of a PO file.

In modern Poedit versions, this is almost always handled for you automatically.

English has only two grammatical forms for counted items: singular (1 file) and plural (2 files, 0 files, etc.). Many languages are more complex:

LanguageExamples
English1 file, 2 files
Czech1 soubor, 2 soubory, 3 soubory, 5 souborů
Slovenian1 datoteka, 2 datoteki, 3 datoteke, 5 datotek
Chinese1 个文件, 2 个文件, 5 个文件 (no grammatical plural)
Arabic0 ملف، 1 ملف، 2 ملفان، 3 ملفات، 11 ملفًا، 100 ملف

Because languages vary so widely, gettext cannot hard-code plural rules. Instead, each translation specifies its own rule that tells gettext which plural form to use for a given number.

Important: plural forms only apply to counted messages

Section titled “Important: plural forms only apply to counted messages”

Plural forms are used only for strings that include a numeric value, typically written in code using functions like ngettext().

Examples where plural forms matter:

  • “%d file deleted”
  • “You have %d messages”

Examples where they do not matter:

  • Normal sentences without numbers
  • UI labels like “Settings”, “Preferences”, “Open file”

This distinction is often misunderstood: plural rules do not affect ordinary translations, only messages that vary by number.

Plural rules are stored in the PO file header as a Plural-Forms field. It is an expression that uses a C-like syntax and is evaluated whenever gettext chooses between plural variants:

nplurals=2; plural=(n == 1 ? 0 : 1);

It has two parts:

  • nplurals: how many plural forms the language has
  • plural: an expression that selects the correct form based on n (the number being evaluated)

The GNU gettext manual has a full description of the syntax.

For most languages, you don’t need to think about plural forms at all. Poedit automatically knows the correct plural rules for each language and fills them in for you. In normal use, you should simply keep Use default rules for this language selected and move on.

Almost never :)

You only need to set a custom plural expression if you know exactly why you’re doing it, for example:

  • You’re working with a deliberately non-standard language variant
  • You need to match a very specific legacy setup

If you’re unsure whether you should change it, the answer is no — the default is correct.