diff --git a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php index 431ba8e..dcd1e59 100644 --- a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php +++ b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php @@ -8,7 +8,14 @@ namespace Drupal\Core\StringTranslation; /** - * Provides a t() method to use when translating strings in an object context. + * Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface. + * + * The supported way to work with injected translation in Drupal 8 so that the + * string extractor can find strings is by using a protected t() method wrapping + * \Drupal\Core\StringTranslation\TranslationInterface::translate(). This trait + * provides this method in a re-usable way. + * Procedural code should use t(). Any other way will result to untranslatable + * strings since the string extractor will not be able to find them. */ trait StringTranslationTrait { @@ -31,7 +38,7 @@ protected function t($string, array $args = array(), array $options = array()) { /** * Formats a string containing a count of items. * - * See the \Drupal\Core\StringTranslation::formatPlural() for details. + * See \Drupal\Core\StringTranslation::formatPlural() for details. */ protected function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { return $this->getStringTranslation()->formatPlural($count, $singular, $plural, $args, $options); @@ -47,10 +54,11 @@ protected function getStringTranslation() { if (!$this->stringTranslation) { $this->stringTranslation = \Drupal::service('string_translation'); } + return $this->stringTranslation; } - /** + /** * Sets the string translation service to use. * * @param \Drupal\Core\StringTranslation\TranslationInterface $translation