Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(make-pot): parses mangled webpack statements (closes #203) #204

Merged
merged 1 commit into from
Mar 2, 2020
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
5 changes: 5 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ Feature: Generate a POT file of a WordPress project
translate.__( 'translate.__', 'foo-plugin' );

Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( 'webpack.__', 'foo-plugin' );
Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( 'webpack.mangle.__', 'foo-plugin' );

Object(u.__)( 'minified.__', 'foo-plugin' );
Object(j._x)( 'minified._x', 'minified._x_context', 'foo-plugin' );
Expand Down Expand Up @@ -1660,6 +1661,10 @@ Feature: Generate a POT file of a WordPress project
"""
msgid "webpack.__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "webpack.mangle.__"
"""
And the foo-plugin/foo-plugin.pot file should contain:
"""
msgid "minified.__"
Expand Down
11 changes: 10 additions & 1 deletion src/JsFunctionsScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,17 @@ private function resolveExpressionCallee( Node\CallExpression $node ) {
// Matches unminified webpack statements:
// Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__["__"])( "translation" );
if ( 'Literal' === $property->getType() ) {
$name = $property->getValue();

// Matches mangled webpack statement:
// Object(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_7__[/* __ */ "a"])( "translation" );
$leading_property_comments = $property->getLeadingComments();
if ( count( $leading_property_comments ) === 1 && $leading_property_comments[0]->getKind() === 'multiline' ) {
$name = trim( $leading_property_comments[0]->getText() );
}

return [
'name' => $property->getValue(),
'name' => $name,
'comments' => $callee->getCallee()->getLeadingComments(),
];
}
Expand Down