Closed swissspidy closed 1 year ago
I have a working version of text domain validation ready, will push it soon.
Passing a variable to
__()
et al instead of a string literal
This is currently enforced using no-restricted-syntax
:
Should be fairly easy to port this to its own proper rule.
Needs some way to detect whether text is passed as a prop or child that should probably be translatable
Some cases, off the top of my head:
aria-*
,title
, alt
attributes<div>Hello World</div>
or <div>{ 'Hello World' }</div>
Might even be fixable by wrapping the found strings in __()
It looks like a lot of tasks listed are done. Excellent work! There is only one left on the list that was initially marked as “likely to do”. @swissspidy, what would be your current recommendation on criteria to consider this issue finished?
I was just thinking the pther day that a rule for catching trailing whitespace would be nice. See https://core.trac.wordpress.org/ticket/55669
This mistake wasn‘t caught in the Gutenberg code base.
I was just thinking the pther day that a rule for catching trailing whitespace would be nice. See https://core.trac.wordpress.org/ticket/55669
This mistake wasn‘t caught in the Gutenberg code base.
I agree that it would be great to cover as much as possible from the cases that slipped through WP 6.0 Beta phase from the Gutenberg repository ❤️
Looks like #38225 introduced such a rule (i18n-no-flanking-whitespace
)
Edit: this begs the question why it didn't catch dd7db32c1a3430046576b9c2da3f306d7cec06d2
Looks like the rule was only enabled for React Native code and not the whole code base 🙃
@jhnstn Do you recall why it wasn't considered to apply the i18n-no-flanking-whitespace
rule for the rest of the code base? Seems like a missed opportunity.
@jhnstn Do you recall why it wasn't considered to apply the
i18n-no-flanking-whitespace
rule for the rest of the code base? Seems like a missed opportunity.
It would be great to find out and potentially enable for the rest of Gutenberg 👍🏻
Is your feature request related to a problem? Please describe.
Similar to the i18n sniffs in WPCS there could be some custom ESLint rules to catch some common i18n mistakes.
Describe the solution you'd like
Off the top of my head, there could be rules like follows:
Done
default
instead of just omitting it)sprintf
with placeholders%s
andsprintf
~ -> tracked separately in #20554.Likely to-do
%s
placeholders instead (e.g. URLs)On the fence
Needs some way to detect whether text is passed as a prop or child that should probably be translatable (e.g.
aria-label
prop). Helps catch places where__()
is forgotten.__()
(e.g.__( 'Hello' + '' + 'World' )
_x()
instead of__()
under certain conditions (needs list of ambiguous terms)__experimentalCreateInterpolateElement
__experimentalCreateInterpolateElement
defaultProps
(when using prop-types)Actual implementation should be split up into multiple PRs.
Describe alternatives you've considered
Find other solutions out there that likely won't work with
@wordpress/i18n
or build something custom.