Using language codes in PHP

A function has been created in PHP to retrieve the translations of the language codes: _T.

It is used very simply as shown below:

_T('code');
_T('prefix:code');
_T('prefix1/.../prefixN:code');
_T('prefix:code', array('param'=>'value'));

Character strings during development

You may sometimes run into the _L function, which is used to signify: "Character string to be assigned a language code when development is nearly finished". The general idea, is that during development of SPIP or plugin functionality, the language strings may change quite frequently. In order to distinguish strings which have already been translated in the language files from those that have just recently been created, we generally apply the _L function.

_L('This text will need to be codified and translated!');

When the code development has stabilised, a search through the code for uses of the "_L" function makes it easy to replace such character strings with appropriate language codes (and then use the _T function instead).

Example

The "Tickets" plugin has a language file named lang/tickets_fr.php which contains (amidst other code):

$GLOBALS[$GLOBALS['idx_lang']] = array(
    // ...
    'ticket_enregistre' => 'Ticket saved',
);

When someone creates a new ticket, the feedback form indicates that it has actually been saved by sending the language string to the message_ok parameter of the ticket writing form:

$message['message_ok'] = _T('tickets:ticket_enregistre');
// being = "Ticket enregistré" if it were in French.

Author Mark Baber Published : Updated : 16/02/10

Translations : English, français