master is red: test_po_files fails on the new Azerbaijani translation
Problem
python_tests fails on master itself, so every open PR is red. Currently failing on #13741, #13747, #13749 and #13751 — none of which touch i18n.
FAILED test_po_files.py::test_html_format[az-For example, if you want to prevent edits containing the domain <code>t.co</code>...]
FAILED test_po_files.py::test_html_format[az-One moment... It looks like we already have <em>some potential matches</em>...]
FAILED test_po_files.py::test_html_format[az-<a href="%(daisy_url)s"><strong>Download the DAISY.zip</strong></a>...]
Started with #13704 (merged 2026-09-28), the first Azerbaijani translation. The translation looks correct to me — it surfaced two pre-existing problems.
Cause 1 — the test forbids reordering (2 of the 3)
trees_equal walks children pairwise:
# openlibrary/i18n/test_po_files.py:36-38
assert len(el1) == len(el2)
for c1, c2 in zip(el1, el2):
trees_equal(c1, c2)
so a translation must keep the English element order. Azerbaijani puts the author before the title, and the link destination before the link text:
msgid "...we already have <em>some potential matches</em> for <b>%(title)s</b> by <b>%(author)s</b>."
msgstr "...Görünür, <b>%(author)s</b> müəllifinin <b>%(title)s</b> əsəri üçün artıq <em>bəzi mümkün uyğunluqlar</em> var."
zip pairs English <em> against Azerbaijani <b> and fails.
This contradicts our own guidance in AGENTS.md:
use single, unified translatable strings with Python formatting placeholders … so translators can position links according to the target language's grammatical structure
The test can still verify the same elements appear, with the same tags and attribute names, without requiring the same order.
Cause 2 — a control character in a source string (1 of the 3)
openlibrary/templates/admin/spamwords.html:16:
$:_('... add <code>(\b|https://|http://)t\\.co</code> to the spamwords list.')
\b is meant as a literal regex word boundary, but Python reads it as \x08 (backspace). \\. on the same line is escaped correctly; \b was missed. A backspace is not valid XML, so ET.fromstring raises ParseError: not well-formed (invalid token): line 1, column 143.
Latent since the string was written — az is simply the first locale to translate it. Fix is \\b.
cc @jamalkamaladdin — nothing wrong with your translation, it exposed these.
Reproducing the bug
On clean master (75eaea434), with no other changes:
git switch master
docker compose run --rm home make test-py PYTEST_ARGS="openlibrary/i18n/test_po_files.py"
- Expected behavior: tests pass on master
- Actual behavior:
3 failed, 2882 passed
Context
* Browser: n/a
* OS: Ubuntu (WSL2)
* Logged in (Y/N): n/a
* Environment: local, and CI on every open PR
Breakdown
Cause 2 is unambiguous — one character in one template — and I am happy to send that now.
Cause 1 is a judgement call: make trees_equal order-insensitive, or require
translators to preserve element order. I lean order-insensitive, since our i18n
guidance explicitly tells translators to reposition. Happy to implement
whichever you prefer.
Requirements Checklist
- [ ]
\b→\\binopenlibrary/templates/admin/spamwords.html - [ ] Decide whether
trees_equalshould compare element order - [ ]
make test-pygreen on master
Related files
openlibrary/i18n/test_po_files.pyopenlibrary/templates/admin/spamwords.htmlopenlibrary/i18n/az/messages.po
Tested both fixes locally:
trees_equalsorting children by(tag, len(e), sorted attribute names)before comparing: 3 failed → 1 failed- plus
\b→\\binspamwords.html: green
Happy to open a PR with both if that approach looks right. The sort key is the part worth a second opinion — it treats two sibling elements as interchangeable when they have the same tag, the same number of children and the same attribute names, which is enough to catch a translator dropping or inventing an element while still letting them reposition.
Thanks for the issue! Fixed by https://github.com/internetarchive/openlibrary/pull/13757