class 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. This class is essentially a wrapper around the traditional t() function in drupal.

Hierarchy

Expanded class hierarchy of Translation

126 files declare their use of Translation
ArgumentDefaultTest.php in drupal/core/modules/views/tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/argument_default/ArgumentDefaultTest.php
Definition of Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest.
Attachment.php in drupal/core/modules/views/lib/Drupal/views/Plugin/views/display/Attachment.php
Definition of Drupal\views\Plugin\views\display\Attachment.
Banana.php in drupal/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/fruit/Banana.php
Contains \Drupal\plugin_test\Plugin\plugin_test\fruit\Banana.
Basic.php in drupal/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/Basic.php
Definition of Drupal\views\Plugin\views\exposed_form\Basic.
Block.php in drupal/core/modules/block/lib/Drupal/block/Plugin/views/display/Block.php
Definition of Drupal\views\Plugin\views\display\Block. Definition of Drupal\block\Plugin\views\display\Block.

... See full list

7 string references to 'Translation'
EntityTranslationController::entityFormAlter in drupal/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php
Implements EntityTranslationControllerInterface::entityFormAlter().
TranslationTest::getInfo in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
translation_entity_field_extra_fields in drupal/core/modules/translation_entity/translation_entity.module
Implements hook_field_extra_fields().
translation_entity_language_configuration_element_process in drupal/core/modules/translation_entity/translation_entity.module
Process callback: Expands the language_configuration form element.
translation_entity_overview in drupal/core/modules/translation_entity/translation_entity.pages.inc
Translations overview page callback.

... See full list

File

drupal/core/lib/Drupal/Core/Annotation/Translation.php, line 22
Definition of Drupal\Core\Annotation\Translation.

Namespace

Drupal\Core\Annotation
View source
class Translation implements AnnotationInterface {

  /**
   * The translation of the value passed to the constructor of the class.
   *
   * @var string
   */
  protected $translation;

  /**
   * Constructs a Translation object.
   *
   * Parses values passed into this class through the t() function in Drupal and
   * handles an optional context for the string.
   */
  public function __construct($values) {
    $string = $values['value'];
    $options = array();
    if (!empty($values['context'])) {
      $options = array(
        'context' => $values['context'],
      );
    }
    $this->translation = t($string, array(), $options);
  }

  /**
   * Implements Drupal\Core\Annotation\AnnotationInterface::get().
   */
  public function get() {
    return $this->translation;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Translation::$translation protected property The translation of the value passed to the constructor of the class.
Translation::get public function Implements Drupal\Core\Annotation\AnnotationInterface::get(). Overrides AnnotationInterface::get
Translation::__construct public function Constructs a Translation object.