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

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

@akxakx changed the title Add support for other systemic aliases specified in CLDR root.xmlAdd support for other systemic aliases specified in CLDR root.xmlJul 31, 2026
@codecov

codecovBot 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 
FlagCoverage Δ
macos-14-3.1091.26% <100.00%> (+0.01%)⬆️
macos-14-3.1191.19% <100.00%> (+0.01%)⬆️
macos-14-3.1291.40% <100.00%> (+0.01%)⬆️
macos-14-3.1391.40% <100.00%> (+0.01%)⬆️
macos-14-3.1491.38% <100.00%> (+0.01%)⬆️
macos-14-3.1591.38% <100.00%> (+0.01%)⬆️
macos-14-3.891.13% <100.00%> (+0.01%)⬆️
macos-14-3.991.19% <100.00%> (+0.01%)⬆️
macos-14-pypy3.1091.26% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1091.28% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1191.22% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1291.43% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1391.43% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1491.40% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.1591.40% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.891.15% <100.00%> (+0.01%)⬆️
ubuntu-24.04-3.991.21% <100.00%> (+0.01%)⬆️
ubuntu-24.04-pypy3.1091.28% <100.00%> (+0.01%)⬆️
windows-2022-3.1091.27% <100.00%> (+0.01%)⬆️
windows-2022-3.1191.21% <100.00%> (+0.01%)⬆️
windows-2022-3.1291.42% <100.00%> (+0.01%)⬆️
windows-2022-3.1391.42% <100.00%> (+0.01%)⬆️
windows-2022-3.1491.40% <100.00%> (+0.01%)⬆️
windows-2022-3.1591.40% <100.00%> (+0.01%)⬆️
windows-2022-3.891.24% <100.00%> (+0.01%)⬆️
windows-2022-3.991.20% <100.00%> (+0.01%)⬆️
windows-2022-pypy3.1091.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.

@akx
akx requested a review from CopilotJuly 31, 2026 12:46
@codspeed-hq

codspeed-hqBot 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

CopilotAI 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
FileDescription
scripts/import_cldr.pyImports additional CLDR root.xml aliases (decimal formats, unit patterns/display names, date fields) into generated locale data.
babel/localedata.pyExtends merge + alias resolution to support dict overrides layered on top of aliases.
babel/units.pySwitches format_unit to rely on alias-resolving locale data for length fallback/alias behavior.
babel/dates.pySwitches format_timedelta unit/date-field lookup to rely on alias-resolving locale data and avoids a direct KeyError path.
tests/test_units.pyAdds regression tests for unit aliases, length aliases, and person-variant alias behavior.
tests/test_numbers.pyAdds regression tests for compact decimal and currency format aliasing.
tests/test_dates.pyAdds 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 threadscripts/import_cldr.py
Comment threadscripts/import_cldr.py
@akx
akx requested a review from tomasr8July 31, 2026 12:57

@tomasr8tomasr8 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 threadbabel/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
MemberAuthor

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
akxforce-pushed the systemic-aliases branch from 1c8d2c9 to fcb73a0CompareJuly 31, 2026 19:19
@akx
akx enabled auto-merge July 31, 2026 19:19
@akx
akx merged commit c2fdae6 into masterJul 31, 2026
41 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

@akx@tomasr8