You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(i18n): normalize language codes before lookup, guard unknown locale
Both from the cross-family review of this PR.
Canonicalization ran *after* the locale-table lookup, so the two passes are
collapsed into one that normalizes /B -> /T before anything is looked up.
Previously a locale table that ever gained a 'ger' key would capture the code
in the first pass and store it verbatim -- a code the rest of the stack cannot
render -- and would stop de-duplicating a book that declares both 'ger' and
'deu'. The shipped tables are /T-only so this was latent, not live; the point
is not to depend on that holding forever.
Collapsing the passes surfaced that names.items() on an unrecognised locale
had always raised AttributeError, even though get_language_names() is
documented to return None for one and get_language_name() already guards it.
The validator guards it too now and falls through to the reference table, so
the book imports instead of 500-ing the request.
Tests, also from the review:
- edit_book_languages(upload_mode=True) is now under test. It is the only
production caller and the place remainder becomes the reporter's ValueError,
and nothing exercised it -- every helper test could stay green while a
refactor stopped passing upload_mode or mishandled the remainder loop.
- Replaced the canonical_lang_code monkeypatch test, which only proved the
helper was called and would pass if it mapped everything to 'eng', with a
public-boundary test that pins the ordering invariant above.
- test_alias_targets_resolve_through_the_language_backend claimed to run on
either backend but asserted pycountry's specific AttributeError; it now
asserts the semantic condition and tolerates the backend's miss form.
- Added test_reference_table_is_the_superset_of_every_locale, the property
that makes the reference table a valid oracle, and reworded its docstring,
which implied an ISO registry rather than generated application data.
Kept the three _resolve_lang_code empty-entry tests the review called
opportunistic: they pin a contract the docstring now states, and a documented
invariant with no test is the drift risk.
0 commit comments