smhg / gettext-parser

Parse and compile gettext po and mo files, nothing more, nothing less
MIT License
160 stars 44 forks source link

Error in PO(T) compilation for plural strings #18

Closed maufl closed 8 years ago

maufl commented 8 years ago

react-gettext-parser uses this library to compile POT files from JSX and JS sources. However, if you have a function call to ngettext or other plural translations, it will result in only one empty string in the msgstr array of the translation. gettext-parser will rely on the number of msgstr elements to decide whether it should render msgstr or msgstr[0] instead of relying on the presence of a msgid_plural key. The relevant code is here: https://github.com/andris9/gettext-parser/blob/master/lib/pocompiler.js#L104

For me this results in having a POT file like this:

#: web/static/js/components/react_test.js:14
msgid "Buy envelope"
msgid_plural "Buy envelopes"
msgstr ""

instead of

#: web/static/js/components/react_test.js:14
msgid "Buy envelope"
msgid_plural "Buy envelopes"
msgstr[0] ""

which leads to my gettext tool throwing an error.

This could be fixed in react-gettext-parser but I think it might be more correct for gettext-parser to produce msgstr[0] if a msgid_plural is present and has content.

See also https://github.com/laget-se/react-gettext-parser/issues/6.