8.3.x StringTranslationTrait.php protected StringTranslationTrait::t($string, array $args = [], array $options = [])
8.0.x StringTranslationTrait.php protected StringTranslationTrait::t($string, array $args = array(), array $options = array())
8.1.x StringTranslationTrait.php protected StringTranslationTrait::t($string, array $args = array(), array $options = array())
8.2.x StringTranslationTrait.php protected StringTranslationTrait::t($string, array $args = array(), array $options = array())
8.4.x StringTranslationTrait.php protected StringTranslationTrait::t($string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the Localization API. When possible, use the \Drupal\Core\StringTranslation\StringTranslationTrait $this->t(). Otherwise create a new \Drupal\Core\StringTranslation\TranslatableMarkup object.

Parameters

string $string: A string containing the English text to translate.

array $args: (optional) 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\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options: (optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the Internationalization topic for more information about string contexts.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup An object that, when cast to a string, returns the translated string.

See also

\Drupal\Component\Render\FormattableMarkup::placeholderFormat()

\Drupal\Core\StringTranslation\TranslatableMarkup::__construct()

Related topics

1102 calls to StringTranslationTrait::t()
AccessPluginBase::summaryTitle in core/modules/views/src/Plugin/views/access/AccessPluginBase.php
Returns the summary of the settings in the display.
AccountForm::alterPreferredLangcodeDescription in core/modules/user/src/AccountForm.php
Alters the preferred language widget description.
AccountForm::form in core/modules/user/src/AccountForm.php
Gets the actual form array to be built.
AccountSettingsForm::buildForm in core/modules/user/src/AccountSettingsForm.php
Form constructor.
Action::fields in core/modules/action/src/Plugin/migrate/source/Action.php
Returns available fields on the source.

... See full list

2 methods override StringTranslationTrait::t()
ConfigDependencyDeleteFormTrait::t in core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php
Translates a string to the current language or to a given language.
ContextAwarePluginAssignmentTrait::t in core/lib/Drupal/Core/Plugin/ContextAwarePluginAssignmentTrait.php
Ensures the t() method is available.

File

core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php, line 70

Class

StringTranslationTrait
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Namespace

Drupal\Core\StringTranslation

Code

protected function t($string, array $args = array(), array $options = array()) {
  return new TranslatableMarkup($string, $args, $options, $this->getStringTranslation());
}