Add update/unchanged file reporting to update-po command
Implement feature to report updated vs unchanged PO files in update-po command
- [x] Explore repository structure and understand the UpdatePoCommand
- [x] Review existing test scenarios
- [x] Implement change detection in UpdatePoCommand.php
- [x] Clone original translations before merging
- [x] Compare Translation objects to detect actual changes
- [x] Track updated vs unchanged file counts separately
- [x] Update success message to show both updated and unchanged files
- [x] Simplify message formatting logic
- [x] Add new test scenarios for the change detection feature
- [x] Test when no files change (POT unchanged)
- [x] Test when some files change and some don't
- [x] Update documentation examples in the command docblock
- [x] Fix change detection to compare objects instead of file content
- [x] Avoids false positives from timestamp/formatting changes
- [x] Compares actual translation data, references, and comments
- [x] Fix method name: use getComments() instead of non-existent getTranslatorComments()
Summary
This PR implements the feature request from issue #333 to improve the update-po command reporting.
Changes Made
-
UpdatePoCommand.php:
- Clone original translations before merging
- Compare Translation objects instead of file content to detect actual changes
- Added
translations_differ()method that compares:- Translation counts
- Individual translation strings and plurals
- Source code references
- Extracted comments and translator comments
- Updated success message to show both updated and unchanged counts
- Fixed to use correct
getComments()method
-
updatepo.feature:
- Added test scenario for unchanged files when POT hasn't changed
- Added test scenario for mixed updated/unchanged files
Output Examples
-
Success: Updated 0 files. 1 file unchanged.- When no files need updating -
Success: Updated 1 file.- When one file is updated, none unchanged -
Success: Updated 4 files. 2 files unchanged.- When multiple files, some updated some not
How It Works
The implementation now properly detects changes by comparing Translation objects instead of raw file content. This avoids false positives from timestamp updates or formatting changes that the gettext library makes when writing PO files.
Original prompt
This section details on the original issue you should resolve
<issue_title>
update-po: Update/no changes report</issue_title> <issue_description>## Feature Request
- [x] Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing (Side note: The new
update-posubcommand is awesome!)Currently it will report that the PO files were updated, even they hadn't changed (because the POT file hadn't changed).
Describe the solution you'd like
update-poshould either report updated files or files that didn't need an update/changing.Some examples:
Success: Updated 0 files. 1 file unchanged.Success: Updated 1 file.Success: Updated 4 files. 2 files unchanged.This also helps spotting the need for adding/updating translations without using something like a diff tool or inspecting the last modified date of the POT file(s).</issue_description>
Comments on the Issue (you are @copilot in this section)
@swissspidy Thanks for sharing this suggestion 👍Would need to check if it's easily possible to detect changes/modifications like that.</comment_new>
- Fixes wp-cli/i18n-command#333
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.
Codecov Report
:x: Patch coverage is 84.44444% with 7 lines in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/UpdatePoCommand.php | 84.44% | 7 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!