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

  • class \Drupal\Core\Annotation\Translation implements \Drupal\Component\Annotation\AnnotationInterface

Expanded class hierarchy of Translation

Related topics

1 string reference to 'Translation'
install_check_translations in drupal/core/includes/install.core.inc
Checks installation requirements and reports any errors.

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

Contains filters are case sensitive
Namesort descending Modifiers Type Description
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.