|
| 1 | +Locale-Aware List Formatting |
| 2 | +============================ |
| 3 | + |
| 4 | +``locale_parse`` formats numbers and dates, but joining a list of items the way a |
| 5 | +language expects — the conjunction word, whether there is a serial/Oxford comma, |
| 6 | +the two-item special case — is its own small problem. A naive ``", ".join`` gives |
| 7 | +``"A, B, C"`` with no "and"/"or" and no localisation. |
| 8 | + |
| 9 | +This implements the CLDR list-pattern composition (start/middle/end plus a |
| 10 | +two-item pattern) for a handful of locales and the conjunction / disjunction / |
| 11 | +unit styles. Pure standard library; imports no ``PySide6``. Every function is |
| 12 | +pure, so it is fully deterministic in CI. |
| 13 | + |
| 14 | +Headless API |
| 15 | +------------ |
| 16 | + |
| 17 | +.. code-block:: python |
| 18 | +
|
| 19 | + from je_auto_control import format_list |
| 20 | +
|
| 21 | + format_list(["apple", "pear", "grape"]) # 'apple, pear, and grape' |
| 22 | + format_list(["apple", "pear", "grape"], style="or") # 'apple, pear, or grape' |
| 23 | + format_list(["apple", "pear"], style="unit") # 'apple, pear' |
| 24 | + format_list(["manzana", "pera", "uva"], locale="es") # 'manzana, pera y uva' |
| 25 | + format_list(["A", "B", "C", "D"], locale="fr") # 'A, B, C et D' |
| 26 | +
|
| 27 | +``style`` is ``"and"`` (conjunction), ``"or"`` (disjunction) or ``"unit"`` |
| 28 | +(comma-separated, no conjunction). ``locale`` selects the conjunction word and |
| 29 | +the serial-comma rule (``en`` / ``es`` / ``fr`` / ``de`` / ``pt``; English uses |
| 30 | +the Oxford comma, the others do not; an unknown locale falls back to English). |
| 31 | +One and two element lists, and the empty list, are handled as special cases. |
| 32 | +``ValueError`` is raised for an unknown ``style``. |
| 33 | + |
| 34 | +Executor commands |
| 35 | +----------------- |
| 36 | + |
| 37 | +``AC_format_list`` takes a JSON array and returns ``{text}``, accepting ``style`` |
| 38 | +and ``locale``. It is exposed as the MCP tool ``ac_format_list`` and as a Script |
| 39 | +Builder command under **Data**. |
0 commit comments