-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
Fixes I18NSniff for multi-line gettext
calls
#1962
base: develop
Are you sure you want to change the base?
Conversation
623e1b2
to
19bab38
Compare
@sdnunca What do you base this on ? The sniff implementation as-is is based on the PO specs + the implementation of the most commonly used tools. None of which agree with your statement. |
19bab38
to
353ad94
Compare
@jrfnl Thanks for looking into this so quickly. I've encountered this extracting comments with If the call is multi line and the comment is on the line above, the text is not extracted. |
Related #742 |
I'm not sure if this is particular to |
353ad94
to
9adee92
Compare
Ok, interesting. Not sure if that was changed between the original implementation and now, but never mind that. For this PR to be considered, tests will need to be run with all commonly used tooling to extract translatable strings, like Someone will need to create an overview of how each of those tools handle the various situations highlighted in the screenshot above. Once that is done, it can be evaluated whether this PR would improve or break compatibility with the various tools. Only if it would turn out that it would improve compatibility, a full code review of this PR will be done. @sdnunca Please don't take this push-back the wrong way. I appreciate your initiative and interest in improving WPCS. It might have been better to initially open an issue about this to discuss the problem instead of opening a PR. |
@jrfnl Again, thank you so much for taking the time to look into this.
I'll definitely keep that in mind for the future :) . I'll further investigate and get back with my findings on compatibility. |
Here's the result of my testing. List of tools checked:
Test file:<?php
/*
* Plugin Name: Test plugin
* Description: Test description
* Text Domain: test-plugin
*/
/* translators: number of monkeys, location 1. */
__( 'There are %1$d monkeys in the %2$s 1'
); // Ok, the string is on the same line as the gettext call
__( /* translators: number of monkeys, location 2.*/
'There are %1$d monkeys in the %2$s 2'
); // OK, comment is on the same line as the gettext call
/* translators: number of monkeys, location 3. */
_n(
'There are %1$d monkeys in the %2$s 3',
'There are %1$d monkeys in the %2$s 3'
); // Bad, comment will not be extracted
_n(
/* translators: number of monkeys, location 4. */
'There are %1$d monkeys in the %2$s 4',
'There are %1$d monkeys in the %2$s 4'
); // Ok, comment will be extracted
function test_plugin_init() {
load_plugin_textdomain( 'test-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action( 'plugins_loaded', 'test_plugin_init' ); 1. wp i18n make-pot (also used by core)Conclusion: All locations are extracted by 2. POEditLocations #1, #2, #4 are successfully extracted ✅. #3 is NOT ❌. Conclusion: The current implementation is not working with POEdit. 3. Grunt toolingTesting Locations #2 and #4 are NOT extracted ❌. Conclusion: grunt-wp-i18n uses the old ConclusionsAs a conclusion for the whole experiment, we will lose compatibility with grunt-wp-i18n is planning to switch to Please let me know if there are any other tools you feel need testing. |
Hey @jrfnl , |
Currently, there is an issue with the PHPCS Sniff that validates translator comments.
Translator comments usually need to be placed on the line above the gettext call.
However, in the case of multi-line translation function calls, the comment needs to be placed between the line of the function call and the first string.
Here's an example of possible comment locations:
This PR changes the sniff implementation to also take into account the multi-line calls edge case.