Skip to content
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
30 changes: 30 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
<?php
/**
* Plugin Name: Plugin name
*/

/* translators: Translators 1! */
__( 'Hello World', 'foo-plugin' );

/* translators: Translators 1! */
__( 'Hello World', 'foo-plugin' );

/* Translators: Translators 2! */
__( 'Hello World', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin --debug`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And STDERR should contain:
"""
Warning: The string "Hello World" has 2 different translator comments.
"""
17 changes: 17 additions & 0 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,23 @@ protected function makepot( $domain ) {
$this->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 );
}

Expand Down
4 changes: 2 additions & 2 deletions src/WordPressFunctionsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand Down