smhg / gettext-parser

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

Handle obsolete messages in PO #64

Closed KapitanOczywisty closed 2 years ago

KapitanOczywisty commented 2 years ago

Obsolete translations are kept in optional obsolete property:

{
  //...
  obsolete: {
    '': {
      'Obsolete message': {
        msgid: 'Obsolete message',
        comments: { translator: 'Obsolete comment' },
        msgstr: [
          'Message obsolete.\nLines are properly handled, even for obsolete translations.'
        ]
      }
    }
  }
}

and properly compiled back into po file:

# Obsolete comment
#~ msgid "Obsolete message"
#~ msgstr ""
#~ "Message obsolete.\n"
#~ "Lines are properly handled, even for obsolete translations."

Closes #9

smhg commented 2 years ago

This is great! Thank you! One thing: can you add/update docblocks for the methods you've added/changed?

KapitanOczywisty commented 2 years ago

@smhg something like that?

KapitanOczywisty commented 2 years ago

I forgot about that, fixed.

rankida commented 2 years ago

Is it intended that now all new comments with a tilde ~ in it fail parsing? I expected only those lines starting with #~ would be considered as obsolete comments but it seems if the first comment line has a ~ anywhere in the comment it is picked up, and so expects a regular comment on the proceeding line.

For example the below PO file now returns the error message Error parsing PO data: Invalid key name "obsolete" at line 13. This can be caused by an unescaped quote character in a msgid or msgstr value.

msgid ""
msgstr ""
"Project-Id-Version: 10.0.0\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"
""

# Text: this is NOT ~ obsolete
msgid "test
msgstr "regular text"
smhg commented 2 years ago

Thank you for reporting and patching this. This fix is released in version 5.1.1. Please do me a favor and submit a separate issue and PR next time :)

rankida commented 2 years ago

Thanks so much 🙇

Sorry for not following the process. Really appreciate the response. Cheers!