wp-cli / i18n-command

Provides internationalization tools for WordPress projects.
MIT License
96 stars 52 forks source link

`update-po`: Preserve unused translations/comments? #334

Open strarsis opened 2 years ago

strarsis commented 2 years ago

Feature Request

Describe your use case and the problem you are facing update-po doesn't preserve unused translations/comments inside the PO files. As Gettext editors like POEdit use their own translation database and VCS are usually used, this isn't a big deal and may de-clutter the PO file. - But an option for keeping this extra stuff may still be helpful in some cases.

Describe the solution you'd like An option that lets update-po keep the unused translations/comments inside the PO files.

Example: Input PO:

# Copyright (C) 2022 ACME
# This file is distributed under the proprietary.
msgid ""
msgstr ""
"Project-Id-Version: Test Theme 1.0.0\n"
[...]

#: theme.json
msgctxt "Color name"
msgid "Yellow"
msgstr "Gelb"

#~ msgctxt "Font size name"
#~ msgid "Small"
#~ msgstr "Klein"

Output PO (as you can see the extra Copyright comment and the unused translation were both stripped):

msgid ""
msgstr ""
"Project-Id-Version: Test Theme 1.0.0\n"
[...]

#: theme.json
msgctxt "Color name"
msgid "Yellow"
msgstr "Gelb"
swissspidy commented 2 years ago

Thanks for sharing this suggestion 👍

I'm not sure if the gettext library we use supports that, but at first glance it looks like it at least does extract # and #~ comments:

https://github.com/php-gettext/Gettext/blob/3e7460f8d9c90174824e3f39240bd578bb3d376a/src/Extractors/Po.php#L47-L59

Then the question is whether these can be kept during the update/merge.