WordPress/WordPress-Coding-Standards

I18n: do not report `NonSingularStringLiteral` for low level functions

swissspidy opened this issue · 2 comments

Is your feature request related to a problem?

Right now, the i18n sniff reports NonSingularStringLiteral errors to translate and translate_with_gettext_context functions.

The whole point of this sniff is to ensure string extraction works correctly when using the typical translation functions like __(). However, translate and translate_with_gettext_context are not used for string extraction by tools like WP-CLI's i18n command, which is the tool translate.wordpress.org uses.

See: https://github.com/wp-cli/i18n-command/blob/203b020318fe2596a218bf52db25adc6b187f42d/src/PhpCodeExtractor.php#L16-L43

So I don't really see a reason for reporting this error for these two functions.

Describe the solution you'd like

Do not report NonSingularStringLiteral errors for translate and translate_with_gettext_context functions.

Additional context (optional)

The sniff already reports LowLevelTranslationFunction errors when using the low-level translate and translate_with_gettext_context functions. That is fine, plugins and themes don't really have a reason to use these. And if they do, they can suppress the errors.

jrfnl commented

While I get where you are coming from, WP-CLI's i18n command isn't the only way translation files are created...

There is gettext, POEdit, grunt i18n commands etc. And while those may not be commonly in use for WP related code hosted on WP.org, there is a huge market of commercial and proprietary plugins and themes where those other tools are being used.

jrfnl commented

@swissspidy Any response to my reply ? If not, I suggest we close this issue.