Export to PO with plural
Describe the bug When exporting to .PO with plural keys, the po file is invalid.
To Reproduce Flat JSon
{
"user.notification.count": "{value, plural, one {Notification} other {Notifications}}"
}
Exported PO
msgid ""
msgstr ""
"Language: fr-FR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals = 2; plural = (n > 1)\n"
"X-Generator: Tolgee\n"
msgid "user.notification.count"
msgstr[0] "Notification"
msgstr[1] "Notifications"
PoEdit complain about invalid file with message: Broken PO file: plural form msgstr used without msgid_plural
Expected behavior
msgid "user.notification.count"
msgstr "{value, plural, one {Notification} other {Notifications}}"
Versions and environment
- Tolgee Platform version: tolgee/tolgee:v3.113.0
- Environment: Docker
Hello! Thanks for reaching out!
Can you please specify the exact steps to reproduce?
- Create a fresh project. Default language "english (en)"
- Add key "account.notification" with plural and english translations : One: Notification Other: Notifications
- validate the translation
- Export lang en, format: Gettext .po, ICU
- Open the .po file with poedit 3.5.2
Exporting PO with "php sprintf" instead of ICU create an error too. The error is not in Tolgee but in PoEdit complaining about an invalid .po file.
Thanks a lot! You're right it's a bug.
I'm not sure if this is related directly to this, but the "Plural-Forms: nplurals = 2; plural = (n > 1)\n" generated by Tolgee also seems to cause issues with Python.
From all the examples I've seen, there should be no spaces around the equal signs, so "Plural-Forms: nplurals = 2; plural = (n > 1)\n" would become "Plural-Forms: nplurals=2; plural=(n > 1)\n".
This causes an IndexError exception in Pythons gettext implementation, as the header is parsed by splitting with plural=: https://github.com/python/cpython/blob/main/Lib/gettext.py#L413
I can create another issue if needed.
I'm not sure if this is related directly to this, but the
"Plural-Forms: nplurals = 2; plural = (n > 1)\n"generated by Tolgee also seems to cause issues with Python.From all the examples I've seen, there should be no spaces around the equal signs, so
"Plural-Forms: nplurals = 2; plural = (n > 1)\n"would become"Plural-Forms: nplurals=2; plural=(n > 1)\n".This causes an IndexError exception in Pythons gettext implementation, as the header is parsed by splitting with
plural=: https://github.com/python/cpython/blob/main/Lib/gettext.py#L413I can create another issue if needed.
Currently facing the same issue
Hi everyone! I've fixed all the issues mentioned. The only missing part is the ability to export plurals using ICU instead of handling them with the PO format. The proposal to let users do this is now in issue #3227.
I'll close this issue for now. Let me know what you think about the proposed solution or if I've overlooked anything! ^^