1.20.x install.inc st($string, array $args = array(), array $options = array())

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 Backdrop 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.

See also

t()

get_t()

Related topics

File

includes/install.inc, line 1342
API functions for installing modules and themes.

Code

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 ending in install.{$install_state['parameters']['langcode']}.po
      // This might or might not be the entire filename. It is also possible
      // that multiple files end with the same extension, even if unlikely.
      $files = install_find_translation_files($install_state['parameters']['langcode']);
      if (!empty($files)) {
        require_once BACKDROP_ROOT . '/core/includes/gettext.inc';
        foreach ($files as $file) {
          _locale_import_read_po('mem-store', $file);
        }
        $strings = _locale_import_one_string('mem-report');
      }
    }
  }

  // Transform arguments before inserting them
  foreach ($args as $key => $value) {
    switch (substr($key, 0, 1)) {
      // 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);
}