There is no difference between using t()
in modules, or themes; in both the cases, the function expects the string passed as argument to be in English.
Between using t()
, even when you know the page is always show in a specific language, and using a string that is in the language you know to use, using t()
is preferable.
Why? Because in the first case, the string would be hardcoded in the code of the theme, which means you cannot change it without to change the code. If the page that you are now showing in a language needs to be shown in a different language, you should change the code of your theme to change the strings. That is exactly what t()
avoids.
Suppose that the same code is used for more than one site, and in one site one of the string needs to be different. Without using t()
, you would need two different themes, while using t()
you would use the same code for both the sites.
It's enough that in the settings.php file you add lines similar to the following:
$conf['locale_custom_strings_en'][''] = array(
'forum' => 'Discussion board',
'@count min' => '@count minutes',
);
The example is for changing the strings used for English, but the same can be done for every language; it's enough you change the "_en" part in "locale_custom_strings_en" with the language ID for the language you are interested. The first string is in English, and the second string is the translation of the first string in that language.
Suppose that your theme contains print t('forum')
. Adding that code in the settings.php file, what the user will see, when the currently set language for that page is English, is "Discussion board"; if your theme contains print 'forum'
, the user will always see "forum," and to change that you need to change the code of your theme.
I could also use the following code:
$conf['locale_custom_strings_it'][''] = array(
'forum' => 'Tavola di discussione',
'@count min' => '@count minuti primi',
);
In this case, when Italian is the language set for a page, and the theme contains print t('forum')
, what the users will see is "Tavola di discussione."