W3cubDocs

/Drupal 8

public function Translation::__construct

public Translation::__construct(array $values)

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.

Parameters

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";

File

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

Class

Translation
Defines a translatable annotation object.

Namespace

Drupal\Core\Annotation

Code

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);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Annotation!Translation.php/function/Translation::__construct/8.1.x