Skip to content

Commit

Permalink
Merge pull request #318 from wp-cli/fix/227-references
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Jul 4, 2022
2 parents 7f0a55c + bddba75 commit 0204ade
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion 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
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

0 comments on commit 0204ade

Please sign in to comment.