t() публичный Метод

This function is used to look up a translation tag in dictionaries, and return the translation into the current language. If no translation into the current language can be found, english will be tried, and if that fails, placeholder text will be returned. An array can be passed as the tag. In that case, the array will be assumed to be on the form (language => text), and will be used as the source of translations. This function can also do replacements into the translated tag. It will search the translated tag for the keys provided in $replacements, and replace any found occurrences with the value of the key.
Устаревший: Not used in twig, gettext
public t ( string | array $tag, array $replacements = [], boolean $fallbackdefault = true, $oldreplacements = [], $striptags = false ) : string
$tag string | array A tag name for the translation which should be looked up, or an array with (language => text) mappings. The array version will go away in 2.0
$replacements array An associative array of keys that should be replaced with values in the translated string.
$fallbackdefault boolean Default translation to use as a fallback if no valid translation was found.
Результат string The translated tag, or a placeholder value if the tag wasn't found.
Пример #1
0
 /**
  * Test SimpleSAML\Locale\Translate::t().
  */
 public function testTFallback()
 {
     $c = \SimpleSAML_Configuration::loadFromArray(array());
     $t = new Translate($c);
     $testString = 'Blablabla';
     // $fallbackdefault = true
     $result = 'not translated (' . $testString . ')';
     $this->assertEquals($result, $t->t($testString));
     // $fallbackdefault = false, should be a noop
     $this->assertEquals($testString, $t->t($testString, array(), false));
 }
Пример #2
0
 /**
  * Wrap Language->t to translate tag into the current language, with a fallback to english.
  *
  * @see \SimpleSAML\Locale\Translate::t()
  * @deprecated This method will be removed in SSP 2.0. Please use \SimpleSAML\Locale\Translate::t() instead.
  */
 public function t($tag, $replacements = array(), $fallbackdefault = true, $oldreplacements = array(), $striptags = false)
 {
     return $this->translator->t($tag, $replacements, $fallbackdefault, $oldreplacements, $striptags);
 }