Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Problem/Motivation
When extracting translations with the option "Include translations" checked, the translations for plural strings are not filled in the export.
Expected result:
#: templates/test.html.twig
msgid "This is a plural test string with a single result."
msgid_plural "This is a plural test string with @num results."
msgstr[0] "Dit is een test string met een enkel resultaat."
msgstr[1] "Dit is een test string met @num resultaten"
Actual result:
#: templates/test.html.twig
msgid "This is a plural test string with a single result."
msgid_plural "This is a plural test string with @num results."
msgstr[0] ""
msgstr[1] ""
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 3013103-22.patch | 2.36 KB | idebr |
| #22 | interdiff-18-22.txt | 681 bytes | idebr |
Comments
Comment #2
bryandenijsI did some debugging and noticed that the single version and the plural version of the string are stored in the database in a single row, delimited with a "\03" character. By extracting the translation string, the module only search for the single or plural version of the string (not glued together).
Maybe not the most clean way to fix it, but this patch works for me.
Comment #3
bryandenijsComment #4
bryandenijsComment #5
idebr commentedPatch works as expected, thanks!
Comment #6
hctomPatch applies cleanly against latest 8.x-1.x-dev and works as expected. But I guess this still needs some tests, doesn't it?
In addition to that, this patch collides with the automated Drupal 9 compatibility patch from #3148463: Automated Drupal 9 compatibility fixes. Perhaps there should be made some progress first, before getting this done here.
Comment #7
penyaskitoRelated: #2918489: Plurals are not exported correctly when exporting source translations
What about when there are more plurals?
Can we use the constant PoItem::DELIMITER here instead of hardcoding "\03"?
That won't work for sites in a version older than 8.7 (https://www.drupal.org/node/3014611), but I think that's something we can assume?
Comment #8
gábor hojtsy@penyaskito: re
Here we are looking at source strings and not translations, and the source would always only ever have a singular and singular and one plural, right?
Comment #9
penyaskitoSure, all sources should be English per Drupal standards, missed that :-)
Comment #10
gábor hojtsySo I committed #3148463: Automated Drupal 9 compatibility fixes already which means this needs work because db_query() is not in Drupal 9 anymore and otherwise the code supports Drupal 9 and declares that it supports Drupal 9.
Comment #11
bryandenijsI will try to write a new patch after the weekend!
Comment #12
bryandenijsSorry it took some time, but here is a new patch based on the latest 8.x-1.x-dev branch.
Comment #13
gábor hojtsyLooks good to me but another pair of eyes would be useful before commit :)
Comment #14
bryandenijsWhoops, someone notified me there was a problem in the query condition.
Here is a new fix.
Comment #15
idebr commentedThe feedback in #7 and #10 have been adressed. Patch still works as expected, so setting to RTBC. Thanks Bryan :)
Comment #16
gngn commented#14 worked for me. Thanks.
Comment #17
hoanns commentedThanks #14 is good and should be merged
Comment #18
hoanns commentedWhoops no there was still a bug, it didnt correctly add msgstr[0] "" msgstr[1] "" if there was no translation found. This created a broken po file.
Here is the patch
Comment #19
bryandenijs@hoanns: Yes, you are right. Thanks for the fix!
Comment #20
bryandenijsComment #21
idebr commentedPatch #18 still applies to the latest dev after 1.0.0 was tagged
Comment #22
idebr commentedThe source string for languages with more than 2 plural forms is incorrect in #18. It is always the English singular and plural string.
Attached patch fixed the source string for languages with more than 2 plural forms.