diff --git a/core/core.services.yml b/core/core.services.yml index 025368e..d053481 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -451,7 +451,7 @@ services: - { name: event_subscriber } controller.page: class: Drupal\Core\Controller\HtmlPageController - arguments: ['@controller_resolver', '@string_translation', '@title_resolver'] + arguments: ['@controller_resolver', '@title_resolver'] controller.ajax: class: Drupal\Core\Controller\AjaxController arguments: ['@controller_resolver', '@ajax_response_renderer'] @@ -579,7 +579,7 @@ services: arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot'] exception_controller: class: Drupal\Core\Controller\ExceptionController - arguments: ['@content_negotiation', '@string_translation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer'] + arguments: ['@content_negotiation', '@title_resolver', '@html_page_renderer', '@html_fragment_renderer'] calls: - [setContainer, ['@service_container']] exception_listener: diff --git a/core/lib/Drupal/Core/Annotation/Translation.php b/core/lib/Drupal/Core/Annotation/Translation.php index 5726878..ad32b5e 100644 --- a/core/lib/Drupal/Core/Annotation/Translation.php +++ b/core/lib/Drupal/Core/Annotation/Translation.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Annotation; use Drupal\Component\Annotation\AnnotationBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * @defgroup plugin_translatable Translatable plugin metadata @@ -51,6 +52,7 @@ * @ingroup plugin_translatable */ class Translation extends AnnotationBase { + use StringTranslationTrait; /** * The translation of the value passed to the constructor of the class. @@ -60,13 +62,6 @@ class Translation extends AnnotationBase { protected $translation; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a new class instance. * * Parses values passed into this class through the t() function in Drupal and @@ -88,7 +83,7 @@ public function __construct(array $values) { 'context' => $values['context'], ); } - $this->translation = $this->getTranslationManager()->translate($string, $arguments, $options); + $this->translation = $this->t($string, $arguments, $options); } /** @@ -98,18 +93,4 @@ public function get() { return $this->translation; } - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function getTranslationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::translation(); - } - - return $this->translationManager; - } - } diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php index 63fe199..a88944a 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbBuilderBase.php @@ -7,12 +7,15 @@ namespace Drupal\Core\Breadcrumb; +use Drupal\Core\StringTranslation\StringTranslationTrait; + /** * Defines a common base class for breadcrumb builders adding a link generator. * * @todo Use traits once we have a PHP 5.4 requirement. */ abstract class BreadcrumbBuilderBase implements BreadcrumbBuilderInterface { + use StringTranslationTrait; /** * The link generator. @@ -22,13 +25,6 @@ protected $linkGenerator; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Returns the service container. * * @return \Symfony\Component\DependencyInjection\ContainerInterface $container @@ -64,26 +60,4 @@ protected function linkGenerator() { return $this->linkGenerator; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - } diff --git a/core/lib/Drupal/Core/Config/ConfigImportValidateEventSubscriberBase.php b/core/lib/Drupal/Core/Config/ConfigImportValidateEventSubscriberBase.php index dfda0aa..ee5340c 100644 --- a/core/lib/Drupal/Core/Config/ConfigImportValidateEventSubscriberBase.php +++ b/core/lib/Drupal/Core/Config/ConfigImportValidateEventSubscriberBase.php @@ -7,13 +7,14 @@ namespace Drupal\Core\Config; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Defines a base event listener implementation for config sync validation. */ abstract class ConfigImportValidateEventSubscriberBase implements EventSubscriberInterface { + use StringTranslationTrait; /** * Checks that the configuration synchronization is valid. @@ -31,27 +32,4 @@ static function getSubscribedEvents() { return $events; } - /** - * Translates a string to the current language or to a given language. - * - * @param string $string - * A string containing the English string to translate. - * @param array $args - * An associative array of replacements to make after translation. Based - * on the first character of the key, the value is escaped and/or themed. - * See \Drupal\Component\Utility\String::format() for details. - * @param array $options - * An associative array of additional options, with the following elements: - * - 'langcode': The language code to translate to a language other than - * what is used to display the page. - * - 'context': The context the source string belongs to. - * - * @return string - * The translated string. - * - * @see \Drupal\Core\StringTranslation\TranslationInterface::translate() - */ - protected function t($string, array $args = array(), array $options = array()) { - return \Drupal::translation()->translate($string, $args, $options); - } } diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index e81b29b..c11b395 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -15,7 +15,8 @@ use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Lock\LockBackendInterface; -use Drupal\Core\StringTranslation\TranslationManager; +use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -38,6 +39,7 @@ * @see \Drupal\Core\Config\ConfigImporterEvent */ class ConfigImporter extends DependencySerialization { + use StringTranslationTrait; /** * The name used to identify the lock. @@ -122,13 +124,6 @@ class ConfigImporter extends DependencySerialization { protected $themeHandler; /** - * The string translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationManager - */ - protected $translationManager; - - /** * Flag set to import system.theme during processing theme enable and disables. * * @var bool @@ -178,10 +173,10 @@ class ConfigImporter extends DependencySerialization { * The module handler * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler - * @param \Drupal\Core\StringTranslation\TranslationManager $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. */ - public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, TranslationManager $translation_manager) { + public function __construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation) { $this->storageComparer = $storage_comparer; $this->eventDispatcher = $event_dispatcher; $this->configManager = $config_manager; @@ -189,7 +184,7 @@ public function __construct(StorageComparerInterface $storage_comparer, EventDis $this->typedConfigManager = $typed_config; $this->moduleHandler = $module_handler; $this->themeHandler = $theme_handler; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; $this->processedConfiguration = $this->storageComparer->getEmptyChangelist(); $this->processedExtensions = $this->getEmptyExtensionsProcessedList(); } @@ -835,7 +830,7 @@ protected function checkOp($op, $name) { $entity_type = $this->configManager->getEntityManager()->getDefinition($entity_type_id); $entity = $entity_storage->load($entity_storage->getIDFromConfigName($name, $entity_type->getConfigPrefix())); $entity->delete(); - $this->logError($this->translationManager->translate('Deleted and replaced configuration entity "@name"', array('@name' => $name))); + $this->logError($this->t('Deleted and replaced configuration entity "@name"', array('@name' => $name))); } else { $this->storageComparer->getTargetStorage()->delete($name); @@ -1008,31 +1003,7 @@ protected function reInjectMe() { $this->typedConfigManager = \Drupal::service('config.typed'); $this->moduleHandler = \Drupal::moduleHandler(); $this->themeHandler = \Drupal::service('theme_handler'); - $this->translationManager = \Drupal::service('string_translation'); - } - - /** - * Translates a string to the current language or to a given language. - * - * @param string $string - * A string containing the English string to translate. - * @param array $args - * An associative array of replacements to make after translation. Based - * on the first character of the key, the value is escaped and/or themed. - * See \Drupal\Component\Utility\String::format() for details. - * @param array $options - * An associative array of additional options, with the following elements: - * - 'langcode': The language code to translate to a language other than - * what is used to display the page. - * - 'context': The context the source string belongs to. - * - * @return string - * The translated string. - * - * @see \Drupal\Core\StringTranslation\TranslationManager::translate() - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); + $this->stringTranslation = \Drupal::service('string_translation'); } } diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php index 3af41f5..286c134 100644 --- a/core/lib/Drupal/Core/Controller/ControllerBase.php +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Controller; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -31,6 +32,7 @@ * @see \Drupal\Core\DependencyInjection\ContainerInjectionInterface */ abstract class ControllerBase implements ContainerInjectionInterface { + use StringTranslationTrait; /** * The entity manager. @@ -54,13 +56,6 @@ protected $languageManager; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The configuration factory. * * @var \Drupal\Core\Config\Config @@ -276,28 +271,6 @@ protected function currentUser() { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - - /** * Returns the language manager service. * * @return \Drupal\Core\Language\LanguageManager diff --git a/core/lib/Drupal/Core/Controller/ExceptionController.php b/core/lib/Drupal/Core/Controller/ExceptionController.php index 12e9cbe..4333ffe 100644 --- a/core/lib/Drupal/Core/Controller/ExceptionController.php +++ b/core/lib/Drupal/Core/Controller/ExceptionController.php @@ -9,7 +9,6 @@ use Drupal\Core\Page\DefaultHtmlPageRenderer; use Drupal\Core\Page\HtmlPageRendererInterface; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -60,8 +59,6 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn * @param \Drupal\Core\ContentNegotiation $negotiation * The content negotiation library to use to determine the correct response * format. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. * @param \Drupal\Core\Page\HtmlPageRendererInterface $renderer @@ -69,8 +66,8 @@ class ExceptionController extends HtmlControllerBase implements ContainerAwareIn * @param \Drupal\Core\Page\HtmlFragmentRendererInterface $fragment_renderer * The fragment rendering service. */ - public function __construct(ContentNegotiation $negotiation, TranslationInterface $translation_manager, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer) { - parent::__construct($translation_manager, $title_resolver); + public function __construct(ContentNegotiation $negotiation, TitleResolverInterface $title_resolver, HtmlPageRendererInterface $renderer, $fragment_renderer) { + parent::__construct($title_resolver); $this->negotiation = $negotiation; $this->htmlPageRenderer = $renderer; $this->fragmentRenderer = $fragment_renderer; diff --git a/core/lib/Drupal/Core/Controller/HtmlControllerBase.php b/core/lib/Drupal/Core/Controller/HtmlControllerBase.php index 6b81e7e..5795a48 100644 --- a/core/lib/Drupal/Core/Controller/HtmlControllerBase.php +++ b/core/lib/Drupal/Core/Controller/HtmlControllerBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Controller; -use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\Page\HtmlFragment; use Drupal\Core\Utility\Title; use Symfony\Cmf\Component\Routing\RouteObjectInterface; @@ -20,13 +19,6 @@ class HtmlControllerBase { /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The title resolver. * * @var \Drupal\Core\Controller\TitleResolver @@ -36,13 +28,10 @@ class HtmlControllerBase { /** * Constructs a new HtmlControllerBase object. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. */ - public function __construct(TranslationInterface $translation_manager, TitleResolverInterface $title_resolver) { - $this->translationManager = $translation_manager; + public function __construct(TitleResolverInterface $title_resolver) { $this->titleResolver = $title_resolver; } diff --git a/core/lib/Drupal/Core/Controller/HtmlPageController.php b/core/lib/Drupal/Core/Controller/HtmlPageController.php index 1672939..6ed82f1 100644 --- a/core/lib/Drupal/Core/Controller/HtmlPageController.php +++ b/core/lib/Drupal/Core/Controller/HtmlPageController.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Controller; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -27,13 +26,11 @@ class HtmlPageController extends HtmlControllerBase { * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver * The controller resolver. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. * @param \Drupal\Core\Controller\TitleResolverInterface $title_resolver * The title resolver. */ - public function __construct(ControllerResolverInterface $controller_resolver, TranslationInterface $translation_manager, TitleResolverInterface $title_resolver) { - parent::__construct($translation_manager, $title_resolver); + public function __construct(ControllerResolverInterface $controller_resolver, TitleResolverInterface $title_resolver) { + parent::__construct($title_resolver); $this->controllerResolver = $controller_resolver; } diff --git a/core/lib/Drupal/Core/Controller/TitleResolver.php b/core/lib/Drupal/Core/Controller/TitleResolver.php index 5a1ca50..4fe90a6 100644 --- a/core/lib/Drupal/Core/Controller/TitleResolver.php +++ b/core/lib/Drupal/Core/Controller/TitleResolver.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Controller; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; @@ -15,6 +16,7 @@ * Provides the default implementation of the title resolver interface. */ class TitleResolver implements TitleResolverInterface { + use StringTranslationTrait; /** * The controller resolver. @@ -24,23 +26,16 @@ class TitleResolver implements TitleResolverInterface { protected $controllerResolver; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a TitleResolver instance. * * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver * The controller resolver. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. */ - public function __construct(ControllerResolverInterface $controller_resolver, TranslationInterface $translation_manager) { + public function __construct(ControllerResolverInterface $controller_resolver, TranslationInterface $string_translation) { $this->controllerResolver = $controller_resolver; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; } /** @@ -74,7 +69,7 @@ public function getTitle(Request $request, Route $route) { } // Fall back to a static string from the route. - $route_title = $this->translationManager->translate($title, $args, $options); + $route_title = $this->t($title, $args, $options); } return $route_title; } diff --git a/core/lib/Drupal/Core/Datetime/Date.php b/core/lib/Drupal/Core/Datetime/Date.php index 898a49e..2dd512a 100644 --- a/core/lib/Drupal/Core/Datetime/Date.php +++ b/core/lib/Drupal/Core/Datetime/Date.php @@ -14,11 +14,13 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Provides a service to handler various date related functionality. */ class Date { + use StringTranslationTrait; /** * The list of loaded timezones. @@ -181,7 +183,7 @@ public function formatInterval($interval, $granularity = 2, $langcode = NULL) { foreach ($this->units as $key => $value) { $key = explode('|', $key); if ($interval >= $value) { - $output .= ($output ? ' ' : '') . $this->stringTranslation->formatPlural(floor($interval / $value), $key[0], $key[1], array(), array('langcode' => $langcode)); + $output .= ($output ? ' ' : '') . $this->formatPlural(floor($interval / $value), $key[0], $key[1], array(), array('langcode' => $langcode)); $interval %= $value; $granularity--; } @@ -194,15 +196,6 @@ public function formatInterval($interval, $granularity = 2, $langcode = NULL) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->stringTranslation->translate($string, $args, $options); - } - - /** * Loads the given format pattern for the given langcode. * * @param string $format diff --git a/core/lib/Drupal/Core/Entity/EntityControllerBase.php b/core/lib/Drupal/Core/Entity/EntityControllerBase.php index 7b60766..cbaf670 100644 --- a/core/lib/Drupal/Core/Entity/EntityControllerBase.php +++ b/core/lib/Drupal/Core/Entity/EntityControllerBase.php @@ -9,6 +9,7 @@ use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; /** @@ -17,13 +18,7 @@ * @todo Convert this to a trait. */ abstract class EntityControllerBase extends DependencySerialization { - - /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; + use StringTranslationTrait; /** * The module handler to invoke hooks on. @@ -33,32 +28,6 @@ protected $moduleHandler; /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::translation(); - } - return $this->translationManager; - } - - /** - * Sets the translation manager for this controller. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return $this - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - - /** * Returns the module handler. * * @return \Drupal\Core\Extension\ModuleHandlerInterface diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php index 5e0881d..2a008f2 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerInterface.php @@ -129,14 +129,14 @@ public function validate(array $form, array &$form_state); public function submit(array $form, array &$form_state); /** - * Sets the translation manager for this form. + * Sets the string translation service for this form. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. * * @return $this */ - public function setTranslationManager(TranslationInterface $translation_manager); + public function setStringTranslation(TranslationInterface $string_translation); /** * Sets the module handler for this form. diff --git a/core/lib/Drupal/Core/Entity/EntityListBuilder.php b/core/lib/Drupal/Core/Entity/EntityListBuilder.php index b7b1347..ca5025c 100644 --- a/core/lib/Drupal/Core/Entity/EntityListBuilder.php +++ b/core/lib/Drupal/Core/Entity/EntityListBuilder.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Entity; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Component\Utility\String; @@ -202,15 +201,6 @@ public function render() { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** * Returns the title of the page. * * @return string diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 679f849..6b0fac2 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -230,7 +230,7 @@ public function getFormController($entity_type, $operation) { } $controller - ->setTranslationManager($this->translationManager) + ->setStringTranslation($this->translationManager) ->setModuleHandler($this->moduleHandler) ->setOperation($operation); $this->controllers['form'][$operation][$entity_type] = $controller; @@ -288,8 +288,8 @@ public function getController($entity_type, $controller_type, $controller_class_ if (method_exists($controller, 'setModuleHandler')) { $controller->setModuleHandler($this->moduleHandler); } - if (method_exists($controller, 'setTranslationManager')) { - $controller->setTranslationManager($this->translationManager); + if (method_exists($controller, 'setStringTranslation')) { + $controller->setStringTranslation($this->translationManager); } $this->controllers[$controller_type][$entity_type] = $controller; } diff --git a/core/lib/Drupal/Core/Form/FormBase.php b/core/lib/Drupal/Core/Form/FormBase.php index 93abb5b..5311836 100644 --- a/core/lib/Drupal/Core/Form/FormBase.php +++ b/core/lib/Drupal/Core/Form/FormBase.php @@ -11,7 +11,7 @@ use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\DependencyInjection\DependencySerialization; use Drupal\Core\Routing\UrlGeneratorInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -19,13 +19,7 @@ * Provides a base class for forms. */ abstract class FormBase extends DependencySerialization implements FormInterface, ContainerInjectionInterface { - - /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; + use StringTranslationTrait; /** * The current request. @@ -70,15 +64,6 @@ public function validateForm(array &$form, array &$form_state) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** * Generates a URL or path for a specific route based on the given parameters. * * @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute() for @@ -92,19 +77,6 @@ public function url($route_name, $route_parameters = array(), $options = array() } /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = $this->container()->get('string_translation'); - } - return $this->translationManager; - } - - /** * Retrieves a configuration object. * * This is the main entry point to the configuration API. Calling @@ -128,19 +100,6 @@ protected function config($name) { } /** - * Sets the translation manager for this form. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return $this - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - - /** * Sets the config factory for this form. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 9353a76..b9c6ec7 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -19,6 +19,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -32,6 +33,7 @@ * Provides form building and processing. */ class FormBuilder implements FormBuilderInterface { + use StringTranslationTrait; /** * The module handler. @@ -62,13 +64,6 @@ class FormBuilder implements FormBuilderInterface { protected $urlGenerator; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The current request. * * @var \Symfony\Component\HttpFoundation\Request @@ -130,19 +125,19 @@ class FormBuilder implements FormBuilderInterface { * The event dispatcher. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The URL generator. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. * @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token * The CSRF token generator. * @param \Drupal\Core\HttpKernel $http_kernel * The HTTP kernel. */ - public function __construct(ModuleHandlerInterface $module_handler, KeyValueExpirableFactoryInterface $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $translation_manager, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) { + public function __construct(ModuleHandlerInterface $module_handler, KeyValueExpirableFactoryInterface $key_value_expirable_factory, EventDispatcherInterface $event_dispatcher, UrlGeneratorInterface $url_generator, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token = NULL, HttpKernel $http_kernel = NULL) { $this->moduleHandler = $module_handler; $this->keyValueExpirableFactory = $key_value_expirable_factory; $this->eventDispatcher = $event_dispatcher; $this->urlGenerator = $url_generator; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; $this->csrfToken = $csrf_token; $this->httpKernel = $http_kernel; } @@ -1808,15 +1803,6 @@ protected function currentUser() { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - - /** * {@inheritdoc} */ public function setRequest(Request $request) { diff --git a/core/lib/Drupal/Core/Installer/Exception/InstallerException.php b/core/lib/Drupal/Core/Installer/Exception/InstallerException.php index e8c1ec3..b9b3bcf 100644 --- a/core/lib/Drupal/Core/Installer/Exception/InstallerException.php +++ b/core/lib/Drupal/Core/Installer/Exception/InstallerException.php @@ -7,10 +7,13 @@ namespace Drupal\Core\Installer\Exception; +use Drupal\Core\StringTranslation\StringTranslationTrait; + /** * Base class for exceptions thrown by installer. */ class InstallerException extends \RuntimeException { + use StringTranslationTrait; /** * The page title to output. @@ -20,13 +23,6 @@ class InstallerException extends \RuntimeException { protected $title; /** - * The string translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $stringTranslation; - - /** * Constructs a new installer exception. * * @param string $title @@ -52,13 +48,4 @@ public function getTitle() { return $this->title; } - /** - * Translates a string using StringTranslation. - * - * @see \Drupal\Core\StringTranslation\TranslationInterface::translate() - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->stringTranslation->translate($string, $args, $options); - } - } diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index fa036a2..19f5825 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -11,7 +11,7 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Core\Plugin\Context\Context; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Drupal specific class for plugins that use context. @@ -21,6 +21,7 @@ * ContextAwarePluginBase but it is using a different Context class. */ abstract class ContextAwarePluginBase extends ComponentContextAwarePluginBase { + use StringTranslationTrait; /** * Override of \Drupal\Component\Plugin\ContextAwarePluginBase::__construct(). @@ -55,47 +56,4 @@ public function setContextValue($name, $value) { return $this; } - /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::translation(); - } - return $this->translationManager; - } - - /** - * Sets the translation manager for this plugin. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return self - * The plugin object. - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - } diff --git a/core/lib/Drupal/Core/Plugin/PluginBase.php b/core/lib/Drupal/Core/Plugin/PluginBase.php index f0bce24..931062d 100644 --- a/core/lib/Drupal/Core/Plugin/PluginBase.php +++ b/core/lib/Drupal/Core/Plugin/PluginBase.php @@ -8,13 +8,14 @@ namespace Drupal\Core\Plugin; use Drupal\Component\Plugin\PluginBase as ComponentPluginBase; -use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for plugins supporting metadata inspection and translation. */ abstract class PluginBase extends ComponentPluginBase { + use StringTranslationTrait; /** * An array of service IDs keyed by property name used for serialization. @@ -27,49 +28,6 @@ protected $_serviceIds = array(); /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::getContainer()->get('string_translation'); - } - return $this->translationManager; - } - - /** - * Sets the translation manager for this plugin. - * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager - * The translation manager. - * - * @return self - * The plugin object. - */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; - return $this; - } - - /** * {@inheritdoc} * * @todo Remove when Drupal\Core\DependencyInjection\DependencySerialization diff --git a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php new file mode 100644 index 0000000..01e3ec6 --- /dev/null +++ b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php @@ -0,0 +1,78 @@ +getStringTranslation()->translate($string, $args, $options); + } + + /** + * Formats a string containing a count of items. + * + * See the \Drupal\Core\StringTranslation\TranslationInterface::formatPlural() + * documentation for details. + */ + protected function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { + return $this->getStringTranslation()->formatPlural($count, $singular, $plural, $args, $options); + } + + /** + * Gets the string translation service. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The string translation service. + */ + 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 + * The string translation service. + * + * @return $this + */ + public function setStringTranslation(TranslationInterface $translation) { + $this->stringTranslation = $translation; + + return $this; + } + +} diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php index 29376bc..ea77c2b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php @@ -56,12 +56,12 @@ class SettingsForm extends ConfigFormBase { * The aggregator parser plugin manager. * @param \Drupal\aggregator\Plugin\AggregatorPluginManager $processor_manager * The aggregator processor plugin manager. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation manager. */ - public function __construct(ConfigFactoryInterface $config_factory, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $translation_manager) { + public function __construct(ConfigFactoryInterface $config_factory, AggregatorPluginManager $fetcher_manager, AggregatorPluginManager $parser_manager, AggregatorPluginManager $processor_manager, TranslationInterface $string_translation) { parent::__construct($config_factory); - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; $this->managers = array( 'fetcher' => $fetcher_manager, 'parser' => $parser_manager, diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index 482ac75..bb76ec2 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -12,6 +12,7 @@ use Drupal\Core\Language\LanguageManager; use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Manages discovery and instantiation of block plugins. @@ -21,6 +22,7 @@ * @see \Drupal\block\BlockPluginInterface */ class BlockManager extends DefaultPluginManager { + use StringTranslationTrait; /** * An array of all available modules and their data. @@ -30,13 +32,6 @@ class BlockManager extends DefaultPluginManager { protected $moduleData; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs a new \Drupal\block\Plugin\Type\BlockManager object. * * @param \Traversable $namespaces @@ -48,15 +43,15 @@ class BlockManager extends DefaultPluginManager { * The language manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler, TranslationInterface $string_translation) { parent::__construct('Plugin/Block', $namespaces, $module_handler, 'Drupal\block\Annotation\Block'); $this->alterInfo('block'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; } /** @@ -95,15 +90,6 @@ protected function getModuleName($module) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - - /** * Gets the names of all block categories. * * @return array diff --git a/core/modules/book/lib/Drupal/book/BookManager.php b/core/modules/book/lib/Drupal/book/BookManager.php index 3e0a6aa..c491cf4 100644 --- a/core/modules/book/lib/Drupal/book/BookManager.php +++ b/core/modules/book/lib/Drupal/book/BookManager.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\node\NodeInterface; @@ -20,6 +21,7 @@ * Defines a book manager. */ class BookManager implements BookManagerInterface { + use StringTranslationTrait; /** * Defines the maximum supported depth of the book tree. @@ -41,13 +43,6 @@ class BookManager implements BookManagerInterface { protected $entityManager; /** - * The translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translation; - - /** * Config Factory Service Object. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -74,7 +69,7 @@ class BookManager implements BookManagerInterface { public function __construct(Connection $connection, EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory) { $this->connection = $connection; $this->entityManager = $entity_manager; - $this->translation = $translation; + $this->stringTranslation = $translation; $this->configFactory = $config_factory; } @@ -324,15 +319,6 @@ public function getBookParents(array $item, array $parent = array()) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translation->translate($string, $args, $options); - } - - /** * Builds the parent selection form element for the node form or outline tab. * * This function is also called when generating a new set of options during the diff --git a/core/modules/comment/lib/Drupal/comment/CommentManager.php b/core/modules/comment/lib/Drupal/comment/CommentManager.php index c522fd3..d56efe8 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentManager.php +++ b/core/modules/comment/lib/Drupal/comment/CommentManager.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\field\FieldInfo; @@ -21,6 +22,7 @@ * Comment manager contains common functions to manage comment fields. */ class CommentManager implements CommentManagerInterface { + use StringTranslationTrait; /** * The field info service. @@ -58,13 +60,6 @@ class CommentManager implements CommentManagerInterface { protected $userConfig; /** - * The string translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The url generator service. * * @var \Drupal\Core\Routing\UrlGeneratorInterface @@ -82,17 +77,17 @@ class CommentManager implements CommentManagerInterface { * The current user. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation service. * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator * The url generator service. */ - public function __construct(FieldInfo $field_info, EntityManagerInterface $entity_manager, AccountInterface $current_user, ConfigFactoryInterface $config_factory, TranslationInterface $translation_manager, UrlGeneratorInterface $url_generator) { + public function __construct(FieldInfo $field_info, EntityManagerInterface $entity_manager, AccountInterface $current_user, ConfigFactoryInterface $config_factory, TranslationInterface $string_translation, UrlGeneratorInterface $url_generator) { $this->fieldInfo = $field_info; $this->entityManager = $entity_manager; $this->currentUser = $current_user; $this->userConfig = $config_factory->get('user.settings'); - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; $this->urlGenerator = $url_generator; } @@ -315,13 +310,4 @@ public function forbiddenMessage(EntityInterface $entity, $field_name) { return ''; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php index 19f417f..a9eaac7 100644 --- a/core/modules/config/lib/Drupal/config/Form/ConfigSync.php +++ b/core/modules/config/lib/Drupal/config/Form/ConfigSync.php @@ -264,7 +264,7 @@ public function submitForm(array &$form, array &$form_state) { $this->typedConfigManager, $this->moduleHandler, $this->themeHandler, - $this->translationManager() + $this->getStringTranslation() ); if ($config_importer->alreadyImporting()) { drupal_set_message($this->t('Another request may be synchronizing configuration already.')); diff --git a/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php b/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php index 9dc32bb..c2e8fb0 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/ConfigNamesMapper.php @@ -81,14 +81,14 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con * The mapper plugin discovery service. * @param \Drupal\Core\Routing\RouteProviderInterface * The route provider. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation manager. * * @throws \Symfony\Component\Routing\Exception\RouteNotFoundException * Throws an exception if the route specified by the 'base_route_name' in * the plugin definition could not be found by the route provider. */ - public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager) { + public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation) { $this->pluginId = $plugin_id; $this->pluginDefinition = $plugin_definition; @@ -96,7 +96,7 @@ public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterfa $this->localeConfigManager = $locale_config_manager; $this->configMapperManager = $config_mapper_manager; - $this->setTranslationManager($translation_manager); + $this->stringTranslation = $string_translation; $this->baseRoute = $route_provider->getRouteByName($this->getBaseRouteName()); } diff --git a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php index 3cc9867..3abb57e 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/DateFormat.php @@ -11,11 +11,13 @@ use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\ReplaceCommand; use Drupal\Core\Language\Language; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Defines the date format element for the configuration translation interface. */ -class DateFormat extends Element { +class DateFormat implements ElementInterface { + use StringTranslationTrait; /** * {@inheritdoc} diff --git a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Element.php b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Element.php deleted file mode 100644 index 40a43c2..0000000 --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Element.php +++ /dev/null @@ -1,44 +0,0 @@ -translationManager()->translate($string, $args, $options); - } - - /** - * Returns the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::translation(); - } - return $this->translationManager; - } - -} diff --git a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php index e79107e..b796685 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textarea.php @@ -8,11 +8,13 @@ namespace Drupal\config_translation\FormElement; use Drupal\Core\Language\Language; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Defines the textarea element for the configuration translation interface. */ -class Textarea extends Element { +class Textarea implements ElementInterface { + use StringTranslationTrait; /** * {@inheritdoc} diff --git a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php index 1791961..46d71fe 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/FormElement/Textfield.php @@ -8,11 +8,13 @@ namespace Drupal\config_translation\FormElement; use Drupal\Core\Language\Language; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Defines the textfield element for the configuration translation interface. */ -class Textfield extends Element { +class Textfield implements ElementInterface { + use StringTranslationTrait; /** * {@inheritdoc} diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php b/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php index f7fd862..37e546d 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Plugin/Derivative/FieldUiLocalTask.php @@ -11,6 +11,7 @@ use Drupal\Component\Plugin\Derivative\DerivativeBase; use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface; use Drupal\Core\Routing\RouteProviderInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -18,6 +19,7 @@ * Provides local task definitions for all entity bundles. */ class FieldUiLocalTask extends DerivativeBase implements ContainerDerivativeInterface { + use StringTranslationTrait; /** * The route provider. @@ -34,26 +36,19 @@ class FieldUiLocalTask extends DerivativeBase implements ContainerDerivativeInte protected $entityManager; /** - * The translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Creates an FieldUiLocalTask object. * * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. */ - public function __construct(RouteProviderInterface $route_provider, EntityManagerInterface $entity_manager, TranslationInterface $translation_manager) { + public function __construct(RouteProviderInterface $route_provider, EntityManagerInterface $entity_manager, TranslationInterface $string_translation) { $this->routeProvider = $route_provider; $this->entityManager = $entity_manager; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; } /** @@ -196,13 +191,4 @@ public function alterLocalTasks(&$local_tasks) { } } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/modules/forum/lib/Drupal/forum/ForumManager.php b/core/modules/forum/lib/Drupal/forum/ForumManager.php index 388dd4a..ea601b7 100644 --- a/core/modules/forum/lib/Drupal/forum/ForumManager.php +++ b/core/modules/forum/lib/Drupal/forum/ForumManager.php @@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\comment\CommentInterface; use Drupal\field\FieldInfo; use Drupal\node\NodeInterface; @@ -21,6 +22,7 @@ * Provides forum manager service. */ class ForumManager extends DependencySerialization implements ForumManagerInterface { + use StringTranslationTrait; /** * Forum sort order, newest first. @@ -106,13 +108,6 @@ class ForumManager extends DependencySerialization implements ForumManagerInterf protected $fieldInfo; /** - * Translation manager service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * Constructs the forum manager service. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -123,15 +118,15 @@ class ForumManager extends DependencySerialization implements ForumManagerInterf * The current database connection. * @param \Drupal\field\FieldInfo $field_info * The field info service. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager service. */ - public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, Connection $connection, FieldInfo $field_info, TranslationInterface $translation_manager) { + public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, Connection $connection, FieldInfo $field_info, TranslationInterface $string_translation) { $this->configFactory = $config_factory; $this->entityManager = $entity_manager; $this->connection = $connection; $this->fieldInfo = $field_info; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; } /** @@ -551,15 +546,6 @@ public function updateIndex($nid) { } /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - - /** * {@inheritdoc} */ public function __sleep() { diff --git a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php index 22d3618..8b71d69 100644 --- a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php +++ b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumBreadcrumbBuilderBaseTest.php @@ -131,7 +131,7 @@ public function testBuild() { // Add a translation manager for t(). $translation_manager = $this->getStringTranslationStub(); - $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'translationManager'); + $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'stringTranslation'); $property->setAccessible(TRUE); $property->setValue($breadcrumb_builder, $translation_manager); diff --git a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumListingBreadcrumbBuilderTest.php b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumListingBreadcrumbBuilderTest.php index 2aa2804..7a58343 100644 --- a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumListingBreadcrumbBuilderTest.php +++ b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumListingBreadcrumbBuilderTest.php @@ -187,7 +187,7 @@ public function testBuild() { // Add a translation manager for t(). $translation_manager = $this->getStringTranslationStub(); - $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'translationManager'); + $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'stringTranslation'); $property->setAccessible(TRUE); $property->setValue($breadcrumb_builder, $translation_manager); diff --git a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php index 4a12d0d..d1019f5 100644 --- a/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php +++ b/core/modules/forum/tests/Drupal/forum/Tests/Breadcrumb/ForumNodeBreadcrumbBuilderTest.php @@ -195,7 +195,7 @@ public function testBuild() { // Add a translation manager for t(). $translation_manager = $this->getStringTranslationStub(); - $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'translationManager'); + $property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'stringTranslation'); $property->setAccessible(TRUE); $property->setValue($breadcrumb_builder, $translation_manager); diff --git a/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php index dcb84d2..5b9d8bb 100644 --- a/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php +++ b/core/modules/migrate/lib/Drupal/migrate/MigrateExecutable.php @@ -8,6 +8,7 @@ namespace Drupal\migrate; use Drupal\Core\Utility\Error; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -15,6 +16,7 @@ * Defines a migrate executable class. */ class MigrateExecutable { + use StringTranslationTrait; /** * The configuration of the migration to do. @@ -127,13 +129,6 @@ class MigrateExecutable { protected $memoryLimit; /** - * The translation manager. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * The rollback action to be saved for the current row. * * @var int @@ -645,26 +640,4 @@ public function handleException(\Exception $exception, $save = TRUE) { $this->message->display($message, 'error'); } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager()->translate($string, $args, $options); - } - - /** - * Gets the translation manager. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The translation manager. - */ - protected function translationManager() { - if (!$this->translationManager) { - $this->translationManager = \Drupal::translation(); - } - return $this->translationManager; - } - } diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php index e837e09..fd0da23 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecutableTest.php @@ -67,7 +67,7 @@ protected function setUp() { $this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message); - $this->executable->setTranslationManager($this->getStringTranslationStub()); + $this->executable->setStringTranslation($this->getStringTranslationStub()); $this->executable->setTimeThreshold(0.1); $this->executable->limit = array('unit' => 'second', 'value' => 1); } diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php index 133402e..e4b6e24 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateExecuteableMemoryExceededTest.php @@ -70,7 +70,7 @@ protected function setUp() { $this->message = $this->getMock('Drupal\migrate\MigrateMessageInterface'); $this->executable = new TestMigrateExecutable($this->migration, $this->message); - $this->executable->setTranslationManager($this->getStringTranslationStub()); + $this->executable->setStringTranslation($this->getStringTranslationStub()); } /** diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php index 598db2c..66e0fef 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/MigrateSqlSourceTestCase.php @@ -82,7 +82,7 @@ protected function setUp() { $plugin = new $plugin_class($this->migrationConfiguration['source'], $this->migrationConfiguration['source']['plugin'], array(), $migration); $plugin->setDatabase($this->getDatabase($this->databaseContents + array('test_map' => array()))); $plugin->setModuleHandler($module_handler); - $plugin->setTranslationManager($this->getStringTranslationStub()); + $plugin->setStringTranslation($this->getStringTranslationStub()); $migration->expects($this->any()) ->method('getSourcePlugin') ->will($this->returnValue($plugin)); diff --git a/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php b/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php index ad305f2..8746236 100644 --- a/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php +++ b/core/modules/migrate/tests/Drupal/migrate/Tests/TestMigrateExecutable.php @@ -37,13 +37,13 @@ class TestMigrateExecutable extends MigrateExecutable { protected $clearedMemoryUsage; /** - * Sets the translation manager. + * Sets the string translation service. * - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The translation manager. */ - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; + public function setStringTranslation(TranslationInterface $string_translation) { + $this->stringTranslation = $string_translation; } /** diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemController.php b/core/modules/system/lib/Drupal/system/Controller/SystemController.php index eda620d..d521932 100644 --- a/core/modules/system/lib/Drupal/system/Controller/SystemController.php +++ b/core/modules/system/lib/Drupal/system/Controller/SystemController.php @@ -299,10 +299,10 @@ public function themesPage() { // There are two possible theme groups. $theme_group_titles = array( - 'enabled' => $this->translationManager()->formatPlural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'), + 'enabled' => $this->formatPlural(count($theme_groups['enabled']), 'Enabled theme', 'Enabled themes'), ); if (!empty($theme_groups['disabled'])) { - $theme_group_titles['disabled'] = $this->translationManager()->formatPlural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes'); + $theme_group_titles['disabled'] = $this->formatPlural(count($theme_groups['disabled']), 'Disabled theme', 'Disabled themes'); } uasort($theme_groups['enabled'], 'system_sort_themes'); diff --git a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkForm.php b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkForm.php index 172162b..fc9898d 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkForm.php +++ b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkForm.php @@ -268,7 +268,7 @@ public function viewsFormSubmit(&$form, &$form_state) { $count = count(array_filter($form_state['values'][$this->options['id']])); if ($count) { - drupal_set_message($this->translationManager()->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array( + drupal_set_message($this->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', array( '%action' => $action->label(), ))); } diff --git a/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php b/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php index ef7cb95..f7c86a2 100644 --- a/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php +++ b/core/modules/system/tests/Drupal/system/Tests/Breadcrumbs/PathBasedBreadcrumbBuilderTest.php @@ -124,7 +124,7 @@ public function setUp() { $this->currentUser ); - $this->builder->setTranslationManager($this->getStringTranslationStub()); + $this->builder->setStringTranslation($this->getStringTranslationStub()); $this->linkGenerator = $this->getMock('Drupal\Core\Utility\LinkGeneratorInterface'); $this->builder->setLinkGenerator($this->linkGenerator); @@ -415,8 +415,8 @@ protected function setupStubPathProcessor() { */ class TestPathBasedBreadcrumbBuilder extends PathBasedBreadcrumbBuilder { - public function setTranslationManager(TranslationInterface $translation_manager) { - $this->translationManager = $translation_manager; + public function setStringTranslation(TranslationInterface $string_translation) { + $this->stringTranslation = $string_translation; } public function setLinkGenerator(LinkGeneratorInterface $link_generator) { diff --git a/core/modules/update/lib/Drupal/update/UpdateManager.php b/core/modules/update/lib/Drupal/update/UpdateManager.php index 8c7c48a..a1801fe 100644 --- a/core/modules/update/lib/Drupal/update/UpdateManager.php +++ b/core/modules/update/lib/Drupal/update/UpdateManager.php @@ -10,12 +10,14 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\KeyValueStore\KeyValueFactoryInterface; use Drupal\Core\StringTranslation\TranslationInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\ProjectInfo; /** * Default implementation of UpdateManagerInterface. */ class UpdateManager implements UpdateManagerInterface { + use StringTranslationTrait; /** * The update settings @@ -60,13 +62,6 @@ class UpdateManager implements UpdateManagerInterface { protected $availableReleasesTempStore; /** - * The translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translation; - - /** * Constructs a UpdateManager. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory @@ -84,7 +79,7 @@ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandle $this->updateSettings = $config_factory->get('update.settings'); $this->moduleHandler = $module_handler; $this->updateProcessor = $update_processor; - $this->translation = $translation; + $this->stringTranslation = $translation; $this->keyValueStore = $key_value_expirable_factory->get('update'); $this->availableReleasesTempStore = $key_value_expirable_factory->get('update_available_releases'); $this->projects = array(); @@ -215,13 +210,4 @@ public function fetchDataBatch(&$context) { } } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translation->translate($string, $args, $options); - } - } diff --git a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsEntityArgumentValidator.php b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsEntityArgumentValidator.php index 9800e32..7c83546 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsEntityArgumentValidator.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Derivative/ViewsEntityArgumentValidator.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\Derivative\DerivativeBase; use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -21,6 +22,8 @@ * @see \Drupal\views\Plugin\views\argument_validator\Entity */ class ViewsEntityArgumentValidator extends DerivativeBase implements ContainerDerivativeInterface { + use StringTranslationTrait; + /** * The base plugin ID this derivative is for. * @@ -36,13 +39,6 @@ class ViewsEntityArgumentValidator extends DerivativeBase implements ContainerDe protected $entityManager; /** - * The string translation. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $translationManager; - - /** * List of derivative definitions. * * @var array @@ -56,13 +52,13 @@ class ViewsEntityArgumentValidator extends DerivativeBase implements ContainerDe * The base plugin ID. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. - * @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager + * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation * The string translation. */ - public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, TranslationInterface $translation_manager) { + public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, TranslationInterface $string_translation) { $this->basePluginId = $base_plugin_id; $this->entityManager = $entity_manager; - $this->translationManager = $translation_manager; + $this->stringTranslation = $string_translation; } /** @@ -96,13 +92,4 @@ public function getDerivativeDefinitions($base_plugin_definition) { return $this->derivatives; } - /** - * Translates a string to the current language or to a given language. - * - * See the t() documentation for details. - */ - protected function t($string, array $args = array(), array $options = array()) { - return $this->translationManager->translate($string, $args, $options); - } - } diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListBuilderTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListBuilderTest.php index 4837525..902b615 100644 --- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListBuilderTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListBuilderTest.php @@ -125,7 +125,7 @@ public function testBuildRowEntityList() { // because t() is called on there. $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); $view_list_builder = new TestViewListBuilder($entity_type, $storage, $display_manager); - $view_list_builder->setTranslationManager($this->getStringTranslationStub()); + $view_list_builder->setStringTranslation($this->getStringTranslationStub()); $view = new View($values, 'view'); diff --git a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php index 0c5f4e7..7597dea 100644 --- a/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php +++ b/core/tests/Drupal/Tests/Core/Controller/ExceptionControllerTest.php @@ -35,7 +35,6 @@ public static function getInfo() { public function test405HTML() { $exception = new \Exception('Test exception'); $flat_exception = FlattenException::create($exception, 405); - $translation_manager = $this->getStringTranslationStub(); $html_page_renderer = $this->getMock('Drupal\Core\Page\HtmlPageRendererInterface'); $html_fragment_renderer = $this->getMock('Drupal\Core\Page\HtmlFragmentRendererInterface'); $title_resolver = $this->getMock('Drupal\Core\Controller\TitleResolverInterface'); @@ -45,7 +44,7 @@ public function test405HTML() { ->method('getContentType') ->will($this->returnValue('html')); - $exception_controller = new ExceptionController($content_negotiation, $translation_manager, $title_resolver, $html_page_renderer, $html_fragment_renderer); + $exception_controller = new ExceptionController($content_negotiation, $title_resolver, $html_page_renderer, $html_fragment_renderer); $response = $exception_controller->execute($flat_exception, new Request()); $this->assertEquals($response->getStatusCode(), 405, 'HTTP status of response is correct.'); $this->assertEquals($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.'); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php index f6d4129..121d745 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityListBuilderTest.php @@ -132,7 +132,7 @@ public function testGetOperations() { ->will($this->returnValue($url)); $list = new EntityListBuilder($this->entityType, $this->roleStorage, $this->moduleHandler); - $list->setTranslationManager($this->translationManager); + $list->setStringTranslation($this->translationManager); $operations = $list->getOperations($this->role); $this->assertInternalType('array', $operations); diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php index 1c260a3..2993b22 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityManagerTest.php @@ -348,7 +348,7 @@ public function testGetFormController() { $apple_form = $this->entityManager->getFormController('apple', 'default'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityForm', $apple_form); $this->assertAttributeInstanceOf('Drupal\Core\Extension\ModuleHandlerInterface', 'moduleHandler', $apple_form); - $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'translationManager', $apple_form); + $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'stringTranslation', $apple_form); $banana_form = $this->entityManager->getFormController('banana', 'default'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityFormInjected', $banana_form); @@ -398,7 +398,7 @@ public function testGetController() { $apple_controller = $this->entityManager->getController('apple', 'storage'); $this->assertInstanceOf($class, $apple_controller); $this->assertAttributeInstanceOf('Drupal\Core\Extension\ModuleHandlerInterface', 'moduleHandler', $apple_controller); - $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'translationManager', $apple_controller); + $this->assertAttributeInstanceOf('Drupal\Core\StringTranslation\TranslationInterface', 'stringTranslation', $apple_controller); $banana_controller = $this->entityManager->getController('banana', 'storage', 'getStorageClass'); $this->assertInstanceOf('Drupal\Tests\Core\Entity\TestEntityControllerInjected', $banana_controller); diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php index 883b79e..9b1b4e7 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php @@ -73,7 +73,7 @@ protected function setUp() { protected function setupContextualLinkDefault() { $this->contextualLinkDefault = new ContextualLinkDefault($this->config, $this->pluginId, $this->pluginDefinition); - $this->contextualLinkDefault->setTranslationManager($this->stringTranslation); + $this->contextualLinkDefault->setStringTranslation($this->stringTranslation); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php index 4febf02..70bddbc 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php @@ -83,7 +83,7 @@ protected function setUp() { */ protected function setupLocalActionDefault() { $this->localActionDefault = new LocalActionDefault($this->config, $this->pluginId, $this->pluginDefinition, $this->routeProvider); - $this->localActionDefault->setTranslationManager($this->stringTranslation); + $this->localActionDefault->setStringTranslation($this->stringTranslation); } /** diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index a0f8106..9cd7210 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -87,7 +87,7 @@ protected function setupLocalTaskDefault() { $this->localTaskBase = new TestLocalTaskDefault($this->config, $this->pluginId, $this->pluginDefinition); $this->localTaskBase ->setRouteProvider($this->routeProvider) - ->setTranslationManager($this->stringTranslation); + ->setStringTranslation($this->stringTranslation); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php new file mode 100644 index 0000000..69d2cea --- /dev/null +++ b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php @@ -0,0 +1,82 @@ + 'String translation trait', + 'description' => 'Tests the string translation trait.', + 'group' => 'StringTranslation', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + $this->translation = $this->getObjectForTrait('\Drupal\Core\StringTranslation\StringTranslationTrait'); + $stub = $this->getStringTranslationStub(); + $stub->expects($this->any()) + ->method('formatPlural') + ->will($this->returnArgument(2)); + $this->translation->setStringTranslation($stub); + $this->reflection = new \ReflectionClass(get_class($this->translation)); + } + + /** + * @covers ::t + */ + public function testT() { + $method = $this->reflection->getMethod('t'); + $method->setAccessible(TRUE); + + $this->assertEquals('something', $method->invoke($this->translation, 'something')); + } + + /** + * @covers ::formatPlural + */ + public function testFormatPlural() { + $method = $this->reflection->getMethod('formatPlural'); + $method->setAccessible(TRUE); + + $this->assertEquals('apples', $method->invoke($this->translation, 2, 'apple', 'apples')); + } + +}