You are here

function t in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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.

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

Related topics

2004 calls to t()
AccessDeniedTest::testAccessDenied in core/modules/system/src/Tests/System/AccessDeniedTest.php
AccessPermissionTest::testAccessPerm in core/modules/user/src/Tests/Views/AccessPermissionTest.php
Tests perm access plugin.
AccessRoleUITest::testAccessRoleUI in core/modules/user/src/Tests/Views/AccessRoleUITest.php
Tests the role access plugin UI.
AccountPermissionsCacheContext::getLabel in core/lib/Drupal/Core/Cache/Context/AccountPermissionsCacheContext.php
Returns the label of the cache context.
ActionListBuilder::buildHeader in core/modules/action/src/ActionListBuilder.php
Builds the header row for the entity listing.

... See full list

68 string references to 't'
CachingStreamTest::testReadsUntilCachedToByte in vendor/guzzlehttp/psr7/tests/CachingStreamTest.php
DatabaseTestController::pagerQueryEven in core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
Runs a pager query and returns the results.
DatabaseTestController::pagerQueryOdd in core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
Runs a pager query and returns the results.
DatabaseTestController::testTablesort in core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
Runs a tablesort query and returns the results.
DatabaseTestController::testTablesortFirst in core/modules/system/tests/modules/database_test/src/Controller/DatabaseTestController.php
Runs a tablesort query with a second order_by after and returns the results.

... See full list

File

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

Code

function t($string, array $args = array(), array $options = array()) {
  return \Drupal::translation()
    ->translate($string, $args, $options);
}