@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.
Comments
Comment #1
mgiffordComment #2
SKAUGHT$nameList = implode(' & ', array_filter(array_reverse(array_merge(array(array_pop($names)), array(implode(', ',$names))))));
Comment #3
mgifford@SKAUGHT - That looks like it would solve the "item 1, item2, item 3 & item4" business. It could be extended to include the "." easily.
$nameList = implode(' & ', array_filter(array_reverse(array_merge(array(array_pop($names)), array(implode(', ',$names)))))) . '.';
But not sure how it would assist improved internationalization.
Comment #4
SKAUGHTi'm not best sure how to handle multilingual aspects. I'm not sure what languages might fall into an issue here..is this just the user of the ampersand across languages? Maybe array matching what character the LanguageManager::getStandardLanguageList() would pull??
As well, rtl/ltr I image is also some issue.. A little routine for that would be needed.
Comment #5
SKAUGHTPerhaps adding an option check into formatPlural() to run this idea. default to ON.
But i'm also wondering if it might be good to introduce another format function for this so it can be recycled as it's certainly a useful formatter...i do myself use it for term outputs all the time. Then: where would be best to add it (I'm not certain in the TranslationManager class is where it should be). How should it as a function be named? formatAndList()??
Toward the point of the ticket title: i think outputting an UL element in the middle of a sentence won't really help anyone and does add html and additional css (that we then need to un-block level it). i know there's some trouble in formatting for languages...but that might be worth that effort in the end to help people read a message that actually makes sense.
===
From my random thoughts of yesterday: might using
&
and,
be a decent approach to shortcut some issues -- allow the font to display the right character. otherwise some extend/supplement to getStandardLanguageList type data.Comment #6
mgiffordSounds good to me. Really gotta get someone like @Gábor Hojtsy to look at it who are familiar with how lists like this are expressed in different languages.
Comment #7
davidhernandezI think Cottser's point was to avoid the use of a sentence at all.
Instead of:
1,2,3
use:
This would be the only thing I see bypassing the translation issues, because it isn't a sentence that needs translating. Imploding the list in different ways, replacing 'and' with '&', etc, will still have problems. I know Gábor mentioned some languages would replace the 'and' with another comma, but might be too particular for someone to want to deal with. It would also mean leaving out the serial (Oxford) comma, which goes agains the style guide.
Comment #8
SKAUGHTi think the issue with a full UL/OL list is that will take alot of screen space, when a list is...more than 4 or 5.. And in a responsive site, even worse. Which could happen in a lot of real world uses.
A lot of clients/designers outlines i have, would hate that (i hate that, too) -- especially as an out of the box solution for Core to do.
Comment #10
SKAUGHTlinking. How basic concept has now been introduced to core.
Although is a css pseudo-class based method which will lack both legacy browser support and poor content indexing of content from search engines. Does work with RTL, (but only visually)
Comment #20
larowlanWe need an issue summary update here to clarify what the bug is
Thanks
Comment #23
smustgrave CreditAttribution: smustgrave at Mobomo commentedIf still a valid bug please reopen adressing #20 and updating issue summary.
Thanks!