diff --git a/core/lib/Drupal/Component/Gettext/PoStreamReader.php b/core/lib/Drupal/Component/Gettext/PoStreamReader.php index f84d251..eb62831 100644 --- a/core/lib/Drupal/Component/Gettext/PoStreamReader.php +++ b/core/lib/Drupal/Component/Gettext/PoStreamReader.php @@ -424,6 +424,9 @@ private function readLine() { $this->_current_item['msgstr'] = []; } + // Replace @count[X] elements with @count. For compatibility with + // drupal.org translations for Drupal 7. + $quoted = preg_replace('!@count\[\d+\]!', '@count', $quoted); $this->_current_item['msgstr'][$this->_current_plural_index] = $quoted; $this->_context = 'MSGSTR_ARR'; diff --git a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php index 581c98f..604f4a1 100644 --- a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php @@ -362,6 +362,17 @@ public function testCreatedLanguageTranslation() { } /** + * Test the translation are imported with fix old Drupal 7 plural style. + */ + public function testCreatedLanguageTranslationWithOldPluralStyle() { + $this->importPoFile($this->getPoFileWithOldPluralStyle(), ['langcode' => 'ru']); + for ($i=0; $i < 6; $i++) { + $plural = \Drupal::translation()->formatPlural($i, '1 word', '@count words', [], ['langcode' => 'ru']); + $this->assertNotContains('[2]', $plural->render(), 'Import Drupal 7 plural style with @count[number]'); + } + } + + /** * Helper function: import a standalone .po file in a given language. * * @param string $contents @@ -640,4 +651,29 @@ public function getPoFileWithConfigDe() { EOF; } + /** + * Helper function that returns a .po file with Drupal 7 translation style. + */ + public function getPoFileWithOldPluralStyle() { + return <<< EOF +msgid "" +msgstr "" +"Project-Id-Version: Drupal 8\\n" +"MIME-Version: 1.0\\n" +"Content-Type: text/plain; charset=UTF-8\\n" +"Content-Transfer-Encoding: 8bit\\n" +"Plural-Forms: nplurals=5; plural=n;\\n" + +msgid "1 word" +msgid_plural "@count words" +msgstr[0] "@count слово" +msgstr[1] "@count слова" +msgstr[2] "@count[2] слов" +msgstr[3] "@count[3] словцо" +msgstr[4] "@count[4] словеса" +msgstr[5] "@count[5] здесь был Вова" + +EOF; + } + }