tolgee-platform icon indicating copy to clipboard operation
tolgee-platform copied to clipboard

Export to PO with plural

Open Erwane opened this issue 9 months ago • 4 comments

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

Erwane avatar Mar 25 '25 23:03 Erwane

Hello! Thanks for reaching out!

Can you please specify the exact steps to reproduce?

JanCizmar avatar Mar 26 '25 09:03 JanCizmar

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

Erwane avatar Mar 26 '25 12:03 Erwane

Thanks a lot! You're right it's a bug.

JanCizmar avatar Apr 01 '25 09:04 JanCizmar

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.

kipe avatar Apr 25 '25 14:04 kipe

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.

Currently facing the same issue

jkaeske avatar Aug 19 '25 12:08 jkaeske

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! ^^

Anty0 avatar Aug 28 '25 14:08 Anty0