Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

When should I use t() in Drupal?

Category: 
Tags: 

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...

drupal_set_message(t('Hello'));
l(t('Hello'));

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';
drupal_set_message($msg);
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