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
70 changes: 70 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,76 @@ Feature: Generate a POT file of a WordPress project
msgid "Hello World"
"""

Scenario: Skips PHP file altogether
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/

__( 'Hello World from PHP', 'foo-plugin' );
"""
And a foo-plugin/foo-plugin.js file:
"""
__( 'Hello World from JavaScript', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin foo-plugin.pot --skip-php`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin.pot file should not contain:
"""
msgid "Hello World from PHP"
"""
And the foo-plugin.pot file should contain:
"""
msgid "Hello World from JavaScript"
"""

Scenario: Skips JavaScript file and PHP file altogether
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/

__( 'Hello World from PHP', 'foo-plugin' );
"""
And a foo-plugin/foo-plugin.js file:
"""
__( 'Hello World from JavaScript', 'foo-plugin' );
"""

When I run `wp i18n make-pot foo-plugin foo-plugin.pot --skip-js --skip-php`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin.pot file should contain:
"""
msgid "Foo Plugin"
"""
And the foo-plugin.pot file should not contain:
"""
msgid "Hello World from PHP"
"""
And the foo-plugin.pot file should not contain:
"""
msgid "Hello World from JavaScript"
"""

Scenario: Extract all strings regardless of text domain
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
Expand Down
27 changes: 19 additions & 8 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class MakePotCommand extends WP_CLI_Command {
*/
protected $skip_js = false;

/**
* @var bool
*/
protected $skip_php = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -190,6 +195,9 @@ class MakePotCommand extends WP_CLI_Command {
* [--skip-js]
* : Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.
*
* [--skip-php]
* : Skips PHP string extraction.
*
* [--skip-audit]
* : Skips string audit where it tries to find possible mistakes in translatable strings. Useful when running in an
* automated environment.
Expand Down Expand Up @@ -267,6 +275,7 @@ public function handle_arguments( $args, $assoc_args ) {
$this->source = realpath( $args[0] );
$this->slug = Utils\get_flag_value( $assoc_args, 'slug', Utils\basename( $this->source ) );
$this->skip_js = Utils\get_flag_value( $assoc_args, 'skip-js', $this->skip_js );
$this->skip_php = Utils\get_flag_value( $assoc_args, 'skip-php', $this->skip_php );
$this->skip_audit = Utils\get_flag_value( $assoc_args, 'skip-audit', $this->skip_audit );
$this->headers = Utils\get_flag_value( $assoc_args, 'headers', $this->headers );
$this->file_comment = Utils\get_flag_value( $assoc_args, 'file-comment' );
Expand Down Expand Up @@ -560,14 +569,16 @@ protected function extract_strings() {
}

try {
$options = [
// Extract 'Template Name' headers in theme files.
'wpExtractTemplates' => isset( $this->main_file_data['Theme Name'] ),
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'php' ],
];
PhpCodeExtractor::fromDirectory( $this->source, $translations, $options );
if ( ! $this->skip_php ) {
$options = [
// Extract 'Template Name' headers in theme files.
'wpExtractTemplates' => isset( $this->main_file_data['Theme Name'] ),
'include' => $this->include,
'exclude' => $this->exclude,
'extensions' => [ 'php' ],
];
PhpCodeExtractor::fromDirectory( $this->source, $translations, $options );
}

if ( ! $this->skip_js ) {
JsCodeExtractor::fromDirectory(
Expand Down