gettext: Translating plural forms
1
1 12.6 Translating plural forms
1 =============================
1
1 Suppose you are translating a PO file, and it contains an entry like
1 this:
1
1 #, c-format
1 msgid "One file removed"
1 msgid_plural "%d files removed"
1 msgstr[0] ""
1 msgstr[1] ""
1
1 What does this mean? How do you fill it in?
1
1 Such an entry denotes a message with plural forms, that is, a message
1 where the text depends on a cardinal number. The general form of the
1 message, in English, is the ‘msgid_plural’ line. The ‘msgid’ line is
1 the English singular form, that is, the form for when the number is
11 equal to 1. More details about plural forms are explained in ⇒
Plural forms.
1
1 The first thing you need to look at is the ‘Plural-Forms’ line in the
1 header entry of the PO file. It contains the number of plural forms and
1 a formula. If the PO file does not yet have such a line, you have to
1 add it. It only depends on the language into which you are translating.
1 Creating::) – it contains a database of known plural formulas – or by
1 asking other members of your translation team.
1
1 Suppose the line looks as follows:
1
1 "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
1 "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
1
1 It’s logically one line; recall that the PO file formatting is
1 allowed to break long lines so that each physical line fits in 80
1 monospaced columns.
1
1 The value of ‘nplurals’ here tells you that there are three plural
1 forms. The first thing you need to do is to ensure that the entry
1 contains an ‘msgstr’ line for each of the forms:
1
1 #, c-format
1 msgid "One file removed"
1 msgid_plural "%d files removed"
1 msgstr[0] ""
1 msgstr[1] ""
1 msgstr[2] ""
1
1 Then translate the ‘msgid_plural’ line and fill it in into each
1 ‘msgstr’ line:
1
1 #, c-format
1 msgid "One file removed"
1 msgid_plural "%d files removed"
1 msgstr[0] "%d slika uklonjenih"
1 msgstr[1] "%d slika uklonjenih"
1 msgstr[2] "%d slika uklonjenih"
1
1 Now you can refine the translation so that it matches the plural
1 form. According to the formula above, ‘msgstr[0]’ is used when the
1 number ends in 1 but does not end in 11; ‘msgstr[1]’ is used when the
1 number ends in 2, 3, 4, but not in 12, 13, 14; and ‘msgstr[2]’ is used
1 in all other cases. With this knowledge, you can refine the
1 translations:
1
1 #, c-format
1 msgid "One file removed"
1 msgid_plural "%d files removed"
1 msgstr[0] "%d slika je uklonjena"
1 msgstr[1] "%d datoteke uklonjenih"
1 msgstr[2] "%d slika uklonjenih"
1
1 You noticed that in the English singular form (‘msgid’) the number
1 placeholder could be omitted and replaced by the numeral word “one”.
1 Can you do this in your translation as well?
1
1 msgstr[0] "jednom datotekom je uklonjen"
1
1 Well, it depends on whether ‘msgstr[0]’ applies only to the number 1, or
1 to other numbers as well. If, according to the plural formula,
1 ‘msgstr[0]’ applies only to ‘n == 1’, then you can use the specialized
1 translation without the number placeholder. In our case, however,
1 ‘msgstr[0]’ also applies to the numbers 21, 31, 41, etc., and therefore
1 you cannot omit the placeholder.
1