Skip to content

Use contextual conjunctions in Spanish list formatting - #1505

Open
0718lol wants to merge 1 commit into
python-babel:masterfrom
0718lol:fix-spanish-list-conjunctions
Open

0718lol wants to merge 1 commit into
python-babel:masterfrom
0718lol:fix-spanish-list-conjunctions

Conversation

@0718lol

@0718lol 0718lol commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #1503.

Use the following item to select the Spanish conjunction in the two-item or final list pattern. The replacement applies to Spanish templates that use y or o. The tests cover both list lengths, short styles, regional Spanish, uppercase input, the hielo exception, and common numeric cases.

The contextual checks follow the Spanish handling in ICU's list formatter. CLDR describes the placement and language rules.

Verification

  • Seven regression cases failed on master before the fix.
  • On Python 3.12 with the CLDR data from Babel 2.19.0, the list and unit suites passed all 49 tests. The full tests suite completed with 8,133 passed, 4 skipped, and 2 expected failures.
  • Ruff and git diff --check passed.

Investigation, implementation, tests, and drafting were done with Codex assistance.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.44%. Comparing base (394f91a) to head (d63a984).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1505      +/-   ##
==========================================
+ Coverage   94.43%   94.44%   +0.01%     
==========================================
  Files          27       27              
  Lines        5051     5061      +10     
==========================================
+ Hits         4770     4780      +10     
  Misses        281      281              
Flag Coverage Δ
macos-26-3.10 93.53% <100.00%> (+0.01%) ⬆️
macos-26-3.11 93.47% <100.00%> (+0.01%) ⬆️
macos-26-3.12 93.73% <100.00%> (+0.01%) ⬆️
macos-26-3.13 93.73% <100.00%> (+0.01%) ⬆️
macos-26-3.14 93.71% <100.00%> (+0.01%) ⬆️
macos-26-3.15 93.71% <100.00%> (+0.01%) ⬆️
macos-26-3.9 93.47% <100.00%> (+0.01%) ⬆️
macos-26-pypy3.11 93.44% <100.00%> (+0.01%) ⬆️
macos-26-pypy3.12 93.69% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.10 93.55% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.11 93.49% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.12 93.75% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.13 93.75% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.14 93.73% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.15 93.73% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.9 93.49% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-pypy3.11 93.45% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-pypy3.12 93.71% <100.00%> (+0.01%) ⬆️
windows-2025-3.10 93.63% <100.00%> (+0.01%) ⬆️
windows-2025-3.11 93.57% <100.00%> (+0.01%) ⬆️
windows-2025-3.12 93.82% <100.00%> (+0.01%) ⬆️
windows-2025-3.13 93.82% <100.00%> (+0.01%) ⬆️
windows-2025-3.14 93.80% <100.00%> (+0.01%) ⬆️
windows-2025-3.15 93.80% <100.00%> (+0.01%) ⬆️
windows-2025-3.9 93.56% <100.00%> (+0.01%) ⬆️
windows-2025-pypy3.11 93.57% <100.00%> (+0.01%) ⬆️
windows-2025-pypy3.12 93.82% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed

codspeed Bot commented Nov 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing 0718lol:fix-spanish-list-conjunctions (d63a984) with master (394f91a)

Open in CodSpeed

@akx akx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a better way to fix this than add special handling for locale.language == 'es'.

@0718lol

0718lol commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Fair point — hardcoding locale.language == 'es' in babel/lists.py sticks out since the rest of Babel is CLDR-data-driven.

I checked CLDR 48.2's common/main/es.xml (and he.xml) and CLDR XML doesn't encode these contextual list conjunction substitutions at all (only {0} y {1} / {0} o {1}). That's why ICU4C (listformatter.cpp) handles them out-of-band via a contextual pattern handler for es and he.

Before reworking this, which direction fits Babel better?

  • Keep babel.lists strictly CLDR-driven (no hardcoded language rules outside CLDR) — in which case I'm happy to close this PR and format_list ignores contextual conjunctions in Spanish #1503.
  • Use a declarative pattern-contextualizer table/registry (keyed by language/pattern, extensible to he as well, and properly handling accented í/ó which my first draft missed).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

format_list ignores contextual conjunctions in Spanish

2 participants