Page MenuHomePhabricator

Allow mw.text.listToText() to produce a list with serial commas
Open, Needs TriagePublicFeature


Feature summary (what you would like to be able to do and where):
The mw.text.listToText() feature should be able to produce lists with serial commas, e.g. "1, 2, and 3"

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
Currently, the mw.text.listToText() feature produces lists such as "1 and 2" or "1, 2 and 3", with no option for a serial comma before the conjunction. Most American style guides mandate the use of a serial comma before the and for lists of three or more items.

Benefits (why should this be implemented?):
Currently, making lists with a serial comma in lua currently requires either re-implementing a custom version of the listToText() function or workarounds such as specifying different conjunctions based on the length of the list. Having this option in the function would greatly simplify the code of modules that produce lists.

Event Timeline

Change 785336 had a related patch set uploaded (by Ahecht; author: Ahecht):

[mediawiki/extensions/Scribunto@master] Add fourth parameter, "serialconjunction", to mwtext.listToText

@Ahecht why not just do something like mw.text.listToText({1,2,3}, nil, ", or ")?

@Legoktm for an input list of arbitrary length, that would result in the possibility of getting an output of "1, or 2", which is not desired. Serial commas should only be used in lists of three or more items. You then end up with something like =mw.text.listToText(list, nil, #list > 2 and ", or " or " or ") which is starting to get pretty unwieldy for something required by pretty much every English style guide.