Same name and namespace in other branches
  1. 4.6.x includes/common.inc \t()
  2. 4.7.x includes/common.inc \t()
  3. 5.x includes/common.inc \t()
  4. 6.x includes/common.inc \t()
  5. 7.x includes/bootstrap.inc \t()
  6. 8.9.x core/includes/bootstrap.inc \t()
  7. 9 core/includes/bootstrap.inc \t()

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()

748 calls to t()
AccountPermissionsCacheContext::getLabel in core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php
Returns the label of the cache context.
ActionResourceTestBase::createEntity in core/modules/action/tests/src/Functional/Rest/ActionResourceTestBase.php
Creates the entity to be tested.
action_help in core/modules/action/action.module
Implements hook_help().
ajax_forms_test_validation_form_callback in core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
Ajax form callback: Selects the 'driver_text' element of the validation form.
ajax_forms_test_validation_number_form_callback in core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module
Ajax form callback: Selects the 'driver_number' element of the validation form.

... See full list

109 string references to 't'
BasicSyntaxTest::testGetFullQualifiedTableName in core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
Tests \Drupal\Core\Database\Connection::getFullQualifiedTableName().
BasicSyntaxTest::testLikeBackslash in core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
Tests a LIKE query containing a backslash.
BasicSyntaxTest::testLikeEscape in core/tests/Drupal/KernelTests/Core/Database/BasicSyntaxTest.php
Tests escaping of LIKE wildcards.
BulkDeleteTest::testDeleteField in core/modules/field/tests/src/Kernel/BulkDeleteTest.php
Tests deleting fields.
CommentType::query in core/modules/comment/src/Plugin/migrate/source/CommentType.php

... See full list

File

core/includes/bootstrap.inc, line 103
Functions that need to be loaded on every Drupal request.

Code

function t($string, array $args = [], array $options = []) {
  return new TranslatableMarkup($string, $args, $options);
}