-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
I18n (PHP): Add lint to avoid including HTML tags in a translated string #19911
Comments
Yes, can you make a PR that adds it to the PHPCS config? |
If the issue is about markup in translated strings, would it be safe to assume that it affects strings both in PHP and in JavaScript? If so, I think it would be a combination of:
|
Yes we should add this for JS as well. I think it’s generic enough to be
enabled for all of WordPress.
|
I was mostly thinking of PHP, since these days, I think I kinda equate JS === React, where I don't think anyone would include HTML in a string, but yeah, fair point -- there's non-React JS where that might be the case, so a JS lint rule might make sense as well.
Thanks for the pointers! I'll try to work on this as soon as I find some time 😅 |
With #17376, we can probably expect it to be more common. I might hope that the overhead of using |
Note that in PHP, while HTML in i18n strings is typically avoided, sometimes it is necessary. |
When?
|
The main WPCS repo doesn't include many i18n sniffs The last I recall I think there were some i18n sniffs in the Automattic or VIP configs, would have to check this |
Found an issue in WPCS asking for a sniff like this: WordPress/WordPress-Coding-Standards#1419 Edit: It's apparently not without controversy, but people seem to agree that 'wrapping' HTML tags ( |
Could someone summarize what the "issue" is, exactly? Is it that all HTML markup in translated strings is bad? Based on:
... I don't think this is what we're wanting out of a rule is to forbid it altogether? Or is it more about forbidding them by default, and force the conscious decision to opt-out of (inline disable) the rule? Otherwise, I think @ockham identifies the issue as being the specific use of wrapping tags, which is consistent with the "i18n for WordPress" page mentioned above:
So maybe the rule can be: Forbid translation strings where the string is wrapped in a single pair of HTML opening and closing tags:
This seems to cover what was originally discussed in https://github.com/WordPress/gutenberg/pull/19576/files#r366897189. |
Yes, that's the rule. |
Yeah, was leaning towards that. This seems to be the non-controversial part that would cover the issue that was orignally flagged by the WP.com linter, so it'd make sense to get a rule like that in. (Eventually, it might be extended to cover other cases if people agree on them.) |
This has been merged, so I think the next version of WPCS should contain this rule. Leave this issue open until then? Or until we also have something for the JS counterpart? |
We could optionally split it to two issues, but I think as written this should remain open 'til it's addressed in both PHP and JavaScript linting. |
Is your feature request related to a problem? Please describe.
We discovered this issue through an i18n linter set up on WP.com, whereas it wasn't detected within the Gutenberg repo.
Describe the solution you'd like
I think it'd make sense to include similar linting capabilities to Gutenberg, which we'll ideally run from a commit hook, and CI (either Travis or GH Actions) to avoid cases like that in the future.
I'm not sure if core (or WP.org, more generally) already has a linter like that in place (and if we could share it with the Gutenberg repo)?
Question: Do we have a place for PHP linting rules like this in the Gutenberg repo?
Describe alternatives you've considered
N/A
/cc @akirk @epiqueras @chriskmnds
The text was updated successfully, but these errors were encountered: