Translates a string when some systems are not available.
Used during the install process, when database, theme, and localization system is possibly not yet available.
Use t() if your code will never run during the Drupal installation phase. Use st() if your code will only run during installation and never any other time. Use get_t() if your code could run in either circumstance.
t()
get_t()
function st($string, array $args = array(), array $options = array()) {
static $strings = NULL;
global $install_state;
if (empty($options['context'])) {
$options['context'] = '';
}
if (!isset($strings)) {
$strings = array();
if (isset($install_state['parameters']['langcode'])) {
// If the given langcode was selected, there should be at least one .po
// file with its name in the pattern drupal-$version.$langcode.po.
// This might or might not be the entire filename. It is also possible
// that multiple files end with the same suffix, even if unlikely.
$files = install_find_translation_files($install_state['parameters']['langcode']);
if (!empty($files)) {
// Register locale classes with the classloader. Locale module is not
// yet enabled at this stage, so this is not happening automatically.
drupal_classloader_register('locale', drupal_get_path('module', 'locale'));
$strings = Gettext::filesToArray($install_state['parameters']['langcode'], $files);
}
}
}
require_once DRUPAL_ROOT . '/core/includes/theme.inc';
// Transform arguments before inserting them
foreach ($args as $key => $value) {
switch ($key[0]) {
// Escaped only
case '@':
$args[$key] = check_plain($value);
break;
// Escaped and placeholder
case '%':
default:
$args[$key] = '<em>' . check_plain($value) . '</em>';
break;
// Pass-through
case '!':
}
}
return strtr(!empty($strings[$options['context']][$string]) ? $strings[$options['context']][$string] : $string, $args);
}