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

Related topics

276 files declare their use of Translation
Action.php in drupal/core/modules/system/lib/Drupal/system/Plugin/Core/Entity/Action.php
Contains \Drupal\system\Plugin\Core\Entity\Action.
ActiveTopicsBlock.php in drupal/core/modules/forum/lib/Drupal/forum/Plugin/Block/ActiveTopicsBlock.php
Contains \Drupal\forum\Plugin\Block\ActiveTopicsBlock.
AddRoleUser.php in drupal/core/modules/user/lib/Drupal/user/Plugin/Action/AddRoleUser.php
Contains \Drupal\user\Plugin\Action\AddRoleUser.
AggregatorCategoryBlock.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorCategoryBlock.php
Contains \Drupal\aggregator\Plugin\Block\AggregatorCategoryBlock.
AggregatorFeedBlock.php in drupal/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Block/AggregatorFeedBlock.php
Contains \Drupal\aggregator\Plugin\Block\AggregatorFeedBlock.

... See full list

8 string references to 'Translation'
EntityTranslationController::entityFormAlter in drupal/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php
Implements EntityTranslationControllerInterface::entityFormAlter().
install_check_translations in drupal/core/includes/install.core.inc
Checks installation requirements and reports any errors.
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.

... See full list

File

drupal/core/lib/Drupal/Core/Annotation/Translation.php, line 46
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.