Skip to content
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

Improve warnings for strings with different comments #318

Merged
merged 6 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,8 @@ Feature: Generate a POT file of a WordPress project
And STDERR should contain:
"""
Warning: The string "Hello World" has 2 different translator comments. (foo-plugin.php:7)
translators: Translators 1!
Translators: Translators 2!
"""

Scenario: Does not print a warning when two identical strings have the same translator comment
Expand Down Expand Up @@ -932,7 +934,7 @@ Feature: Generate a POT file of a WordPress project
"""
And STDERR should not contain:
"""
Warning: The string "Hello World" has 2 different translator comments. (foo-plugin.php:7)
Warning: The string "Hello World" has 2 different translator comments.
"""

Scenario: Skips excluded folders
Expand Down Expand Up @@ -3646,7 +3648,7 @@ Feature: Generate a POT file of a WordPress project
}
}
"""

When I try `wp i18n make-pot foo-theme`
Then STDOUT should be:
"""
Expand Down
7 changes: 4 additions & 3 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ protected function audit_strings( $translations ) {
$references = $translation->getReferences();

// File headers don't have any file references.
$location = $translation->hasReferences() ? '(' . implode( ':', array_shift( $references ) ) . ')' : '';
$location = $translation->hasReferences() ? '(' . implode( ':', $references[0] ) . ')' : '';

// Check 1: Flag strings with placeholders that should have translator comments.
if (
Expand Down Expand Up @@ -805,10 +805,11 @@ function ( $comment ) use ( &$unique_comments ) {

if ( $comments_count > 1 ) {
$message = sprintf(
'The string "%1$s" has %2$d different translator comments. %3$s',
"The string \"%1\$s\" has %2\$d different translator comments. %3\$s\n%4\$s",
$translation->getOriginal(),
$comments_count,
$location
$location,
implode( "\n", $unique_comments )
);
WP_CLI::warning( $message );
}
Expand Down