diff --git a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php index fb7ab9e83965718ca1d7f0370efae3edc8253bd5..d6410b2e5910f9f6f4a428382dd6f75accf52583 100644 --- a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php +++ b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php @@ -107,28 +107,15 @@ public function render() { $arguments['@count'] = $this->count; $translated_array = explode(PoItem::DELIMITER, $this->translatedString); - if ($this->count == 1) { - return $this->placeholderFormat($translated_array[0], $arguments); - } - $index = $this->getPluralIndex(); - if ($index == 0) { + if ($this->count == 1 || $index == 0 || count($translated_array) == 1) { // Singular form. $return = $translated_array[0]; } else { - if (isset($translated_array[$index])) { - // N-th plural form. - $return = $translated_array[$index]; - } - else { - // If the index cannot be computed or there's no translation, use the - // second plural form as a fallback (which allows for most flexibility - // with the replaceable @count value). - $return = $translated_array[1]; - } + // Nth plural form, fallback to second plural form. + $return = $translated_array[$index] ?? $translated_array[1]; } - return $this->placeholderFormat($return, $arguments); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/PluralTranslatableMarkupTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/PluralTranslatableMarkupTest.php index 738c85f9f1d0f639a57f6835ad643a58966743a9..a2cd7082266aa74726a9487d21269a841115b946 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/PluralTranslatableMarkupTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/PluralTranslatableMarkupTest.php @@ -43,4 +43,12 @@ public function providerPluralTranslatableMarkupSerialization() { ]; } + /** + * Tests when the plural translation is missing. + */ + public function testMissingPluralTranslation() { + $markup = PluralTranslatableMarkup::createFromTranslatedString(2, 'There is no plural delimiter @count'); + $this->assertEquals('There is no plural delimiter 2', $markup->render()); + } + }