Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Using this trait will add t() and formatPlural() methods to the class. These must be used for every translatable string, similar to how procedural code must use the global functions t() and \Drupal::translation()->formatPlural(). This allows string extractor tools to find translatable strings.
If the class is capable of injecting services from the container, it should inject the 'string_translation' service and assign it to $this->stringTranslation.
Hierarchy
- trait \Drupal\Core\StringTranslation\StringTranslationTrait
See also
\Drupal\Core\StringTranslation\TranslationInterface
Services and Dependency Injection Container
Related topics
- Internationalization
- Internationalization and translation
File
- core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php, line 22
Namespace
Drupal\Core\StringTranslation
Members
Name | Modifiers | Type | Description |
---|---|---|---|
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. |
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. |
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. |
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Please login to continue.