t

Definition

t($string, $args = 0)
includes/common.inc, line 535

Description

Translate strings to the current locale.

When using t(), try to put entire sentences and strings in one t() call. This makes it easier for translators. HTML markup within translation strings is acceptable, if necessary. The suggested syntax for a link embedded within a translation string is:

<?php

$msg = t('You must log in below or <a href="%url">create a new
account</a> before viewing the next page.', array('%url'
=> url('user/register')));

?>

We suggest the same syntax for links to other sites. This makes it easy to change link URLs if needed (which happens often) without requiring updates to translations.

Parameters

$string A string containing the English string to translate.

$args An associative array of replacements to make after translation. Incidences of any key in this array are replaced with the corresponding value.

Return value

The translated string.

Code

<?php
function t($string, $args = 0) {
  global $locale;
  if (function_exists('locale') && $locale != 'en') {
    $string = locale($string);
  }

  if (!$args) {
    return $string;
  }
  else {
    return strtr($string, $args);
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.