function Translation::__construct
Same name in other branches
- 9 core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\Translation::__construct()
- 8.9.x core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\Translation::__construct()
- 10 core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\Translation::__construct()
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\AnnotationCode
public function __construct(array $values) {
$string = $values['value'];
$arguments = $values['arguments'] ?? [];
$options = [];
if (!empty($values['context'])) {
$options = [
'context' => $values['context'],
];
}
$this->translation = new TranslatableMarkup($string, $arguments, $options);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.