i18n-command icon indicating copy to clipboard operation
i18n-command copied to clipboard

Preserve POT file order when updating PO files

Open Copilot opened this issue 4 months ago • 1 comments

  • [x] Explore repository structure and understand the issue
  • [x] Understand gettext library and how mergeWith works
  • [x] Create test scenario to reproduce the issue
  • [x] Implement solution to preserve POT file order in update-po command
  • [x] Add tests for the new functionality
  • [x] Address code review feedback - fix docblock placement
  • [x] Fix Behat test syntax to use correct step definition
  • [x] Manually verify the fix with additional test scenarios
  • [x] Run security check

Summary

Successfully implemented POT file order preservation in the update-po command. The solution:

  1. Added reorder_translations() method: After merging PO and POT translations, this method creates a new Translations object with entries ordered according to the POT file.

  2. Preserves all translation data: The solution maintains all translations, comments, metadata, and headers while only changing the order.

  3. Works with all entry types: Tested with simple translations, plural forms, translations with contexts, translator comments, extracted comments, references, and new/existing translations.

  4. Backward compatible: Existing tests will pass as the functionality remains the same, only the order changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>update-po: Keep POT's order of translations</issue_title> <issue_description>It would be nice (if not the default, as an option) to keep translations in the order they appear in the POT file when executing the update-po command.

This would help translators better understand the context (keep messages close to one another if they originate from the same source file) and make the diffs clearer (for instance, when a source message is changed in the code).</issue_description>

Comments on the Issue (you are @copilot in this section)

@swissspidy Interesting suggestion!

Not sure if the underlying library we use actually supports this. It would require some investigation.</comment_new>

  • Fixes wp-cli/i18n-command#446

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 03 '25 13:11 Copilot

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

:loudspeaker: Thoughts on this report? Let us know!

codecov[bot] avatar Nov 03 '25 14:11 codecov[bot]