1. 8.5.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  2. 8.0.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  3. 8.1.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  4. 8.2.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  5. 8.3.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  6. 8.4.x core/lib/Drupal/Core/Annotation/Translation.php Translation
  7. 8.6.x core/lib/Drupal/Core/Annotation/Translation.php Translation

Defines a translatable annotation object.

Some metadata within an annotation needs to be translatable. This class supports that need by allowing both the translatable string and, if specified, a context for that string. The string (with optional context) is passed into t().


Expanded class hierarchy of Translation

Related topics

1 file declares its use of Translation
TranslationTest.php in core/tests/Drupal/Tests/Core/Annotation/TranslationTest.php
6 string references to 'Translation'
ContentTranslationController::overview in core/modules/content_translation/src/Controller/ContentTranslationController.php
Builds the translations overview page.
ContentTranslationHandler::entityFormAlter in core/modules/content_translation/src/ContentTranslationHandler.php
Performs the needed alterations to the entity form.
content_translation_entity_extra_field_info in core/modules/content_translation/content_translation.module
Implements hook_entity_extra_field_info().
install_check_translations in core/includes/install.core.inc
Checks installation requirements and reports any errors.
tour.tour.locale.yml in core/modules/locale/config/optional/tour.tour.locale.yml

... See full list


core/lib/Drupal/Core/Annotation/Translation.php, line 53


View source
class Translation extends AnnotationBase {

   * The string translation object.
   * @var \Drupal\Core\StringTranslation\TranslatableMarkup
  protected $translation;

   * Constructs a new class instance.
   * Parses values passed into this class through the t() function in Drupal and
   * handles an optional context for the string.
   * @param array $values
   *   Possible array keys:
   *   - value (required): the string that is to be translated.
   *   - arguments (optional): an array with placeholder replacements, keyed by
   *     placeholder.
   *   - context (optional): a string that describes the context of "value";
  public function __construct(array $values) {
    $string = $values['value'];
    $arguments = isset($values['arguments']) ? $values['arguments'] : array();
    $options = array();
    if (!empty($values['context'])) {
      $options = array(
        'context' => $values['context'],
    $this->translation = new TranslatableMarkup($string, $arguments, $options);

   * {@inheritdoc}
  public function get() {
    return $this->translation;



Contains filters are case sensitive
Namesort descending Modifiers Type Description Overrides
AnnotationBase::$class protected property The class used for this annotated class.
AnnotationBase::$id public property The annotated class ID.
AnnotationBase::$provider protected property The provider of the annotated class.
AnnotationBase::getClass public function Gets the class of the annotated class. Overrides AnnotationInterface::getClass
AnnotationBase::getId public function Gets the unique ID for this annotated class. Overrides AnnotationInterface::getId
AnnotationBase::getProvider public function Gets the name of the provider of the annotated class. Overrides AnnotationInterface::getProvider
AnnotationBase::setClass public function Sets the class of the annotated class. Overrides AnnotationInterface::setClass
AnnotationBase::setProvider public function Sets the name of the provider of the annotated class. Overrides AnnotationInterface::setProvider
Translation::$translation protected property The string translation object.
Translation::get public function Gets the value of an annotation. Overrides AnnotationInterface::get
Translation::__construct public function Constructs a new class instance.