When should I use t() in Drupal?


This page contains information about when, and when not to use the t() function in Drupal 7 (and beyond). I learned this information from the Localization API, and will add more tid-bits as I learn them. Until then, t('thanks for stopping by!');

When to use it...


When to NOT use it...

In hook_menu() and/or hook_perm()

Text declared in hook_menu() and hook_perm() are automatically translated when displayed.

With watchdog()

Watchdog messages are stored in English, and automatically translated when displayed.

In a variable

$msg = 'Hello';
watchdog('example', $msg);

In a .info file

Just use plain strings in your module's .info file, Drupal will take care of the rest.

Add new comment