Skip to content

Scan for esc_xml_*() localization helpers - #221

Merged
schlessera merged 2 commits into
wp-cli:masterfrom
pbiron:esc_xml
Jul 8, 2020
Merged

schlessera merged 2 commits into
wp-cli:masterfrom
pbiron:esc_xml

Conversation

@pbiron

@pbiron pbiron commented Jul 6, 2020

Copy link
Copy Markdown
Contributor

Addresses #220.

This the first time I've looked at the i18n make-pot code, so I'm not positive this PR does what I think it does :-)

I looked at the existing unit tests and couldn't figure out how to add a test for esc_xml__(), etc. Pointers on how to write that test greatly appreciated.

@pbiron
pbiron requested a review from a team as a code owner July 6, 2020 22:02
@swissspidy

Copy link
Copy Markdown
Member

Most of the functionality is covered by Behat tests, not unit tests. Those should be rather self explanatory.

@pbiron

pbiron commented Jul 7, 2020

Copy link
Copy Markdown
Contributor Author

Most of the functionality is covered by Behat tests, not unit tests. Those should be rather self explanatory.

maybe self explanatory if I knew how to write behat tests :-) I'll guess I'll have to learn.

@swissspidy

Copy link
Copy Markdown
Member

@pbiron You can basically just amend this part with esc_xml__ & co:

Scenario: Extract all supported functions
Given an empty foo-plugin directory
And a foo-plugin/foo-plugin.php file:
"""
<?php
/**
* Plugin Name: Foo Plugin
*/
__( '__', 'foo-plugin' );
esc_attr__( 'esc_attr__', 'foo-plugin' );
esc_html__( 'esc_html__', 'foo-plugin' );
_e( '_e', 'foo-plugin' );
esc_attr_e( 'esc_attr_e', 'foo-plugin' );
esc_html_e( 'esc_html_e', 'foo-plugin' );
_x( '_x', '_x_context', 'foo-plugin' );
_ex( '_ex', '_ex_context', 'foo-plugin' );
esc_attr_x( 'esc_attr_x', 'esc_attr_x_context', 'foo-plugin' );
esc_html_x( 'esc_html_x', 'esc_html_x_context', 'foo-plugin' );
_n( '_n_single', '_n_plural', $number, 'foo-plugin' );
_nx( '_nx_single', '_nx_plural', $number, '_nx_context', 'foo-plugin' );
_n_noop( '_n_noop_single', '_n_noop_plural', 'foo-plugin' );
_nx_noop( '_nx_noop_single', '_nx_noop_plural', '_nx_noop_context', 'foo-plugin' );
// Compat.
_( '_', 'foo-plugin' );
// Deprecated.
_c( '_c', 'foo-plugin' );
_nc( '_nc_single', '_nc_plural', $number, 'foo-plugin' );
__ngettext( '__ngettext_single', '__ngettext_plural', $number, 'foo-plugin' );
__ngettext_noop( '__ngettext_noop_single', '__ngettext_noop_plural', 'foo-plugin' );
__unsupported_func( '__unsupported_func', 'foo-plugin' );
__( 'wrong-domain', 'wrong-domain' );
"""
When I run `wp i18n make-pot foo-plugin`
Then STDOUT should be:
"""
Plugin file detected.
Success: POT file successfully generated!
"""
And the foo-plugin/foo-plugin.pot file should exist
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "esc_attr__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "esc_html__"
"""

Copy & paste :-)

@pbiron

pbiron commented Jul 8, 2020

Copy link
Copy Markdown
Contributor Author

the behat tests have been updated and, yeah, travis was happy...so I guess I did the mods correctly :-)

@schlessera schlessera added the command:i18n-make-pot Related to 'i18n make-pot' command label Jul 8, 2020
@schlessera schlessera added this to the 2.2.5 milestone Jul 8, 2020
@schlessera
schlessera merged commit b02ecdc into wp-cli:master Jul 8, 2020
@schlessera schlessera changed the title Scan for esc_xml_*() l10n helpers. Scan for esc_xml_*() localization helpers Jul 8, 2020
@schlessera

Copy link
Copy Markdown
Member

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.

3 participants