Last updated July 25, 2010.
The translation tool poEdit for Windows seems to require some additional steps to recognize plural forms: if you try to edit a term which has plurals, even if you translate it, it doesn't appear in poedit when you move to another term, as usual, and even if you save, it doesn't.
Plurals Solution #1
If you find a plural term, close poedit, open the file you were translating with a normal text editor (not MS Word) and search for "plural" in it, you find something similar to this:
#: modules/comment.module:187 modules/node.module:89
msgid "1 comment"
msgid_plural "%count comments"
msgstr[0] "1 commento"
msgstr[1] "%count commenti"simply translate the text in msgid (singular form) into msgstr[0], and the text in msgid_plural (plural form) into msgstr[1], save the file, close the editor and return to poedit. Even better, you can do this BEFORE starting to translate the rest of the file with poedit, translating every occurrence of plural in the same way, in every file, and THEN start using poedit. This way, you will find those strings already translated in poedit.
Plurals Solution #2
To use plurals in PO edit you can start with the catalog setting for English and then modify to suit. The syntax is:
nplurals=2; plural=(n != 1);
which gave me what I needed in Swedish translation of:
#: modules/aggregator.module:100;711;722
msgid "1 item"
msgid_plural "items"
msgstr[0] "1 inlägg"
msgstr[1] "%count inlägg"
I tested this in PO Edit 1.3.1 and got the proper GUI response and saved without error.
Plurals Solution #3
The plural forms to use in PO edit under catalog-settings where you see
nplural=INTEGER; plural=EXPRESSION
Only one form: Some languages only require one single form. There is no distinction between the singular and plural form. An appropriate header entry would look like this:
Plural-Forms: nplurals=1; plural=0;
Languages with this property include:
Finno-Ugric family
Hungarian
Asian family
Japanese, Korean
Turkic/Altaic family
Turkish
Two forms, singular used for one only: This is the form used in most existing programs since it is what English is using. A header entry would look like this:
Plural-Forms: nplurals=2; plural=n != 1;
Note: this uses the feature of C expressions that Boolean expressions have to value zero or one.
Languages with this property include:
Germanic family
Danish, Dutch, English, German, Norwegian, Swedish
Finno-Ugric family
Estonian, Finnish
Latin/Greek family
Greek
Semitic family
Hebrew
Romanic family
Italian, Portuguese, Spanish
Artificial
Esperanto
Two forms, singular used for zero and one: Exceptional case in the language family. The header entry would be:
Plural-Forms: nplurals=2; plural=n>1;
Languages with this property include:
Romanic family
French, Brazilian Portuguese
Three forms, special case for zero: The header entry would be:
Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;
Languages with this property include:
Baltic family
Latvian
Three forms, special cases for one and two: The header entry would be:
Plural-Forms: nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2;
Languages with this property include:
Celtic
Gaeilge (Irish)
Three forms, special case for numbers ending in 1[2-9]: The header entry would look like this:
Plural-Forms: nplurals=3; \
plural=n%10==1 && n%100!=11 ? 0 : \
n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2;Languages with this property include:
Baltic family
Lithuanian
Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]: The header entry would look like this:
Plural-Forms: nplurals=3; \
plural=n%10==1 && n%100!=11 ? 0 : \
n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;Languages with this property include:
Slavic family
Croatian, Czech, Russian, Slovak, Ukrainian
Three forms, special case for one and some numbers ending in 2, 3, or 4: The header entry would look like this:
Plural-Forms: nplurals=3; \
plural=n==1 ? 0 : \
n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;Languages with this property include:
Slavic family
Polish
Four forms, special case for one and all numbers ending in 02, 03, or 04: The header entry would look like this:
Plural-Forms: nplurals=4; \plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;
Languages with this property include:
Slavic family
Slovenian
Long plural formulae: Those should not be broken into several lines in the header of the .po file. Drupal expects the formula to be on one line. One could consider this a bug.
I don't think that you can use line breaks in Poedit either. The text is fixed to keep from breaking the site layout. But this:
nplurals=1; plural=ar;
produces an error. The plural form "ar" is not recognized.
Comments
Don't use Notepad
I first tried Solution #1 using my favorite Windows Editor (Notepad), but thereafter Drupal refused to recognise the language file.
So I tried using Solution #2 with poedit - and that worked!
poEdit recognizes plurals
poEdit supports plural forms (>1.3.0). You must have correct syntax in Catalog/Settings/Plural forms field. Or correct syntax in a source code (po file). Without line breaks. Than you can edit plurals in poEdit (a tab for each plural).
For example correct form for slavic languages is
nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
not
nplurals=3; \
plural=n%10==1 && n%100!=11 ? 0 : \
n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
Don't use line breaks.
Polish/Polski
Correct form for Polish is a little more complex:
nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);Drupal-centric webdesign · Drupal Polska -- Polish support
Plural Solution for Chinese
Here is the plural solution for Chinese which is not listed above:
"Plural-Forms: nplurals=2; plural=1;\n"So if you open the po file using text editor (I think Emeditor is better for the job), you get :
#: modules/archive.module:136msgid "1 post"
msgid_plural "%count posts"
msgstr[0] "1篇文章"
msgstr[1] "%count 文章"
--------------------------
http://www.kzeng.info
--------------------------
http://www.kzeng.info
Ukrainian plural form incorrect!
Just try to "eval" formula. You'll never get form 0 ;).
So 21, 31 and so on will be translated incorrectly.
Correct formula for ukrainian, russian, etc is:
($n%10==1 && $n%100!=11) ? 0 : (($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20)) ? 1 : 2)Take a look at braces
http://tusovka.in.ua
List of plural forms
We maintain a list of Gettext plural forms for all languages that we have seen translated on Pootle and other systems online translation systems. Please add your language if it is missing.
Remark to Solution 3
Hi,
it seems as there must chosen in po-edit the option "nplurals=2; plural=(n !=1);\n;"
Don't ask me why — it works... :-)
Best regards, Ralf
comm-press Web-Services
Ralf Hendel
comm-press Drupal Solutions Hamburg
Russian plural formula
(actual for poedit 1.4.2 / SuSE Linux and Drupal 6.10)
The multiline-slashed plural formula for Russian from this article (actually, it is from GNU gettext manual), did not work for me, giving errors on file saving.
I used one from KBabel.
In poedit, go to Catalog->Settings
Set both charsets to utf-8
Set plural forms to:
nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);
Set country to RUSSIAN FEDERATION
and the language to Russian.
It worked fine, no errors on file saving and re-opening. Drupal seems to drop header information on language .po file export (is it bug or feature?), so one have to repeat header re-setting every time s/he exports .po from Drupal installation.