diff --git a/features/makepot.feature b/features/makepot.feature index a955a3d5..a048473c 100644 --- a/features/makepot.feature +++ b/features/makepot.feature @@ -2608,6 +2608,7 @@ Feature: Generate a POT file of a WordPress project """ #. translators: %s: test #: foo-plugin.js:1 + #, js-format msgid "Hi %s" msgstr "" """ @@ -4097,3 +4098,60 @@ Feature: Generate a POT file of a WordPress project """ msgid "Not extracted style variation description" """ + + Scenario: Add php-format and js-format flags for printf usage + Given an empty foo-plugin directory + And a foo-plugin/foo-plugin.php file: + """ + insert( $context, $original, $plural ); + if ( $add_reference ) { $translation->addReference( $file, $line ); } + if ( + 1 === preg_match( MakePotCommand::SPRINTF_PLACEHOLDER_REGEX, $original ) || + 1 === preg_match( MakePotCommand::UNORDERED_SPRINTF_PLACEHOLDER_REGEX, $original ) + ) { + $translation->addFlag( 'js-format' ); + } + /** @var Node\Comment $comment */ foreach ( $all_comments as $comment ) { // Comments should be before the translation. diff --git a/src/PhpFunctionsScanner.php b/src/PhpFunctionsScanner.php index 9ec67878..033ba2d0 100644 --- a/src/PhpFunctionsScanner.php +++ b/src/PhpFunctionsScanner.php @@ -72,10 +72,18 @@ public function saveGettextFunctions( $translations, array $options ) { } $translation = $translations->insert( $context, $original, $plural ); + if ( $add_reference ) { $translation = $translation->addReference( $file, $line ); } + if ( + 1 === preg_match( MakePotCommand::SPRINTF_PLACEHOLDER_REGEX, $original ) || + 1 === preg_match( MakePotCommand::UNORDERED_SPRINTF_PLACEHOLDER_REGEX, $original ) + ) { + $translation->addFlag( 'php-format' ); + } + if ( isset( $function[3] ) ) { foreach ( $function[3] as $extracted_comment ) { $translation = $translation->addExtractedComment( $extracted_comment );