-
Notifications
You must be signed in to change notification settings - Fork 59
Add dedicated wp i18n audit command with JSON and GitHub Actions output formats
#459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Copilot
wants to merge
19
commits into
main
Choose a base branch
from
copilot/add-i18n-audit-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b30a367
Initial plan
Copilot cb2df63
Add new i18n audit command with multiple output formats
Copilot 33ffb82
Fix debug context from 'make-pot' to 'audit' in AuditCommand
Copilot 16e72a9
Improve code quality: add helper method and documentation
Copilot 242d6aa
Refactor AuditCommand to extend MakePotCommand and eliminate code dup…
Copilot 83d45cd
Suppress log and summary messages in non-plaintext output formats
Copilot baa2210
Fix --ignore-domain flag to properly extract all strings regardless o…
Copilot 56333d7
Lint fixes
swissspidy ddba9bf
Remove unused line
swissspidy 336153e
Return false
swissspidy 8e1d8a0
Return false
swissspidy ee82ee7
Merge branch 'main' into copilot/add-i18n-audit-command
swissspidy ab7d23c
Fix file data access
swissspidy c311f0e
Merge branch 'main' into copilot/add-i18n-audit-command
swissspidy 4c3a823
Update src/AuditCommand.php
swissspidy 4ea4b9b
Remove unnecessary quote-stripping regex as gettext already provides …
Copilot 9b1ee8e
Refactor code for better readability: simplify unique comments and th…
Copilot b5563fa
Update src/AuditCommand.php
swissspidy 1753a81
Fix FileDataExtractor data access to check ['value'] key consistently…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| Feature: Audit strings in a WordPress project | ||
|
|
||
| Background: | ||
| Given a WP install | ||
|
|
||
| Scenario: Audits a plugin for translation issues | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. | ||
| """ | ||
| And STDERR should contain: | ||
| """ | ||
| Warning: Found 1 issue. | ||
| """ | ||
| And the return code should be 0 | ||
|
|
||
| Scenario: Audits a plugin and finds no issues | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello World', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I run `wp i18n audit foo-plugin` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Success: No issues found. | ||
| """ | ||
| And STDERR should be empty | ||
|
|
||
| Scenario: Outputs audit results as JSON | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I run `wp i18n audit foo-plugin --format=json` | ||
| Then STDOUT should contain: | ||
| """ | ||
| "file": "foo-plugin.php" | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| "line": 7 | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| "message": "The string \"Hello %s\" contains placeholders but has no \"translators:\" comment to clarify their meaning." | ||
| """ | ||
| And STDOUT should contain: | ||
| """ | ||
| "code": "missing-translator-comment" | ||
| """ | ||
|
|
||
| Scenario: Outputs audit results in GitHub Actions format | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I run `wp i18n audit foo-plugin --format=github-actions` | ||
| Then STDOUT should contain: | ||
| """ | ||
| ::warning file=foo-plugin.php,line=7::The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. | ||
| """ | ||
|
|
||
| Scenario: Detects multiple unordered placeholders | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: Multiple placeholders should be ordered. | ||
| """ | ||
|
|
||
| Scenario: Detects strings without translatable content | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( '%s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: Found string without translatable content. | ||
| """ | ||
|
|
||
| Scenario: Detects multiple translator comments | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| /* translators: Comment 1 */ | ||
| __( 'Hello World', 'foo-plugin' ); | ||
|
|
||
| /* translators: Comment 2 */ | ||
| __( 'Hello World', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php: | ||
| """ | ||
| And STDERR should contain: | ||
| """ | ||
| different translator comments | ||
| """ | ||
|
|
||
| Scenario: Detects missing singular placeholder | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| _n( 'One comment', '%s Comments', $count, 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: Missing singular placeholder, needed for some languages. | ||
| """ | ||
|
|
||
| Scenario: Detects mismatched placeholders in plural strings | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| _n( '%s Comment', '%d Comments', $count, 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: Mismatched placeholders for singular and plural string. | ||
| """ | ||
|
|
||
| Scenario: Respects --ignore-domain flag | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'different-domain' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin --ignore-domain` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. | ||
| """ | ||
|
|
||
| Scenario: Respects --skip-php flag | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I run `wp i18n audit foo-plugin --skip-php` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Success: No issues found. | ||
| """ | ||
|
|
||
| Scenario: Shows file before warning message in plaintext format | ||
| Given an empty foo-plugin directory | ||
| And a foo-plugin/foo-plugin.php file: | ||
| """ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Foo Plugin | ||
| * Text Domain: foo-plugin | ||
| */ | ||
|
|
||
| __( 'Hello %s', 'foo-plugin' ); | ||
| """ | ||
|
|
||
| When I try `wp i18n audit foo-plugin --format=plaintext` | ||
| Then STDERR should contain: | ||
| """ | ||
| Warning: foo-plugin.php:7: The string "Hello %s" contains placeholders but has no "translators:" comment to clarify their meaning. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.