WPTT / WPThemeReview

PHP_CodeSniffer rules (sniffs) to enforce WordPress theme review coding conventions
MIT License
209 stars 37 forks source link

Check that all text strings are translated and in the same language #33

Open jrfnl opened 8 years ago

jrfnl commented 8 years ago

Rule type:

Error

Rule:

From what I can see, there are actually 5 distinct i18n related rules which may need sniffs - this issue covers the first and fourth item on the list.

  1. All theme text strings are to be translatable.
  2. Include a text domain in style.css (#34)
  3. Use a single unique theme slug – as the theme slug appears in style.css. If it uses a framework then no more than 2 unique slugs. (#35)
  4. Can use any language for text, but only use the same one for all text.
  5. Correct usage of the WP i18n functions. (#31)

Refs: https://make.wordpress.org/themes/handbook/review/required/#language https://make.wordpress.org/themes/handbook/review/required/theme-check-plugin/#additional-checks

Checking whether all text strings are translatable is very tricky as the echo call and the string building aren't always done in the same place. Strings within PHP are often enough also used for other purposes - think array indexes -, so it is doubtful this can be implemented in the form of a sniff.

The Pig Latin plugin comes to mind as a useful tool to check this, but this is a tool that checks at runtime in contrast to PHPCS which does a static code analysis.

Similarly, checking whether all text strings are in the same languages would be a very interesting challenge to.

I believe these will remain manual check.

All the same: ideas welcome ;-)

Theme check file covering this rule:

n/a

Decision needed:

Request for decision: Is it acceptable that this will stay a manual check ?

To do:

grappler commented 8 years ago

I think this will be a difficult check to run. Even with Pig Latin you need to do a manual check for which strings are not being converted.

These are the three main forms that I could think of that we would need to catch.

<span>Hello World</span>
echo 'Hello World!'
array (
    'title' => 'Hello World!',
)

We could help the manuall check by listing strings that need to be check. This would change the check from an ERROR to a WARNING.

Let's keep this as low priorty at the moment.

dingo-d commented 5 years ago

Do we want to work on this, or can we close this issue?

jrfnl commented 5 years ago

The "check that all translatable strings are in the same language" bit may be sniffable if we could do some sort of dictionary check, possibly using the PHP ICU extension, but the "check that all text strings are translatable" bit is neigh impossible to sniff for.

jrfnl commented 5 years ago

All the same, if at all, this should probably be addressed in WPCS itself. Not sure if an upstream issue exists for this yet.