Verified Commit e48bf570 authored by Alex Pott's avatar Alex Pott
Browse files

fix: #3122231 Singular variant for plural string must contain @count,...

fix: #3122231 Singular variant for plural string must contain @count, otherwise Drupal displays wrong data for untranslated strings

By: niklan
By: andypost
By: kunalgautam
By: larowlan
By: dww
By: d34dman
By: gábor hojtsy
By: xjm
By: alexpott
By: godotislate
By: longwave
parent 82549dba
Loading
Loading
Loading
Loading
Loading
+1 −1
Changes for core/includes/form.inc: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -254,7 +254,7 @@ function form_get_options($element, $key) {
 *   // The 'success' parameter means no fatal PHP errors were detected. All
 *   // other error management should be handled using 'results'.
 *   if ($success) {
 *     $message = \Drupal::translation()->formatPlural(count($results), 'One item processed.', '@count items processed.');
 *     $message = \Drupal::translation()->formatPlural(count($results), '@count item processed.', '@count items processed.');
 *   }
 *   else {
 *     $message = t('Finished with an error.');
+1 −1
Changes for core/lib/Drupal/Core/DefaultContent/Command/ContentExportCommand.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

    $message = (string) $this->formatPlural(
      $count,
      'One entity was exported to @dir.',
      '@count entity was exported to @dir.',
      '@count entities were exported to @dir.',
      ['@dir' => $this->fileSystem->realpath($dir)],
    );
+2 −2
Changes for core/lib/Drupal/Core/Language/language.api.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -111,12 +111,12 @@
 * @code
 * // PHP code
 * t('May', [], ['context' => 'Long month name']);
 * \Drupal::translation()->formatPlural($count, '1 something',
 * \Drupal::translation()->formatPlural($count, '@count something',
 *   '@count somethings', [], ['context' => 'My context']);
 *
 * // JavaScript code
 * Drupal.t('May', {}, {'context': 'Long month name'});
 * Drupal.formatPlural(count, '1 something', '@count somethings', {},
 * Drupal.formatPlural(count, '@count something', '@count somethings', {},
 *   {'context': 'My context'});
 *
 * // *.links.yml file
+1 −1
Changes for core/lib/Drupal/Core/StringTranslation/ByteSizeMarkup.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ public static function create(float|int $size, ?string $langcode = NULL, ?Transl
    $options = ['langcode' => $langcode];
    $absolute_size = abs($size);
    if ($absolute_size < Bytes::KILOBYTE) {
      return new PluralTranslatableMarkup($size, '1 byte', '@count bytes', [], $options, $stringTranslation);
      return new PluralTranslatableMarkup($size, '@count byte', '@count bytes', [], $options, $stringTranslation);
    }
    // Create a multiplier to preserve the sign of $size.
    $sign = $absolute_size / $size;
+6 −5
Changes for core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php: 6 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -26,8 +26,10 @@ class PluralTranslatableMarkup extends TranslatableMarkup {
   *   The item count to display.
   * @param string $singular
   *   The string for the singular case. Make sure it is clear this is singular,
   *   to ease translation (e.g. use "1 new comment" instead of "1 new"). Do not
   *   use @count in the singular string.
   *   to ease translation (e.g. use "@count new comment" instead of "@count
   *   new"). Do not put "1" or "one" in the string, always use "@count". This
   *   ensures valid .po files and is necessary to correctly translate such
   *   strings in certain languages.
   * @param string $plural
   *   The string for the plural case. Make sure it is clear this is plural, to
   *   ease translation. Use @count in place of the item count, as in
@@ -36,8 +38,7 @@ 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.
   *   include @count in this array; this replacement is done automatically.
   * @param array $options
   *   (optional) An associative array of additional options. See t() for
   *   allowed keys.
@@ -75,7 +76,7 @@ public function __construct(
   *   Based on the first character of the key, the value is escaped and/or
   *   themed. See \Drupal\Component\Render\FormattableMarkup. Note that you
   *   do not need to include @count in this array; this replacement is done
   *   automatically for the plural cases.
   *   automatically.
   * @param array $options
   *   An associative array of additional options. See t() for allowed keys.
   *
Loading