function t
Same name and namespace in other branches
Translates a string to the current language or to a given language.
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 directly.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
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\StringTranslationTrait::t()
\Drupal\Core\StringTranslation\TranslatableMarkup::__construct()
287 calls to t()
- AccountPermissionsCacheContext::getLabel in core/
lib/ Drupal/ Core/ Cache/ Context/ AccountPermissionsCacheContext.php - Returns the label of the cache context.
- aggregator_entity_extra_field_info in core/
modules/ aggregator/ aggregator.module - Implements hook_entity_extra_field_info().
- aggregator_help in core/
modules/ aggregator/ aggregator.module - Implements hook_help().
- batch_process in core/
includes/ form.inc - Processes the batch.
- batch_set in core/
includes/ form.inc - Adds a new batch.
72 string references to 't'
- CommentType::query in core/
modules/ comment/ src/ Plugin/ migrate/ source/ CommentType.php - DateHelper::days in core/
lib/ Drupal/ Core/ Datetime/ DateHelper.php - Constructs an array of days in a month.
- DateHelper::daysInMonth in core/
lib/ Drupal/ Core/ Datetime/ DateHelper.php - Identifies the number of days in a month for a date.
- DateHelper::weekDaysAbbr1 in core/
lib/ Drupal/ Core/ Datetime/ DateHelper.php - Constructs a translated array of 1-letter week day abbreviations.
- DateTimePlus::arrayToISO in core/
lib/ Drupal/ Component/ Datetime/ DateTimePlus.php - Creates an ISO date from an array of values.
File
-
core/
includes/ bootstrap.inc, line 290
Code
function t($string, array $args = [], array $options = []) {
return new TranslatableMarkup($string, $args, $options);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.