diff --git a/features/makepot.feature b/features/makepot.feature index cb79d074..aa27227e 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -523,3 +523,33 @@ Feature: Generate a POT file of a WordPress plugin """ msgid "https://foobar.example.com" """ + + Scenario: Prints a warning when two identical strings have different translator comments. + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin.php file: + """ + translations[] = $translation; } + foreach( $this->translations as $translation ) { + if ( ! $translation->hasExtractedComments() ) { + continue; + } + + $comments = $translation->getExtractedComments(); + $comments_count = count( $comments ); + + if ( $comments_count > 1 ) { + WP_CLI::warning( sprintf( + 'The string "%1$s" has %2$d different translator comments.', + $translation->getOriginal(), + $comments_count + ) ); + } + } + return PotGenerator::toFile( $this->translations, $this->destination ); } diff --git a/src/WordPressFunctionsScanner.php b/src/WordPressFunctionsScanner.php index 846a6668..b98d56dd 100644 --- a/src/WordPressFunctionsScanner.php +++ b/src/WordPressFunctionsScanner.php @@ -80,11 +80,11 @@ public function saveGettextFunctions( Translations $translations, array $options // Todo: Require a domain? if ( (string) $original !== '' && ( $domain === null || $domain === $translations->getDomain() ) ) { $translation = $translations->insert( $context, $original, $plural ); - $translation->addReference( $file, $line ); + $translation = $translation->addReference( $file, $line ); if ( isset( $function[3] ) ) { foreach ( $function[3] as $extractedComment ) { - $translation->addExtractedComment( $extractedComment ); + $translation = $translation->addExtractedComment( $extractedComment ); } } }