diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php
index 89df04d..f455a9c 100644
--- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php
+++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php
@@ -175,6 +175,10 @@ public function formatPluralTranslated($count, $translation, array $args = array
$args['@count'] = $count;
$translated_array = explode(LOCALE_PLURAL_DELIMITER, $translation);
+ if ($count == 1) {
+ return String::format($translated_array[0], $args);
+ }
+
// Get the plural index through the gettext formula.
// @todo implement static variable to minimize function_exists() usage.
$index = (function_exists('locale_get_plural')) ? locale_get_plural($count, isset($options['langcode']) ? $options['langcode'] : NULL) : -1;
@@ -189,9 +193,9 @@ public function formatPluralTranslated($count, $translation, array $args = array
}
else {
// If the index cannot be computed or there's no translation, use
- // the most common rules of using the first item for 1 and the second
- // item for all other numbers.
- $return = $translated_array[(int)($count != 1)];
+ // the second plural form as a fallback (which allows for most flexibility
+ // with the replaceable @count value).
+ $return = $translated_array[1];
}
}
diff --git a/core/modules/config_translation/src/FormElement/FormElementBase.php b/core/modules/config_translation/src/FormElement/FormElementBase.php
index 19114ee..e13cc31 100644
--- a/core/modules/config_translation/src/FormElement/FormElementBase.php
+++ b/core/modules/config_translation/src/FormElement/FormElementBase.php
@@ -91,9 +91,7 @@ public function getTranslationBuild(LanguageInterface $source_language, Language
* A render array for the source value.
*/
protected function getSourceElement(LanguageInterface $source_language, $source_config) {
- // @todo Should be able to render source as singular+plurals. Similar
- // to TranslateEditForm::buildForm(), but here the source may also be
- // multi-plural.
+ // @todo Should support singular+plurals https://www.drupal.org/node/2454829
if ($source_config) {
$value = '' . nl2br($source_config) . '';
}
@@ -164,8 +162,7 @@ protected function getSourceElement(LanguageInterface $source_language, $source_
*/
protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
// Add basic properties that apply to all form elements.
- // @todo Needs support for possibly singular+plurals input if the source
- // was singular/plural. As in TranslateEditForm::buildForm().
+ // @todo Should support singular+plurals https://www.drupal.org/node/2454829
return array(
'#title' => $this->t('!label (!source_language)', array(
'!label' => $this->t($this->definition['label']),
diff --git a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php b/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php
index 705279a..a673ef4 100644
--- a/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php
+++ b/core/modules/views/src/Tests/Plugin/NumericFormatPluralTest.php
@@ -92,7 +92,7 @@ function testNumericFormatPlural() {
// Add Slovenian and set its plural formula to test multiple plural forms.
$edit = ['predefined_langcode' => 'sl'];
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
- $formula = 'nplurals=4; plural=(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);';
+ $formula = 'nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);';
$header = new PoHeader();
list($nplurals, $formula) = $header->parsePluralForms($formula);
debug($formula);
@@ -123,12 +123,12 @@ function testNumericFormatPlural() {
// The view should now use the new plural configuration.
$this->drupalGet('sl/numeric-test');
- $this->assertRaw('0 time0');
- $this->assertRaw('1 time1');
- $this->assertRaw('2 time2');
- $this->assertRaw('3 time3');
- $this->assertRaw('4 time3');
- $this->assertRaw('42 time0');
+ $this->assertRaw('0 time3');
+ $this->assertRaw('1 time0');
+ $this->assertRaw('2 time1');
+ $this->assertRaw('3 time2');
+ $this->assertRaw('4 time2');
+ $this->assertRaw('42 time3');
}
/**