Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Reproduction:
- install a new Drupal site
- enable the locale module
- add a new language (e.g. Hungarian)
- export the translation of the potx module from the l.d.o., using the "Compact files optimized for size, not desktop editing" format
- import the translation
- the locale module imports 55 strings, and does not import the translation of the "one day/@count day" string.
There is not a message or a watchdog entry, the plural forms simply skipped, as well as any compact files, like the Drupal core translation for example.
Comment | File | Size | Author |
---|---|---|---|
#26 | locale-plural-fix-and-test.patch | 3.02 KB | Gábor Hojtsy |
#25 | 860154-plural-import-fix-d7.patch | 7.03 KB | andypost |
#22 | locale-plural-fix-and-test.patch | 3.02 KB | Gábor Hojtsy |
#19 | locale-plural-test.patch | 1.85 KB | Gábor Hojtsy |
#4 | 860154_locale_does_not_import_plural_forms_4.patch | 753 bytes | zserno |
Comments
Comment #1
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedI do not know, how can I create a patch for the core, but the solution is:
includes/locale.inc, line 1148
old: if ($context == "MSGSTR") { // End current entry, start a new one
new: if ($context == "MSGSTR" || ($context == "MSGSTR_ARR")) { // End current entry, start a new one
Comment #2
Damien Tournoud CreditAttribution: Damien Tournoud commentedIndeed. Affects D7 too, bumping there for correction.
Comment #3
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedIt is necessary to look my solution better for 6.x, because if the l10n_update module refreshes the translations, then the plural forms are left out from the database.The l10n_update duplicate the code from include/locale.inc
#860480: This module does not import the plural forms from the compact files
Comment #4
zserno CreditAttribution: zserno commentedAttached a proper patch for D7. I tested Zoltan's solution and it did work for me.
Comment #5
Zoltán Balogh CreditAttribution: Zoltán Balogh commentedDo not release D7 without this fix
Comment #6
aspilicious CreditAttribution: aspilicious commentedcould you place the comment above the code line?
Comment #7
zserno CreditAttribution: zserno commented@aspilicious Sure I could, but if you take a look at locale.inc, it has a number of lines with such documentation style.
So I'd rather clean up the whole file in a separate issue. What do you think?
Comment #8
aspilicious CreditAttribution: aspilicious commentedHmm well leave it this way, I'll fix those in D8 ;)
Comment #9
Damien Tournoud CreditAttribution: Damien Tournoud commentedNot critical, but major.
Comment #10
Damien Tournoud CreditAttribution: Damien Tournoud commented- There is other case (in msgctxt) where we switch to a new entry. We need the same fix there.
- We need to update the .po parsing tests that we have.
Comment #11
Gábor HojtsyWhy is that this issue comes up with the compact files only? Also, how does the patch solve Drupal not importing the plural formula (if that is also happening as far as I understood)?
Comment #12
Zoltán Balogh CreditAttribution: Zoltán Balogh commented6.x: In the verbose translation files, after the plural formula there is an empty and a comment line before the next "msgid". In this case, the locale.inc works fine, and the _locale_import_one_string at the line 1123 will import the last plural formula. In the compact files after the "msgstr[" the next line immediately starts with a new "msgid". In this case the value of the $context is MSGSTR_ARR yet (last line was a msgstr[1]), and this condition is missing from the line 1148. Therefore the locale.inc ignoring all plural formulas, except if the plural formula is the last in the compact translation file.
7.x: I do not know, and I think, it would be better if we separate the versions.
Comment #13
Gábor Hojtsy@Zoltán Balogh: ok, so its the plural variants for source strings, not "the plural formula" (which is in the header section of the file). The Drupal 7 import code is very similar and probably has the same issue (I did not reproduce).
Comment #14
andypostJust a remark, compact files could not used for JS strings. Because JS translation depends on filenames in .po file (
s.location LIKE '%.js%'
) in _locale_rebuild_js()EDIT: filed #864064: Compact files format could not used for JS strings
Comment #15
Gábor Hojtsy@andypost: indeed, that should actually be a bug report against l10n_server's compact file format. It should include the location info for JS files (at least ".js" as location, so it will work with the JS translation in D6/7). Can you submit a report for that in l10n_server?
Comment #16
Gábor HojtsyBug also applies to Drupal 5, reported at #843154: Plural forms not imported into Drupal 5.22 core (marked as duplicate).
Comment #17
andypostThere's issue to add test for plurals #848966: Improve locale tests
Comment #18
andypostMarked as duplicate #769698: Incorrect work _locale_import_read_po()
Comment #19
Gábor HojtsySo the bug in short is that the state machine is not implemented consistently. If a comment follows an msgstr or an msgstr[] then the previous string is saved in the DB. However, if an msgid or msgctxt is encountered, the previous string is only saved if it was an msgstr. So a plural string translation can only be followed by a comment or end of file to be saved. If it is followed by a new string (which starts with msgid or msgctxt in D7), then it will not be saved. Attached a test extension to check for this. The issue referenced by @andypost does not cover plural imports, so thats not relevant.
The attached patch should fail by definition. I'll attach the fix with the patch in another comment.
Comment #21
andypostGábor Hojtsy, issue I'm referencing is about export fix so I think it's just addition to import
Comment #22
Gábor HojtsyOk, we proved above the tests fail. Now this patch includes a fix with the very same tests as in #19. Should pass.
Comment #23
andypostGábor Hojtsy, any reason you are using
((==) || (==))
? Code is more readable without expensive () and == has priority on ||PS: http://www.php.net/manual/en/language.operators.precedence.php
Comment #24
Gábor HojtsyIt is already like that at other parts of the code. I'm trying to restrict myself to the bugfix not to introduce other differences or fix other parts of that code which are not broken. Feel free to submit cleanups once this is committed. There is plenty to clean up here :)
Comment #25
andypostThis is a only function in this file with broken code-style. It's easy to fix while you on it.
This is a re-roll
If you strong against this, please, post a follow-up
Comment #26
Gábor HojtsyLook, I'd like to see this committed to Drupal 6, so it gets into the (imminent) upcoming D6 release. If we continue arguing about code style for D7, that's not gonna happen, and we have a broken localization stack to present at Drupalcon Copenhagen. That I don't want. I'd rather postpone minuscule code style issues when we can fix the bug. Let's get the bugfix in and then you can do whatever you want. I'd for one argue that "// A comment." looks really that helpful. Let's get that damn bug fixed, ok?
Comment #27
andypostAgreed exactly! This patch hangs too long. Waiting a bot goes green
PS Filed follow-up #880278: Cleanup _locale_import_read_po()
I will re-roll patch after this issue would be commited
Comment #28
Gábor HojtsyGiven I believe this is important for the D6 release that is imminent and was tested earlier on D6, committed there: http://drupal.org/cvs?commit=405676. Above code+test passed for me on local machine, and seen manual tests, so I'm confident it works well. Still needs testbot feedback and commit for D7.
Comment #29
Sutharsan CreditAttribution: Sutharsan commentedDoes this patch still need a review? Reading Gábor's last comment this patch should be RTBC
Comment #30
Gábor HojtsyYes, the patch looks good, has extended test coverage and is already committed to Drupal 6.
Comment #31
andypost+1 to commit
Comment #32
tom_o_t CreditAttribution: tom_o_t commented#26: locale-plural-fix-and-test.patch queued for re-testing.
Comment #33
andypostSuppose now this critical too
Comment #34
webchickThanks. This was totally off my radar. And because it fixes a bug that's already fixed in D6, agree with critical status.
Committed to HEAD!