smhg / gettext-parser

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

Support unescaped double quotes in message strings & IDs #37

Closed TimKam closed 5 years ago

TimKam commented 6 years ago

The gettext standard isn't clear on whether double quotes (") should be escaped or not (see: https://stackoverflow.com/questions/10218631/printing-with-gettext). However, not all translation management systems escape double quotes, so it would be good if gettext-parser could support unescaped "s. I'll add a PR with a failing test asap and a complete fix eventually.

smhg commented 6 years ago

At the moment, I don't think your proposal is a good idea. For 2 reasons:

I'll close the issue for now (to keep things clean), but please feel free to discuss and reopen if I'm wrong.

TimKam commented 6 years ago

@smhg I don't have the permission to re-open the issue I think. Anyway, with Zanata we currently have the problem that quotes are not automatically escaped. If a translator forgets this, it messes up the JSON object gettext-parser generates. gettext-parser doesn't throw an error message and it is not unlikely that such issues make it into production. We considered writing our own tests that check the structure of the .po file, but suggested it make more sense to address this problem "upstream" to help other users. I should have explained the problem like this in the first place: the standard is ambiguous and tools seem to handle it differently, so I'd say it's ok to be on the safe side and support it. Even if you disagree, gettext-parser should at least throw an error message if the structure is not supported :-)

smhg commented 6 years ago

Your last sentence is spot on I think. Just like msgfmt, gettext-parser should throw too. While I don't know Zanata, it sounds like this is an oversight in their system. PO's only support double quotes when escaped as far as I can tell.

Would you want to submit a new PR that takes care of the error?

probertson commented 5 years ago

@smhg I ran into this recently also and I've started working on it. Feel free to assign it to me.

smhg commented 5 years ago

Thank you @probertson! I can't select you as the assignee, but please go ahead.