diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php index 7d36998..1ba5a3c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php @@ -180,6 +180,11 @@ public function viewElements(FieldItemListInterface $items, $langcode) { } if ($format_string) { + // Pass in the current output as an override for @count in plural + // formatting. The numeric value is used to decide which plural form to + // use, but we want to substitute the current number-formatted + // string with the thousands separator and other settings applied in + // the output. $output = PluralTranslatableMarkup::createFromTranslatedString($item->value, $format_string, ['@count' => $output], ['langcode' => $this->getSetting('_settings_langcode')]); } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php index 5bcfb7c..da19d5c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php @@ -116,9 +116,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // Add prefix and suffix. if ($field_settings['format_plural_string'] && $this->getSetting('format_plural')) { // The field setting is a string containing all plural variants, suitable - // for use in formatPlural() methods, but already translated into the - // UI language. Pop off the last plural variant, and use the parts - // before/after @count in that string as the prefix/suffix for this field. + // for use in plural formatting, translated into the UI language. Pop + // off the last plural variant, and use the parts before/after @count in + // that string as the prefix/suffix for this field. $values = explode(PluralTranslatableMarkup::DELIMITER, $field_settings['format_plural_string']); $labels = explode('@count', array_pop($values)); if (isset($labels[0])) { diff --git a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php index fc7a85b..3d3b170 100644 --- a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php +++ b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php @@ -62,10 +62,10 @@ class PluralTranslatableMarkup extends TranslatableMarkup { * (optional) An array with placeholder replacements, keyed by placeholder. * See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for * additional information about placeholders. Note that you do not need to - * include @count in this array; this replacement is done automatically - * for the plural cases. But you can include @count to override the - * replacement value (for instance, to use a formatted number instead of - * the raw number). + * include @count in this array; this value is supplied automatically. + * However, you can include a replacement for @count to override the + * default of $count (for example, you might want to have a formatted + * number instead of the raw number $count in the output). * @param array $options * (optional) An associative array of additional options. See t() for * allowed keys. @@ -127,7 +127,9 @@ public function render() { } $arguments = $this->getArguments(); - // Allow overrides of what gets substituted in for @count. + // Allow overrides of what gets substituted in for @count; for example, to + // include a formatted number in the output, while using the raw number to + // decide which plural form to use. if (!isset($arguments['@count'])) { $arguments['@count'] = $this->count; } diff --git a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php index cfe8167..175a5a8 100644 --- a/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php +++ b/core/lib/Drupal/Core/StringTranslation/StringTranslationTrait.php @@ -98,8 +98,10 @@ protected function getNumberOfPlurals($langcode = NULL) { protected function getPluralLabels($langcode) { $plurals = $this->getNumberOfPlurals($langcode); - // @todo The return values for both cases should be more relevant to the - // actual plural rules of the language; see + // @todo The return values should be made language-specific, so that they + // reflect the actual plural rules of languages. Also this method should + // be used in several forms that are currently calculating their own + // labels for plural variant forms. Issue: // https://www.drupal.org/node/2499639. if ($plurals == 1) { @@ -112,6 +114,9 @@ protected function getPluralLabels($langcode) { } if ($plurals == 2) { + // @todo see above note. This text is good for typical 2-form languages, + // but it may need special cases for languages where the two forms do not + // correspond to 1 and != 1 values. return [ [ 'label' => $this->t('Singular form'), @@ -125,6 +130,9 @@ protected function getPluralLabels($langcode) { } // For the != 2 case, generate labels. + // @todo see above note. This definitely needs specific cases for languages + // that describe what the forms are used for, rather than saying + // Singular form, First plural form, 2. plural form, etc. $labels = []; for ($i = 0; $i < $plurals; $i++) { $labels[] = [