Plural lists should use HTML lists rather than simply implode(', ', $var)

Created on 16 April 2014, about 10 years ago
Updated 20 June 2023, 12 months ago

@Cottser points out that there are problems displaying multiples separated simply by ", " and that it would be better for internationalization to use HTML lists so that we don't need to worry so much about grammar for different languages.

From a brief search, this problem exists in a number of places.

core/modules/views_ui/views_ui.theme.inc:
$variables['displays'] = empty($variables['displays']) ? t('None') : format_plural(count($variables['displays']), 'Display', 'Displays') . ': ' . '<em>' . implode(', ', $variables['displays']) . '</em>';

core/lib/Drupal/Core/Extension/InfoParser.php:
$message = format_plural(count($missing_keys), 'Missing required key (!missing_keys) in !file.', 'Missing required keys (!missing_keys) in !file.', array('!missing_keys' => implode(', ', $missing_keys), '!file' => $filename));

core/modules/system/lib/Drupal/system/Tests/Form/ValidationTest.php:
$top_message = format_plural(count($error_links), '1 error has been found', '@count errors have been found') . ': ' . implode(', ', $error_links);

core/modules/system/system.install:
'value' => format_plural(count($modules), 'The %modules module is disabled.', 'The following modules are disabled: %modules', array('%modules' =>implode(', ', $modules))),

core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTid.php:
form_error($form, $form_state, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array('@terms' => implode(', ', array_keys($missing)))));

core/modules/user/lib/Drupal/user/Plugin/views/filter/Name.php:
form_error($form, $form_state, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing)))));

But came up because of a patch in #1493324-198: Inline form errors for accessibility and UX β†’ which is adding to this problem.

We should have a consistent pattern in dealing with this. I think it would look better, as the current solution doesn't even work well in English as it lacks both the ", and " which is traditional for the last item as well as the final "." which is another normal convention.

πŸ› Bug report
Status

Closed: outdated

Version

9.5

Component
UI textΒ  β†’

Last updated about 14 hours ago

No maintainer
Created by

πŸ‡¨πŸ‡¦Canada mgifford Ottawa, Ontario

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024