diff --git a/core/lib/Drupal/Core/Annotation/Translation.php b/core/lib/Drupal/Core/Annotation/Translation.php index ae1adf8..9512bec 100644 --- a/core/lib/Drupal/Core/Annotation/Translation.php +++ b/core/lib/Drupal/Core/Annotation/Translation.php @@ -78,7 +78,7 @@ public function __construct(array $values) { 'context' => $values['context'], ); } - $this->translation = new TranslationWrapper($string, $options); + $this->translation = new TranslationWrapper($string, [], $options); } /** diff --git a/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php index 0df0c2e..4720b35 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php @@ -37,7 +37,7 @@ class ConfigEntityType extends EntityType { * {@inheritdoc} */ public function get() { - $this->definition['group_label'] = new TranslationWrapper('Configuration', array('context' => 'Entity type group')); + $this->definition['group_label'] = new TranslationWrapper('Configuration', array(), array('context' => 'Entity type group')); return parent::get(); } diff --git a/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php b/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php index 3e4f9d8..34363a5 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php @@ -37,7 +37,7 @@ class ContentEntityType extends EntityType { * {@inheritdoc} */ public function get() { - $this->definition['group_label'] = new TranslationWrapper('Content', array('context' => 'Entity type group')); + $this->definition['group_label'] = new TranslationWrapper('Content', array(), array('context' => 'Entity type group')); return parent::get(); } diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php index f7d83ce..3a36db5 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php @@ -16,10 +16,6 @@ * system is ready. This is useful for using translation in very low level * subsystems like entity definition and stream wrappers. * - * Because this class is for low-level strings defined in places like - * annotations, there is no support for arguments since those would be fixed - * strings that should simply be included in the string. - * * @see \Drupal\Core\Annotation\Translation */ class TranslationWrapper implements SafeStringInterface { @@ -33,6 +29,13 @@ class TranslationWrapper implements SafeStringInterface { protected $string; /** + * The translation arguments. + * + * @var array + */ + protected $arguments; + + /** * The translation options. * * @var array @@ -47,11 +50,14 @@ class TranslationWrapper implements SafeStringInterface { * * @param string $string * The string that is to be translated. + * @param array $arguments + * (optional) An array with placeholder replacements, keyed by placeholder. * @param array $options * (optional) An array of additional options. */ - public function __construct($string, array $options = []) { + public function __construct($string, array $arguments = array(), array $options = array()) { $this->string = $string; + $this->arguments = $arguments; $this->options = $options; } @@ -79,16 +85,6 @@ public function getOption($name) { } /** - * Gets all options from this translation wrapper. - * - * @return array - * The array of options. - */ - public function getOptions() { - return $this->options; - } - - /** * Implements the magic __toString() method. */ public function __toString() { @@ -102,14 +98,14 @@ public function __toString() { * The translated string. */ public function render() { - return $this->t($this->string, [], $this->options); + return $this->t($this->string, $this->arguments, $this->options); } /** * Magic __sleep() method to avoid serializing the string translator. */ public function __sleep() { - return array('string', 'options'); + return array('string', 'arguments', 'options'); } } diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index f0e9620..d96c758 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -173,7 +173,7 @@ protected function getTranslatableData(TypedDataInterface $element) { if (isset($definition['translation context'])) { $options['context'] = $definition['translation context']; } - return new TranslationWrapper($element->getValue(), $options); + return new TranslationWrapper($element->getValue(), array(), $options); } } return $translatable; diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php deleted file mode 100644 index 91eeaf3..0000000 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php +++ /dev/null @@ -1,75 +0,0 @@ -translationManager = $this->getStringTranslationStub(); - $container = new ContainerBuilder(); - $container->set('string_translation', $this->translationManager); - \Drupal::setContainer($container); - } - - /** - * @covers ::__construct - * @covers ::__toString - * @covers ::render - * - * @dataProvider providerTestConstruction - */ - public function testConstruction($expected, $string, $options = []) { - - $this->translationManager->expects($this->exactly(2)) - ->method('translate') - ->with($string, [], $options); - - $wrapper = new TranslationWrapper($string, $options); - - $this->assertSame($expected, (string) $wrapper); - $this->assertSame($expected, $wrapper->render()); - } - - /** - * Provides data to self::testConstruction(). - */ - public function providerTestConstruction() { - $data = array(); - $data[] = array( - 'Foo', - 'Foo', - ); - - $data[] = array( - 'Foo', - 'Foo', - ['context' => 'Bar'], - ); - - return $data; - } - -}