Skip to content

Add --headers parameter#58

Merged
schlessera merged 2 commits intowp-cli:masterfrom
greatislander:headers-parameter
Jul 31, 2018
Merged

Add --headers parameter#58
schlessera merged 2 commits intowp-cli:masterfrom
greatislander:headers-parameter

Conversation

@greatislander
Copy link
Copy Markdown

This PR resolves #47 by adding a --headers parameter which accepts a JSON-formatted array of custom header values which are added to the POT file. If custom headers are passed which correspond to defaults, the default values will be replaced.

@swissspidy swissspidy changed the title Add --headers parameter (fix #47) Add --headers parameter Jul 26, 2018
}

if ( isset( $assoc_args['headers'] ) ) {
$this->headers = json_decode( $assoc_args['headers'], true );
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.

WP-CLI has a nice little utility method for this so you don't need isset() and json_decode().

Example:

$array_arguments = array( 'headers' );
$assoc_args      = \WP_CLI\Utils\parse_shell_arrays( $assoc_args, $array_arguments );

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.

$this->skip_js = Utils\get_flag_value( $assoc_args, 'skip-js', $this->skip_js );
$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 );
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.

Unintended whitespace changes I guess? :-)

@swissspidy
Copy link
Copy Markdown
Member

Thanks @greatislander! This is coming along nicely.

- Use WP-CLI utility functions where possible
- Fix inadvertent whitespace changes
- Revert accidental composer.json changes
@greatislander
Copy link
Copy Markdown
Author

@swissspidy Updated based on your feedback -- let me know if there's any other changes you'd like!

@schlessera schlessera added the command:i18n-make-pot Related to 'i18n make-pot' command label Jul 31, 2018
@schlessera schlessera added this to the 0.1.0 milestone Jul 31, 2018
@schlessera schlessera merged commit 1a15b15 into wp-cli:master Jul 31, 2018
@schlessera
Copy link
Copy Markdown
Member

Thanks for the pull-request, @greatislander !

schlessera added a commit that referenced this pull request Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:i18n-make-pot Related to 'i18n make-pot' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow passing custom headers and comments for POT file

3 participants