Skip to content

Fix extraction of _nx translation function #5330

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

Merged
merged 1 commit into from
Mar 2, 2018

Conversation

atimmer
Copy link
Member

@atimmer atimmer commented Mar 1, 2018

Description

While working on #5310 I found that the babel plugin was not correctly extracting the _nx function. I have used null as a placeholder for the number argument because that explicitly signals a not-used value.

How Has This Been Tested?

Ran in combination with #5310. The PHP file corresponded to my test values of _nx.

Types of changes

Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code has proper inline documentation.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Nice catch. Code-wise, this generally looks good.

Would be nice to have some tests for this, but these are generally missing for the extraction behavior.

@@ -58,7 +58,7 @@ const DEFAULT_FUNCTIONS = {
__: [ 'msgid' ],
_n: [ 'msgid', 'msgid_plural' ],
_x: [ 'msgid', 'msgctxt' ],
_nx: [ 'msgid', 'msgctxt', 'msgid_plural' ],
_nx: [ 'msgid', 'msgid_plural', '_', 'msgctxt' ],
Copy link
Member

Choose a reason for hiding this comment

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

Following the logic, I don't think we really need to assign anything for the number argument. Even null or undefined would suffice:

const key = functionKeys[ i ];
if ( isValidTranslationKey( key ) ) {

function isValidTranslationKey( key ) {
return -1 !== VALID_TRANSLATION_KEYS.indexOf( key );
}

const VALID_TRANSLATION_KEYS = [ 'msgid', 'msgid_plural', 'msgctxt' ];

@atimmer atimmer force-pushed the fix/context-plural-extraction branch from 516ce0e to f688999 Compare March 2, 2018 09:12
@atimmer atimmer force-pushed the fix/context-plural-extraction branch from f688999 to ae6f68a Compare March 2, 2018 09:13
@atimmer
Copy link
Member Author

atimmer commented Mar 2, 2018

I change the _ to a null.

@atimmer atimmer merged commit 7bb2547 into master Mar 2, 2018
@atimmer atimmer deleted the fix/context-plural-extraction branch March 2, 2018 09:23
@atimmer atimmer added this to the 2.3 milestone Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants