t function is one of the most useful functions in Drupal core, it makes multi-lingual sites so easy to maintain.
This is t().
t($string, array $args = array(), array $options = array())
A very basic example
We have a title string “Backyard Garden” that we want it to be translatable, we simply do this.
String with plain text variables
This is when you have variables in your string, use @variable in the string then define later in $args. @variable with the “@” prefix means the text should be run through check_plain.
|t('@name\'s Backyard Garden',array('@name'=>$user->name));|
If you want to use markup such as span or a in your string and you have no choice but to put the markup here, put them in the $string, not in the $arg.
|t('@name\'s Backyard Garden (@count) ',array('@name'=>$user->name,'@count'=>$count));|
If you want to have a link in the string, use !variable which indicates that the text should be inserted as-is.
|t('Welcome to the Backyard Garden. !url.',array('!url'=> l(t('My garden'),'user/'.$user->uid.'/garden')));|
You can also use %variable with prefix %, which indicates that the string should be HTML escaped and highlighted with theme_placeholder() and shows up by default as emphasized.
|t('Welcome to %name Backyard Garden.',array('%name'=>$user->name));|
It happens a lot when you want the same strings to be translated differently in different context, use ‘context’.
|t('Backyard Garden',array(),array('context'=>'Site section title'));|