Translates a string to the current language or to a given language.
string $string: A string containing the English string to translate.
array $args: An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Core\Utility\String::format() for details.
array $options: An associative array of additional options, with the following elements:
string The translated string.
t()
\Drupal\Core\Utility\String::format()
public function translate($string, array $args = array(), array $options = array()) {
// Merge in defaults.
if (empty($options['langcode'])) {
$options['langcode'] = $this->defaultLangcode;
}
if (empty($options['context'])) {
$options['context'] = '';
}
$translation = $this
->getStringTranslation($options['langcode'], $string, $options['context']);
$string = $translation === FALSE ? $string : $translation;
if (empty($args)) {
return $string;
}
else {
return String::format($string, $args);
}
}