This is only a read-only copy of the old bug tracker. See the support page.

Doc/PluralForms

Plural Forms

The Plural Forms field of PO files header describes how to translate English singular and plural forms into the language of the catalog file. The number of plural forms (even the very existence of it) differ among languages and translating them is not straightforward. GNU gettext solves this by adding a plural form expression to the catalog that describes properties of the translation language. This is what  the gettext manual says on the topic:

Without the input of linguists (which was not available) it was not possible to determine whether there are only a few different forms in which plural forms are formed or whether the number can increase with every new supported language.

Therefore the solution implemented is to allow the translator to specify the rules of how to select the plural form. Since the formula varies with every language this is the only viable solution except for hardcoding the information in the code (which still would require the possibility of extensions to not prevent the use of new languages).

The information about the plural form selection has to be stored in the header entry of the PO file (the one with the empty msgid string). The plural form information looks like this:

Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;

The nplurals value must be a decimal number which specifies how many different plural forms exist for this language. The string following plural is an expression which is using the C language syntax. Exceptions are that no negative numbers are allowed, numbers must be decimal, and the only variable allowed is n. Spaces are allowed in the expression, but backslash-newlines are not; in the examples below the backslash-newlines are present for formatting purposes only. This expression will be evaluated whenever one of the functions ngettext, dngettext, or dcngettext is called. The numeric value passed to these functions is then substituted for all uses of the variable n in the expression. The resulting value then must be greater or equal to zero and smaller than the value given as the value of nplurals.

The manual also lists some commonly used expressions.

How to set the Plural Forms field

Translate Toolkit has a  list of plural forms expressions for many languages.