I am using coder to review code of my module, and I am seeing this in .module file. I am not sure how to fix this up.

Line 49: The $string argument to t() should not begin or end with a space. (Drupal Docs) [i18n_11]

  '#title' => check_plain(t('Role Limit (' . $value . ')')),
  • Are you using Drupal 6? – Randell Mar 20 '14 at 6:06
  • 1
    No, its Drupa 7. – Tanvir Ahmad Mar 20 '14 at 8:04

It's a bug with coder module.. I can replicate using D7 version... See fix below..

'#title' => t('Role Limit (@value)', array('@value' => $value)),

Root cause analysis of above problem is

Coder works with pattern matching to report errors.. In above code you can see a space before single quote inside t function.. that's the reason it's throwing error...

I see same issue in D7 too... Changing your code as explained above will solve the issue..

| improve this answer | |
  • You should't use variables directly in t() function. – Елин Й. Mar 20 '14 at 6:38
  • Agree @ Елин Й , Updated my answer :-) – Anil Sagar Mar 20 '14 at 6:54

The correct way of using variables in t() function is using placeholders.

Example of a correct usage:

$string = t('Role Limit @value', array('@value' => $value));

There are three types of placeholders for t() function.

  • @variable : The variable will be checked through check_plain() function before it is inserted, so you don't need to check it in your script.
  • !variable : The variable will be inserted as it is.
  • %variable : The variable will be checked through check_plain() and highlighted with drupal_placeholder()
| improve this answer | |

The message from the coder module is pretty much nonsense. The text of the error message doesn't really explain the problem.

You cannot pass variables into the t() function like that (check the docs in the link It specifically says that).

The reason is users submitting translations can't possibly know what is in that variable so it cannot be translated.

Also, you don't need to run through check_plain() if you use t() correctly as it will do that for you (check out the different replacement patterns you can use and what they do in the drupal 6 version of the docs for the t() function).

You should do it like this:

'#title' => t('Role Limit (@value)', array('@value' => $value)),
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.