Skip to content

Support the CLDR 49 ordinal day of month pattern field - #1383

Open
summeriver13 wants to merge 1 commit into
python-babel:masterfrom
summeriver13:fix/ordinal-day-of-month-ddd
Open

summeriver13 wants to merge 1 commit into
python-babel:masterfrom
summeriver13:fix/ordinal-day-of-month-ddd

Conversation

@summeriver13

@summeriver13 summeriver13 commented Oct 12, 2026 •

Copy link
Copy Markdown

scripts/import_cldr.py aborts on the CLDR 49 data with ValueError: Invalid length for field: 'ddd' (babel/dates.py:1809): CLDR 49 uses ddd for ordinal days of the month
("Sept 13th"), which the d field did not accept.

Changes

  • babel/dates.py: accept ddd for d and format the ordinal day picked by
    Locale.ordinal_form; locales without ordinal forms fall back to a single d as the CLDR
    spec prescribes, so the day is not zero-padded.
  • babel/core.py: new Locale.ordinal_day_formats property (CLDR 49 <dayOfMonth> patterns
    by ordinal plural category, {0} replaced by the day).
  • scripts/import_cldr.py: import dayOfMonths for the gregorian calendar
    (dayOfMonthContext[@type="format"] / dayOfMonthWidth[@type="abbreviated"]), plus tests
    for parsing, the ordinal output and the fallback.

Verification

$ uv run python scripts/import_cldr.py <cldr-49-beta2>/common   # exit 0, 0 errors, 183 locales
$ uv run python -c "from datetime import date; from babel.dates import format_date as f; print(f(date(2026, 9, 13), 'MMM ddd, y', locale='en'))"
Sep 13th, 2026
  • uv run pytest -q on the pinned CLDR 48.2 data: 7875 passed, 10 skipped, 2 xfailed.
  • The new tests fail without the code change, with exactly the ValueError from the issue.

I left the second half of #1379 (cldr-exemplars-delta import) to the maintainers.

Disclosure: written with AI assistance; I reviewed the diff, ran the importer and the suite.

CLDR 49 uses the "ddd" field for ordinal days of the month, e.g. "Sept 13th"; parse_pattern() rejected it, so scripts/import_cldr.py could not import CLDR 49 data at all. "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.

Refs python-babel#1379

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant