You are here

public function TranslationInterface::translate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/StringTranslation/TranslationInterface.php \Drupal\Core\StringTranslation\TranslationInterface::translate()

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

Never call this translate() method directly. 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.

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

2 methods override TranslationInterface::translate()
TestTranslationManager::translate in core/modules/user/tests/src/Unit/PermissionHandlerTest.php
Translates a string to the current language or to a given language.
TranslationManager::translate in core/lib/Drupal/Core/StringTranslation/TranslationManager.php
Translates a string to the current language or to a given language.

File

core/lib/Drupal/Core/StringTranslation/TranslationInterface.php, line 51
Contains \Drupal\Core\StringTranslation\TranslationInterface.

Class

TranslationInterface
Interface for the translation.manager translation service.

Namespace

Drupal\Core\StringTranslation

Code

public function translate($string, array $args = array(), array $options = array());