Repository navigation
Support the CLDR 49 ordinal day of month pattern field - #1383
summeriver13 wants to merge 2 commits into
Conversation
|
@summeriver13 #1427 was just merged, so we are on CLDR 49. Could you rebase this? |
dfc62a0 to
98659e8
Compare
|
Rebased onto |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1383 +/- ##
==========================================
+ Coverage 93.66% 93.67% +0.01%
==========================================
Files 27 27
Lines 4972 4982 +10
==========================================
+ Hits 4657 4667 +10
Misses 315 315
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟢 Approval recommended
The ordinal day-of-month support changes have no active review issues blocking approval.
No open issues 🎉
What changed in this PR
Adds CLDR 49 ordinal day-of-month support to Babel’s locale-data importer and date formatter, addressing the ordinal-field portion of #1379. The separate locale migration issue remains out of scope.
Changes:
- Imports ordinal day patterns and exposes them through
Locale.ordinal_day_formats. - Formats ordinal days using locale plural rules, falling back to an unpadded day when no matching pattern exists.
- Adds tests for
dddparsing, ordinal output, fallback behavior, and unsupported field lengths.
| File | Description |
|---|---|
tests/test_dates.py |
Tests ordinal day parsing, formatting, and fallback behavior. |
scripts/import_cldr.py |
Imports abbreviated ordinal day patterns from calendar data. |
babel/dates.py |
Adds locale-aware ordinal day formatting. |
babel/core.py |
Exposes ordinal day patterns through a new locale property. |
Review effort: Balanced
akx
left a comment
There was a problem hiding this comment.
Small test changes -- and we'll see if other changes are needed once CI rolls through.
98659e8 to
1ae0152
Compare
|
Done in 1ae0152:
Local run with CLDR 49 data: |
|
I have a few nits, if you give me a few hours I'll post my review :) |
tomasr8
left a comment
There was a problem hiding this comment.
A few nits, but otherwise LGTM :)
CLDR 49 adds the "ddd" pattern field for ordinal days of the month ("Sept 13th")
and the matching <dayOfMonths> data. PATTERN_CHARS already accepts "ddd", so
formatting "ddd" zero-padded the day to three digits ("001"). "ddd" now formats
the day with the locale's ordinal forms, keyed by the ordinal plural category,
and falls back to a single "d" for locales that have none, as the CLDR spec
prescribes. scripts/import_cldr.py imports the dayOfMonth patterns.
Refs python-babel#1379
Remove the CLDR version note from the property docstring. Document the format character count. Warn on unsupported CLDR element types. Extend the tests to French and the fallback path. Co-Authored-By: pi <noreply@pi.dev>
870cceb to
b2b25e6
Compare
scripts/import_cldr.pyaborts on the CLDR 49 data withValueError: Invalid length for field: 'ddd'(babel/dates.py:1809): CLDR 49 usesdddfor ordinal days of the month("Sept 13th"), which the
dfield did not accept.Changes
babel/dates.py: acceptdddfordand format the ordinal day picked byLocale.ordinal_form; locales without ordinal forms fall back to a singledas the CLDRspec prescribes, so the day is not zero-padded.
babel/core.py: newLocale.ordinal_day_formatsproperty (CLDR 49<dayOfMonth>patternsby ordinal plural category,
{0}replaced by the day).scripts/import_cldr.py: importdayOfMonthsfor the gregorian calendar(
dayOfMonthContext[@type="format"]/dayOfMonthWidth[@type="abbreviated"]), plus testsfor parsing, the ordinal output and the fallback.
Verification
uv run pytest -qon the pinned CLDR 48.2 data: 7875 passed, 10 skipped, 2 xfailed.ValueErrorfrom the issue.I left the second half of #1379 (
cldr-exemplars-deltaimport) to the maintainers.Disclosure: written with AI assistance; I reviewed the diff, ran the importer and the suite.