Skip to content

Sort MO indexes by encoded context and message keys - #1374

Open
fhgffy wants to merge 1 commit into
python-babel:masterfrom
fhgffy:fix/mo-context-sort
Open

fhgffy wants to merge 1 commit into
python-babel:masterfrom
fhgffy:fix/mo-context-sort

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 9, 2026

Copy link
Copy Markdown

MO files require the original-string table to be sorted by its encoded lookup keys. Sorting Message objects orders msgid before context, which can emit an unsorted table when messages have contexts. Babel does not emit a hash table, so binary-search readers depend on this ordering.

Sort the existing descriptors by their serialized context/singular keys before writing the parallel original and translation indexes. Add a regression that checks the emitted tables and translation correspondence with UTF-8 and cp1252 contexts and plural messages.

Validation: the new regression fails on the original source; all 6 MO tests and the complete suite (7,829 passed, 10 skipped, 2 xfailed) pass after the fix. Project Ruff and whitespace/debug hooks and sdist/wheel builds passed.

Specification: https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html

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