I've been searching through the documentation for both the t() and the Drupal coding standard for a best practice for wrapping lengthy string literals being passed into t(). Code Sniffer flags any concatenation in the first argument, presumably to prevent variables from being concatenated in instead of using placeholders. Something like this passes:

$text = t('There have been a connection problem or we have been provided with
  wrong login credentials. Please, choose ID verification method once more
  and try again.');

However, this actually adds line breaks into the string and since Drupal's string matching actually matches whitespace characters, this is fraught. Instead, this would be preferable:

$text = t('There have been a connection problem or we have been provided with' .
  ' wrong login credentials. Please, choose ID verification method once more' .
  ' and try again.'); 

My request is that the concatenation detection in Code Sniffer be made so that it ALLOWS concatenation if the concatenation is another string literal.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lunaris’s picture

Status: Active » Needs review
FileSize
948 bytes

Here's a patch that I think works. Unfortunately, since I was just hacking on my installation of PHP_CodeSniffer the changes weren't made under Git and so it needs re-rolling by someone working on head to be of any use. Marking as needs review.

klausi’s picture

Status: Needs review » Closed (won't fix)

Our translation extraction tools cannot detect strings concatenated with ".", therefore you should never use it for your translatable strings.

Note that code lines such as t() calls can exceed 80 characters per line, only comments are limited to 80 characters.