Repository navigation
MOBI: do not take the region of a different language in mobi2iana - #3453
Merged
kovidgoyal merged 1 commit intoNov 5, 2026
Merged
Conversation
mobi2iana() set the region suffix whenever any language's entry had the requested sub language number, not only entries of the requested language. A language with no entry for that sub language therefore kept the region of an earlier language, for example mobi2iana(7, 4) returned 'de-sa' (German, with the Saudi Arabia region of Arabic) instead of 'de'. Only look for the sub language among the entries of the matching language, and add a test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mobi2iana()sets the region suffix whenever any language's entry inIANA_MOBIhas the requested sub language number, not only the entries of the requested language:If the requested language has no entry for that sub language,
suffixkeeps the value from an earlier language. For examplemobi2iana(7, 4)returns'de-sa'(German with the Saudi Arabia region from Arabic's(1, 4)) instead of'de', and(25, 8)gives'ru-pt',(26, 12)'hr-ca'. This moves the sub language check inside the language match. Entries that exist are unchanged:(9, 4)is still'en-us',(7, 8)'de-ch',(4, 12)'zh-hk'.I added
test_mobi2ianatoTestLocaleNamesinsrc/calibre/utils/localization_test.py, since that module'sfind_testsis already registered.I did not touch the caller in
mobi/reader/headers.py, which passes the plain sub language while the table stores it shifted by two bits. That looks like a separate question.I couldn't run calibre locally, so I ran the CI on a fork:
AssertionError: 'de-sa' != 'de'/Failed for: 7, 4intest_mobi2iana(OK: 969 FAIL: 1). The macOS and Windows jobs of that run were cancelled after the failure.The commit in this PR is the squashed form of the fix branch (identical tree).