diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php index 1fda0e0..06b4115 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php @@ -33,7 +33,7 @@ * what is used to display the page. * - 'context': The context the source string belongs to. * - * @return string + * @return string|\Drupal\Core\StringTranslation\TranslationWrapper * The translated string. * * @see \Drupal\Component\Utility\SafeMarkup::format() @@ -43,7 +43,7 @@ public function translate($string, array $args = array(), array $options = array /** * Renders a TranslationWrapper object to a string. * - * @param TranslationWrapper $translated_string + * @param \Drupal\Core\StringTranslation\TranslationWrapper $translated_string * A TranslationWrapper object. * * @return string diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index 0dc9980..038ac52 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -148,7 +148,8 @@ public function translate($string, array $args = array(), array $options = array // If the string has arguments that start with '!' we consider it unsafe // and return the translation as a string for backward compatibility // purposes. - // @todo remove this temporary workaround. + // @todo https://www.drupal.org/node/2570037 remove this temporary + // workaround. if (0 === strpos($arg_key, '!') && !SafeMarkup::isSafe($args[$arg_key])) { $safe = FALSE; break; @@ -173,15 +174,6 @@ public function renderTranslatedString(TranslationWrapper $translated_string) { } /** - * {@inheritdoc} - */ - public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { - $translatable_string = implode(LOCALE_PLURAL_DELIMITER, array($singular, $plural)); - $translated_strings = $this->doTranslate($translatable_string, $options); - return $this->formatPluralTranslated($count, $translated_strings, $args, $options); - } - - /** * Translates a string to the current language or to a given language. * * @param string $string @@ -208,6 +200,15 @@ protected function doTranslate($string, array $options = array()) { /** * {@inheritdoc} */ + public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { + $translatable_string = implode(LOCALE_PLURAL_DELIMITER, array($singular, $plural)); + $translated_strings = $this->doTranslate($translatable_string, $options); + return $this->formatPluralTranslated($count, $translated_strings, $args, $options); + } + + /** + * {@inheritdoc} + */ public function formatPluralTranslated($count, $translation, array $args = array(), array $options = array()) { $args['@count'] = $count; $translated_array = explode(LOCALE_PLURAL_DELIMITER, $translation); diff --git a/core/modules/locale/src/Tests/LocaleExportTest.php b/core/modules/locale/src/Tests/LocaleExportTest.php index 50d23d7..061c161 100644 --- a/core/modules/locale/src/Tests/LocaleExportTest.php +++ b/core/modules/locale/src/Tests/LocaleExportTest.php @@ -64,7 +64,7 @@ public function testExportTranslation() { // Ensure we have a translation file. $this->assertRaw('# French translation of Drupal', 'Exported French translation file.'); // Ensure our imported translations exist in the file. - $this->assertRaw($this->getTranslatedString(), 'French translations present in exported file.'); + $this->assertRaw('msgstr "lundi"', 'French translations present in exported file.'); // Import some more French translations which will be marked as customized. $name = tempnam('temporary://', "po2_") . '.po'; @@ -141,10 +141,8 @@ public function getPoFile() { "Content-Transfer-Encoding: 8bit\\n" "Plural-Forms: nplurals=2; plural=(n > 1);\\n" -msgid "1 comment" -msgid_plural "@count comments" -msgstr[0] "1 commentaire" -msgstr[1] "@count commentaires" +msgid "Monday" +msgstr "lundi" EOF; } @@ -168,21 +166,6 @@ public function getCustomPoFile() { } /** - * Returns a .po file fragment with a translated string. - * - * @return string - * A .po file fragment with a translated string. - */ - function getTranslatedString() { - return <<< EOF -msgid "1 comment" -msgid_plural "@count comments" -msgstr[0] "1 commentaire" -msgstr[1] "@count commentaires" -EOF; - } - - /** * Returns a .po file fragment with an untranslated string. * * @return string diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php index 4c9f8ef..6041e74 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php @@ -95,6 +95,8 @@ public function providerTestTranslatePlaceholder() { return [ ['foo @bar', ['@bar' => 'bar'], 'foo bar', TRUE], ['bar !baz', ['!baz' => 'baz'], 'bar baz', FALSE], + ['bar @bar !baz', ['@bar' => 'bar', '!baz' => 'baz'], 'bar bar baz', FALSE], + ['bar !baz @bar', ['!baz' => 'baz', '@bar' => 'bar'], 'bar baz bar', FALSE], ]; } } diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 405e767..2b6e94f 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -222,6 +222,7 @@ public function getStringTranslationStub() { $wrapper = new TranslationWrapper($string, $args, $options); $wrapper->setStringTranslation($translation); // Pretend everything is not safe. + // @todo https://www.drupal.org/node/2570037 return the wrapper instead. return (string) $wrapper; }); $translation->expects($this->any())