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>

CommentFileSizeAuthor
#2 tr-modified-to-avoid-error.po393.01 KBerdemkose
#1 tr-original.po392.86 KBerdemkose
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

erdemkose’s picture

FileSize
392.86 KB

No 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.

erdemkose’s picture

FileSize
393.01 KB

This 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.

killes@www.drop.org’s picture

Can you try

Plural-Forms: nplurals=2; plural=n != 1;

?

This works for Hungarian and Korean which also only have on Plural form.

erdemkose’s picture

Of 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.

erdemkose’s picture

Version: 4.7.2 » x.y.z

I modified locale.inc to avoid the error and it works now.

My solution is to replace if ($plural) with if (FALSE !== $plural).

Gábor Hojtsy’s picture

Indeed, 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.

Dries’s picture

Status: Active » Fixed

I fixed this in both DRUPAL-4-7 and CVS HEAD. Give it a try. Thanks!

erdemkose’s picture

Status: Fixed » Closed (fixed)

I 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.