I am translating Drupal to Turkish with my friends. Today I tried our translation on a fresh installation and Drupal said that "cannot parse plural formula".
My initial plural formula is: Plural-Forms: nplural=1; plural=0;
This formula gives an error while importing and plural translations don't work. For example: 1 min => 1 dakika
but 8 min => 8 min
(this is wrong) instead of 8 dakika
(this is the right one).
I changed my plural formula to Plural-Forms: nplural=1; plural=(0);
but this also doesn't work.
I changed formula to Plural-Forms: nplural=1; plural=( n != n);
and now Drupal doesn't give error about plural formula and my plural translations work.
locale.inc:792
// Get PHP version of the plural formula
$plural = _locale_import_parse_arithmetic($plural);
if ($plural) {
return array($nplurals, $plural);
}
else {
drupal_set_message(t('The translation file %filename contains an error: the plural formula could not be parsed.', array('%filename' => theme('placeholder', $filename))), 'error');
return FALSE;
}
This may be the cause of the error. Drupal only checks if $plural is non-zero but I must set it to '0' which evaluates to FALSE for PHP. I think it can be solved by checking if (FALSE === $plural)
instead of if ($plural)
.
I don't have access to CVS now to make a patch.
Don't try to add Turkish language now because it contains some errors. Or replace <em>Plural-Forms: nplural=INTEGER; plural=EXPRESSION;</em> to <em>Plural-Forms: nplural=1; plural=0;</em>
Comment | File | Size | Author |
---|---|---|---|
#2 | tr-modified-to-avoid-error.po | 393.01 KB | erdemkose |
#1 | tr-original.po | 392.86 KB | erdemkose |
Comments
Comment #1
erdemkose CreditAttribution: erdemkose commentedNo other language has the same plural formula with Turkish. So this is still a bug but only affects Turkish :(
You may not reproduce the bug with current Turkish translation because it contains errors. So I will attach my test translation file for you to reproduce the bug.
This file is the original translation file with
Plural-Forms: nplural=1; plural=0;
.Error Message after importing:
The translation file contains an error: the plural formula could not be parsed.
And plurals are not translated.
Comment #2
erdemkose CreditAttribution: erdemkose commentedThis file is modified to avoid any error message and plural-translation-bug.
The only modification is
Plural-Forms: nplural=1; plural=(n != n);
. This works correct.Comment #3
killes@www.drop.org CreditAttribution: killes@www.drop.org commentedCan you try
Plural-Forms: nplurals=2; plural=n != 1;
?
This works for Hungarian and Korean which also only have on Plural form.
Comment #4
erdemkose CreditAttribution: erdemkose commentedOf course I can try and I already tried this kind of solutions but I created this issue to make my translation file work with the original plural formula.
This plural formula is also written in Drupal Handbook at Issues using PoEdit.
Comment #5
erdemkose CreditAttribution: erdemkose commentedI modified locale.inc to avoid the error and it works now.
My solution is to replace
if ($plural)
withif (FALSE !== $plural)
.Comment #6
Gábor HojtsyIndeed, the $plural return value could be FALSE on error and some other non-false value on success. These should be differentiated. The solution in #5 should work well.
Comment #7
Dries CreditAttribution: Dries commentedI fixed this in both DRUPAL-4-7 and CVS HEAD. Give it a try. Thanks!
Comment #8
erdemkose CreditAttribution: erdemkose commentedI changed the plural formula in .po files to (1 != 1) to avoid error. They will include this formula until 4.7.3 (or something else) is released.
Thanks.