Annotation for translatable text
Same name in other branches
- 9 core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\plugin_translatable
- 8.9.x core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\plugin_translatable
- 11.x core/lib/Drupal/Core/Annotation/Translation.php \Drupal\Core\Annotation\plugin_translatable
Describes how to put translatable UI text into annotations.
When providing plugin annotation, properties whose values are displayed in the user interface should be made translatable. Much the same as how user interface text elsewhere is wrapped in t() to make it translatable, in plugin annotation, wrap translatable strings in the @ Translation() annotation. For example:
title = @ Translation("Title of the plugin"),
Remove spaces after @ in your actual plugin - these are put into this sample code so that it is not recognized as annotation.
To provide replacement values for placeholders, use the "arguments" array:
title = @ Translation("Bundle @title", arguments = {"@title" = "Foo"}),
It is also possible to provide a context with the text, similar to t():
title = @ Translation("Bundle", context = "Validation"),
Other t() arguments like language code are not valid to pass in. Only context is supported.
See also
File
-
core/
lib/ Drupal/ Core/ Annotation/ Translation.php, line 8
Classes
Title Sort descending | File name | Summary |
---|---|---|
PluralTranslation | core/ |
Defines an annotation object for strings that require plural forms. |
Translation | core/ |
Defines a translatable annotation object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.