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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Scans PHP and JavaScript files, as well as theme stylesheets for translatable st
By default, the following files and folders are ignored: node_modules, .git, .svn, .CVS, .hg, vendor.
Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.

[--headers=<headers>]
Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.

[--skip-js]
Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.

Expand Down
22 changes: 22 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@ Feature: Generate a POT file of a WordPress plugin
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
"""

Scenario: Sets custom Report-Msgid-Bugs-To
When I run `wp scaffold plugin hello-world`

When I run `wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot --headers='{"Report-Msgid-Bugs-To":"https://github.com/hello-world/hello-world/"}'`
And the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
"""
"Report-Msgid-Bugs-To: https://github.com/hello-world/hello-world/\n"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add another test like

And the wp-content/plugins/hello-world/languages/hello-world.pot file should not contain:
  """
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
  """

to prove that the heaader is indeed being replaced and not added.

"""
And the wp-content/plugins/hello-world/languages/hello-world.pot file should not contain:
"""
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/hello-world\n"
"""

Scenario: Sets custom header
When I run `wp scaffold plugin hello-world`

When I run `wp i18n make-pot wp-content/plugins/hello-world wp-content/plugins/hello-world/languages/hello-world.pot --headers='{"X-Poedit-Basepath":".."}'`
And the wp-content/plugins/hello-world/languages/hello-world.pot file should contain:
"""
"X-Poedit-Basepath: ..\n"
"""

Scenario: Sets the last translator and the language team
When I run `wp scaffold plugin hello-world`

Expand Down
21 changes: 18 additions & 3 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class MakePotCommand extends WP_CLI_Command {
*/
protected $skip_js = false;

/**
* @var array
*/
protected $headers = [];

/**
* @var string
*/
Expand Down Expand Up @@ -91,6 +96,9 @@ class MakePotCommand extends WP_CLI_Command {
* By default, the following files and folders are ignored: node_modules, .git, .svn, .CVS, .hg, vendor.
* Leading and trailing slashes are ignored, i.e. `/my/directory/` is the same as `my/directory`.
*
* [--headers=<headers>]
* : Array in JSON format of custom headers which will be added to the POT file. Defaults to empty array.
*
* [--skip-js]
* : Skips JavaScript string extraction. Useful when this is done in another build step, e.g. through Babel.
*
Expand All @@ -102,9 +110,12 @@ class MakePotCommand extends WP_CLI_Command {
* @when before_wp_load
*/
public function __invoke( $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 );
$array_arguments = array( 'headers' );
$assoc_args = \WP_CLI\Utils\parse_shell_arrays( $assoc_args, $array_arguments );
$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->headers = Utils\get_flag_value( $assoc_args, 'headers', $this->headers );

$ignore_domain = Utils\get_flag_value( $assoc_args, 'ignore-domain', false );

Expand Down Expand Up @@ -413,6 +424,10 @@ protected function set_default_headers() {
$this->translations->setHeader( 'Report-Msgid-Bugs-To', $meta['msgid-bugs-address'] );
$this->translations->setHeader( 'Last-Translator', 'FULL NAME <EMAIL@ADDRESS>' );
$this->translations->setHeader( 'Language-Team', 'LANGUAGE <LL@li.org>' );

foreach( $this->headers as $key => $value ) {
$this->translations->setHeader( $key, $value );
}
}

/**
Expand Down