The current version of localization server for Drupal 6 (running on localize.drupal.org) needs to go to great length to try and protect itself from broken .po files imported via deployed modules (modules actually running under the site). Drupal so nicely imports all translation files when enabling modules, but if any of those have a broken plural formula, it breaks plurals after the import. So I think we should try protecting the plural forms just like the existing strings when the KEEP option is used.

Since the automated import uses the KEEP mode when importing, this should protect a properly set up plural form.

The only issue here is that since most people would experience their first .po import via an automated import, they would not get any plural form set up. So I've added a clause to override the KEEP option for the plural formula if there was no plural formula set up earlier. Actually it only checks one of the fields use to store the plural setup, but that should be fine IMHO.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Gábor Hojtsy’s picture

To test:

- import a .po file
- check that the plural formula from the .po file was saved in the DB (languages table)

- mess with the plural formula in the info file (change numbers, equations, do not break the syntax, because it not going to import)
- import it again
- verify that your plural formula became broken

- apply the patch

- mess with your plural formula in a different way (but still do not mess with the syntax, so it gets parsed properly)
- check your protection checkbox while importing
- verify that it did not indeed mess up your existing plural form

- profit :)

seutje’s picture

Tested:

Existing behavior:

  • imported a po file with plural form (n!=1)
  • checked the DB to see the (n!=1) plural form
  • changed it to (n!=0) in the po file
  • reimported it with the KEEP option
  • checked DB to see the (n!=0)

After applying patch:

  • imported a po file with plural form (n!=1)
  • checked the DB to see the (n!=1) plural form
  • changed it to (n!=0) in the po file
  • reimported with the KEEP option
  • checked DB to see the (n!=1) plural form is still intact and wasn't changed

from what I understand that's how it should be so the patch works fine and profit was achieved :)

Gábor Hojtsy’s picture

Do you feel it is good to go then?

seutje’s picture

I do, but shouldn't some1 else review it as well?

Gábor Hojtsy’s picture

Category: task » bug

As explained in #654864: Plural-Forms generated in bad way => unable to properly edit .po files this should be considered a bug. I'd love if someone could be confident it is RTBC (I am :), and mark it as such. Thank you!

Jose Reyero’s picture

FileSize
3.34 KB

The patch doesn't apply anymore (functions moved around) but when fixed that it works as promised.

(Haven't been able to test the module install though, something seems broken with the new admin UI)

Updated patch.

plach’s picture

Component: language system » locale.module

Cleaning-up the "language system" issue queue as per http://cyrve.com/criticals.

Gábor Hojtsy’s picture

FileSize
5.9 KB

Added test coverage to ensure it works as expected and not rely on manual testers :)

- tests now check at first whether number of plurals was saved
- overwrite tester .po getter modified to use plural formula with 3 plurals
- tests added to check that if we asked to not overwrite, plurals are not overwritten either
- tests added to check that if we asked to overwrite, plurals are then overwritten

Locale import tests pass for me with these changes, and they cover the functionality of the patch, so if if all passes, I'm hopeful this is RTBC.

This is really a very small patch and almost all of the non-test changes are indentation differences.

seutje’s picture

Status: Needs review » Reviewed & tested by the community

awesomeness, works exactly as expected.

good to go?

Gábor Hojtsy’s picture

Yay! :)

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Gábor Hojtsy’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

Let's backport to Drupal 6 too. This is a plague many people caught.

Gábor Hojtsy’s picture

Status: Patch (to be ported) » Needs review
FileSize
2 KB

Backport to D6. Testing welcome. Note that we do not change the labels on forms due to this not being a change to justify string breaks.

seutje’s picture

Status: Needs review » Reviewed & tested by the community

Works exactly as expected, a bit unfortunate that we can't change the strings at this point, which leads to the fact that there is no mention anywhere of when plural forms are updated and when they aren't... perhaps we need to add a line to http://drupal.org/node/21145 or something

but this is by no means a stopper for this fix (imo)

Gábor Hojtsy’s picture

@seutje: well, this was a bug at the start because people expected that plural updates will work the same as string updates, so I think while it might not be as clear, it should be understandable from the import modes.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Great, committed then.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ajayg’s picture

Not sure if this bug still exists or this is a sideffect.

1-Download and clean install drupal 6.17 module.
2. Enable locale module
3. Add a language (any language)
4. Export template to create ".pot" file.
5. Try to import the template in the new language

You get an error
"The translation file drupal.pot contains an error: the plural formula could not be parsed"

Why I need to do this? Was trying to add a translation for a new language and wanted to start from scratch with existing language (english) and gradually translate the string as I can.

ajayg’s picture

Status: Closed (fixed) » Active
Gábor Hojtsy’s picture

Status: Active » Closed (fixed)

When you start from scratch, you need to specify the plural formula in your .po file or Drupal will not know what formula to use and will not import your file. Once the plural formula is set, the above fix was about trying to protect it from people importing files like you did which previously killed off a properly set formula. You need to at least import a proper formula once with a .po file. This has nothing to do with the above issue. Look for this error message on drupal.org and you'll find answers.