Having trouble understanding how to write Plural Form line in po files.

Where can I find an explanation of INTERGER and EXPRESSION - I don't understand the syntax of:
"Plural-Forms: nplurals=INTERGER; plural=EXPRESSION;"

Working on po file for Latvian. In other language po files I've seen:

"Plural-Forms: nplurals=2; plural=($n!=1);"

"Plural-Forms: nplurals=2; plural=(n > 1);"

for French
"Plural-Forms: nplurals=2; plural=(n != 1);"

Comments

killes@www.drop.org’s picture

The first thing is the number of plural forms. Many languages have only two (singular and plural), a few have only one (Japanese I think), and some have more than two (Polish and I think Latvian).

The second part is a formula that states for which numbers which plural form is to be used. plural=(n != 1) means that for every number which is not 1 the plural form is to be used.

A better explanation is here:
http://www.gnu.org/software/gettext/manual/html_node/gettext_150.html

It comes even with an example for Latvian.
--
Drupal services
My Drupal services

lisa’s picture

Thanks so much for your explanations and the link - both were very helpful. According to that link, Latvian has 3 forms including a special case for zero. The Plural-Form line for Latvian should look like this:

Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;

Breaking it down, I think this means:

n%10==1 && n%100!=11 ? 0
This relates to msgstr[0] and means the number equals 1 but not 11

n != 0 ? 1
This relates to msgstr[1] and means the number is NOT 0

2
This relates to msgstr[2] and means all other numbers (special case for 0)

1. Is that the correct meaning of the expression?

I think this means I need to add msgstr[2] in all necessary places in the po files. For example, common-inc.po has:

#: includes/common.inc:0
msgid "1 year"
msgid_plural "%count years"
msgstr[0] ""
msgstr[1] ""

I should modify it like this:

#: includes/common.inc:0
msgid "1 year"
msgid_plural "%count years"
msgstr[0] "1 gads"
msgstr[1] "%count gadi"
msgstr[2] "%count gadi"

2. Is this correct?

Thanks again for your help.

killes@www.drop.org’s picture

Yes, this appears to be correct.
--
Drupal services
My Drupal services

lisa’s picture

thanks - seems to work

dwaynebailey’s picture

This list of Gettext plural forms will help you find the correct settings for your language.