-
-
Notifications
You must be signed in to change notification settings - Fork 480
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
Add a translator comment sniff #423
Comments
👍 |
I'm not 100% sure, but I believe subsequent instances of an identical string should not be proceeded by the translator comment (in the same way subsequent uses of a hook or filter shouldn't be documented). Needs checking. |
@johnbillion This depends on whether or not the pot generation will correctly pickup the translator comment if it is only on one of the strings. If that's the case there is still value in this sniff, there then needs to be a way to tell it that the translation has been documented elsewhere. |
Related: #567 |
All, I've started working on adding this check, but would like to verify the exact specs. This is what I've found so far:
Source: https://codex.wordpress.org/I18n_for_WordPress_Developers#Descriptions
Source: https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#descriptions (similar to: https://developer.wordpress.org/themes/functionality/internationalization/#descriptions) However for a sniff those specs are a bit limited. So I have the following questions:
// translators:
/* transators: */
/* translators: a reeeeeaaaaaaaaaallllllllllllllllllllllllllllllllllllly looooonnnnnnnnnnnnnggggggggggg
comment for translators. */
/*
* translators:
*/
/**
* translators:
*/
printf(
/* translators: number of monkeys, location. */
__( 'There are %1$d monkeys in the %2$s', 'my-slug' ),
intval( $number ),
esc_html( $string )
); // This would be ok.
/* translators: number of monkeys, location. */
printf(
__( 'There are %1$d monkeys in the %2$s', 'my-slug' ),
intval( $number ),
esc_html( $string )
); // This would NOT be ok. Other than that I am making the following presumptions:
I will currently not address checking the number of placeholders against the translators comment as the formats used vary and this would IMHO be extremely prone to bugs. See the below examples to illustrate what I mean: /* translators: 1. number of monkeys, 2. location. */
/* translators: %1$d: number of monkeys, %2$s: location. */
/* translators: %d - number of monkeys, %s - location. */
/* translators: number of monkeys, location. */
__( 'There are %1$d monkeys in the %2$s', 'my-slug' ); |
Oh and input on whether or not some form of whitelisting for a gettext call without translators comment is needed and what form it should take would be welcome too ! |
And another question: error or warning ? |
|
@GaryJones Good input. Thanks! The questions regarding the documentation style and whether or not new lines are allowed is not just one of personal preference/"what does core do". I think we also need to look at how tools to generate I can think of a few:
But there are bound to be more tools out there and what about GlotPress ? Anyone here who can give us some insight into the inner workings of these tools with regards to comment style and comment position ? or know of someone who does know ? If so, please ping them to alert them that their input would be much appreciated. |
@ocean90 will know if GlotPress has any considerations here, or whether it internally uses makepot or similar. |
Glotpress uses Makepot. If I am not mistaken then the code that fetched the comments is in This core ticket maybe of interest too. https://core.trac.wordpress.org/ticket/39116 |
PR #742 is ready for testing ;-) |
All strings with placeholders should have a translator comment to explain what the placeholders are replaced with. It would be very nice to have a sniff to automatically flag strings without a proper translator comment.
These would be flagged as incorrect:
And these would be fine:
Strings can be checked for placeholders using the following regex:
%(\d+\$(?:\d+)?)?[bcdefgosuxEFGX]
.The text was updated successfully, but these errors were encountered: