Skip to content

Add support for other systemic aliases specified in CLDR root.xml - #1310

Merged
akx merged 2 commits into
masterfrom
systemic-aliases
Jul 31, 2026
Merged

Add support for other systemic aliases specified in CLDR root.xml#1310
akx merged 2 commits into
masterfrom
systemic-aliases

Conversation

@akx

@akx akx commented Jul 31, 2026

Copy link
Copy Markdown
Member

We had some manual fallbacks for missing field/unit lengths, and ignored many <alias>es in CLDR data entirely.

This PR imports those aliases and uses them to resolve missing lengths, improving output in corner cases and fixes some rare KeyError crashes too.

There's a quirk related to person-variant unit aliases, which are only expressed in CLDR for the short length. If one follows the spec to the letter, a request for a long/narrow person-variant unit will route through the short length and lose the requested length.

We use the same "workaround" as ICU to preserve the length, by importing these as whole-unit aliases. Not totally spec-compliant, but the end result is simply better.

Fixes #1076.

@akx akx changed the title Add support for other systemic aliases specified in CLDR root.xml Add support for other systemic aliases specified in CLDR root.xml Jul 31, 2026
@akx akx added the area/CLDR label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.20%. Comparing base (95d2f60) to head (fcb73a0).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1310      +/-   ##
==========================================
+ Coverage   92.19%   92.20%   +0.01%     
==========================================
  Files          27       27              
  Lines        4764     4761       -3     
==========================================
- Hits         4392     4390       -2     
+ Misses        372      371       -1     
Flag Coverage Δ
macos-14-3.10 91.26% <100.00%> (+0.01%) ⬆️
macos-14-3.11 91.19% <100.00%> (+0.01%) ⬆️
macos-14-3.12 91.40% <100.00%> (+0.01%) ⬆️
macos-14-3.13 91.40% <100.00%> (+0.01%) ⬆️
macos-14-3.14 91.38% <100.00%> (+0.01%) ⬆️
macos-14-3.15 91.38% <100.00%> (+0.01%) ⬆️
macos-14-3.8 91.13% <100.00%> (+0.01%) ⬆️
macos-14-3.9 91.19% <100.00%> (+0.01%) ⬆️
macos-14-pypy3.10 91.26% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.10 91.28% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.11 91.22% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.12 91.43% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.13 91.43% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.14 91.40% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.15 91.40% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.8 91.15% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-3.9 91.21% <100.00%> (+0.01%) ⬆️
ubuntu-24.04-pypy3.10 91.28% <100.00%> (+0.01%) ⬆️
windows-2022-3.10 91.27% <100.00%> (+0.01%) ⬆️
windows-2022-3.11 91.21% <100.00%> (+0.01%) ⬆️
windows-2022-3.12 91.42% <100.00%> (+0.01%) ⬆️
windows-2022-3.13 91.42% <100.00%> (+0.01%) ⬆️
windows-2022-3.14 91.40% <100.00%> (+0.01%) ⬆️
windows-2022-3.15 91.40% <100.00%> (+0.01%) ⬆️
windows-2022-3.8 91.24% <100.00%> (+0.01%) ⬆️
windows-2022-3.9 91.20% <100.00%> (+0.01%) ⬆️
windows-2022-pypy3.10 91.27% <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-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing systemic-aliases (fcb73a0) with master (95d2f60)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Babel’s CLDR import and locale-data resolution to ingest additional systemic <alias> rules from CLDR root.xml, so missing length variants (units, date fields, compact decimals, currency formats) resolve via aliases rather than ad-hoc fallbacks—eliminating some rare KeyError crashes and improving formatting in edge cases.

Changes:

  • Import and materialize additional CLDR root.xml alias relationships during scripts/import_cldr.py ingestion (decimal formats, unit lengths/unit aliases, date field aliases).
  • Enhance locale-data alias resolution/merging in babel/localedata.py to support “alias + dict overrides” safely.
  • Simplify unit and timedelta formatting lookups to rely on alias-resolving locale data instead of hard-coded fallbacks, with new regression tests covering the reported cases.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
scripts/import_cldr.py Imports additional CLDR root.xml aliases (decimal formats, unit patterns/display names, date fields) into generated locale data.
babel/localedata.py Extends merge + alias resolution to support dict overrides layered on top of aliases.
babel/units.py Switches format_unit to rely on alias-resolving locale data for length fallback/alias behavior.
babel/dates.py Switches format_timedelta unit/date-field lookup to rely on alias-resolving locale data and avoids a direct KeyError path.
tests/test_units.py Adds regression tests for unit aliases, length aliases, and person-variant alias behavior.
tests/test_numbers.py Adds regression tests for compact decimal and currency format aliasing.
tests/test_dates.py Adds regression tests for date field length aliasing and missing-pattern edge cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/import_cldr.py
Comment thread scripts/import_cldr.py
@akx
akx requested a review from tomasr8 July 31, 2026 12:57

@tomasr8 tomasr8 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.

Not super familiar with this, but nothing jumps out at me. The comments were very helpful though :)

Comment thread babel/localedata.py
elif isinstance(data, tuple):
alias, others = data
data = alias.resolve(base)
if others: # Apply overrides on a copy.

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.

Sorry, I'm not that familiar with this part of the codebase - why is this needed? And should it be tested?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

others were simply ignored, which caused some chains of override/alias to fail (which are needed here).

There's an explicit test now :)

akx added 2 commits July 31, 2026 22:19
We had some manual fallbacks for missing field/unit lengths,
and ignored many `<alias>`es in CLDR data entirely.

This PR imports those aliases and uses them to resolve missing lengths,
improving output in corner cases and fixes some rare KeyError crashes too.

There's a quirk related to person-variant unit aliases,
which are only expressed in CLDR for the short length.
If one follows the spec to the letter,
a request for a long/narrow person-variant unit will route
through the short length and lose the requested length.
We use the same "workaround" as ICU to preserve the length,
by importing these as whole-unit aliases. Not totally spec-
compliant, but the end result is simply better.

Fixes #1076
@akx
akx force-pushed the systemic-aliases branch from 1c8d2c9 to fcb73a0 Compare July 31, 2026 19:19
@akx
akx enabled auto-merge July 31, 2026 19:19
@akx
akx merged commit c2fdae6 into master Jul 31, 2026
41 checks passed
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.

Add support for other systemic aliases specified in CLDR root.xml

3 participants