class Translation in Service Container 7.2
Same name and namespace in other branches
- 7 lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\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. The string (with optional context) is passed into t().
Hierarchy
- class \Drupal\Component\Annotation\AnnotationBase implements AnnotationInterface
- class \Drupal\Core\Annotation\Translation
Expanded class hierarchy of Translation
Related topics
File
- lib/
Drupal/ Core/ Annotation/ Translation.php, line 58 - Contains \Drupal\Core\Annotation\Translation.
Namespace
Drupal\Core\AnnotationView source
class Translation extends AnnotationBase {
/**
* The string translation object.
*
* @var \Drupal\Core\StringTranslation\TranslationWrapper
*/
protected $translation;
/**
* 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.
*
* @param 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";
*/
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 TranslationWrapper($string, $arguments, $options);
}
/**
* {@inheritdoc}
*/
public function get() {
return $this->translation;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnnotationBase:: |
protected | property | The class used for this annotated class. | |
AnnotationBase:: |
public | property | The annotated class ID. | |
AnnotationBase:: |
protected | property | The provider of the annotated class. | |
AnnotationBase:: |
public | function |
Gets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Gets the unique ID for this annotated class. Overrides AnnotationInterface:: |
1 |
AnnotationBase:: |
public | function |
Gets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the class of the annotated class. Overrides AnnotationInterface:: |
|
AnnotationBase:: |
public | function |
Sets the name of the provider of the annotated class. Overrides AnnotationInterface:: |
|
Translation:: |
protected | property | The string translation object. | |
Translation:: |
public | function |
Gets the value of an annotation. Overrides AnnotationInterface:: |
|
Translation:: |
public | function | Constructs a new class instance. |