Skip to content

Qt front end: ask Windows for the ISO language code, and regenerate the language table - #256

Merged
LNPANDY merged 1 commit into
mainfrom
fix/qt-locale-and-table
Oct 30, 2026
Merged

LNPANDY merged 1 commit into
mainfrom
fix/qt-locale-and-table

Conversation

@LNPANDY

@LNPANDY LNPANDY commented Oct 30, 2026

Copy link
Copy Markdown
Owner

What and why

Two bugs found reviewing #222 against current main.

A Chinese Windows got an English Qt interface. frontend-qt/nspb_qt/i18n.py asked GetLocaleInfoW for 0x00000002, commented as LOCALE_SISO639LANGNAME. 0x02 is LOCALE_SLANGUAGE, the localized display name: on a Chinese Windows it answers 中文(简体,中国), the startswith('zh') test failed, and the early return chose English — so the fix described in the comment above the call never actually worked. The ISO 639 name is 0x59. The LANGID is also now masked with 0x3FF (the primary language) instead of 0xFF.

The Qt table was 18 keys behind the Swift one. #246 (823ca8b) added keys to Localization.swift without running gen_localization.py. Invisible in the Windows bundle (it regenerates before packaging), but a source run of the Qt app showed those as raw keys. Regenerated here.

The Qt test job now regenerates the table and fails on any difference, so this cannot drift again:

python frontend-qt/gen_localization.py
git diff --exit-code -- frontend-qt/nspb_qt/localization.py

Checked

  • python -m unittest discover -s frontend-qt/tests — 179 tests OK.
  • New test_windows_is_asked_for_the_iso_language_code asserts the constant handed to the API (the old test mocked only the answer, which is exactly how 0x02 survived); test_a_windows_display_name_still_selects_the_language covers zh, zh-Hans, sv, de, en-US.
  • Not checked: a real Windows run. The API call is exercised through a mocked ctypes, as the existing tests do; the Windows bundle job builds and runs on tags only.

Scope

  • frontend-qt/ and .github/workflows/tests.yml only — no vendored file (dm/, scripts/, docs/, ref/, AGENTS.md) touched
  • No keys, game files or data extracted from a game

…he language table

Two bugs the PR review of #222 turned up in the current main:

- `nspb_qt/i18n.py` asked `GetLocaleInfoW` for `0x02`, which is LOCALE_SLANGUAGE,
  the *localized display name*. On a Chinese Windows that answer is
  "中文(简体,中国)", the prefix test for "zh" never matched, and the early return
  handed the user an English interface — the very report the comment above the call
  says was fixed. The ISO 639 code is `0x59`, and the LANGID is masked with 0x3FF
  (the primary language) rather than 0xFF.
- `nspb_qt/localization.py` was 18 keys behind `Localization.swift`: #246 added
  them to the Swift table without running `gen_localization.py`. They were never
  visible because the Windows bundle regenerates the table before packaging, but a
  source run of the Qt app showed the raw keys. Regenerated here.

The Qt test job now regenerates the table and fails on any difference, so a string
added to the Swift table cannot leave the Qt one stale again.

Tests: `python -m unittest discover -s frontend-qt/tests` 179 tests OK. New:
`test_windows_is_asked_for_the_iso_language_code` asserts the constant passed to the
API (the existing test mocked only the answer, which is how 0x02 survived), and
`test_a_windows_display_name_still_selects_the_language` covers zh/sv/de/en answers.
@github-actions github-actions Bot added windows Windows (the Qt front end) ci Workflows and repository tooling labels Oct 30, 2026

@v0lumehi v0lumehi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @LNPANDY, both findings are right, and the second one is on us: #246 added the strings without running gen_localization.py. The new check in the Qt job closes that gap for good.

Checked:

  • 0x59 is LOCALE_SISO639LANGNAME and 0x02 is LOCALE_SLANGUAGE (the localized display name), so the old call could never match zh on a Chinese Windows. The new test asserts the constant handed to the API, which is exactly what let 0x02 slip through before.
  • & 0x3FF is PRIMARYLANGID, the right mask for a LANGID. Passing that primary id to GetLocaleInfoW asks for the neutral locale (0x0004 for Chinese), which works on Vista and later. A small optional alternative is to pass the full LANGID unmasked, which is itself a valid LCID and avoids neutral locales entirely. Not a blocker.
  • The empty-answer case now falls through to the environment instead of returning English, which is better.

One thing to keep in mind with #225 (German): it adds Lang.DE to the Qt table, and test_a_windows_display_name_still_selects_the_language here expects de to give English. Whichever merges second needs a de branch in initial() and the test case changed to Lang.DE. I'll take care of that in #225 if this merges first, and #225 will also have to regenerate the table, which your new check now enforces.

Approving. As a fix it can merge once the remaining macOS jobs are green.

@v0lumehi v0lumehi mentioned this pull request Oct 30, 2026
3 tasks done
@LNPANDY
LNPANDY merged commit db4c692 into main Oct 30, 2026
9 checks passed
LNPANDY added a commit that referenced this pull request Oct 30, 2026
…n added

Rebased onto current main and resolved the generated Qt table by regenerating it
(gen_localization.py), so this keeps main's fixes rather than reverting them:

- the ISO language code Windows is asked for (0x59), from #256 — without it a
  German Windows would still fall through to English on the Qt side
- the 18 keys #246 added to the Swift table without regenerating the Qt one

Ten strings had no German, because main added them after this branch was cut:
`saves.macLibrary`, `saves.macStandard`, `saves.macPending`, `saves.noDevices`,
`saves.notConnected`, `saves.timeout`, `saves.device`, `fail.zbic.what`,
`fail.zbic.next` and `fail.zbic.button`. Two existing entries no longer matched
the current English (`saves.reading`, `saves.notInstalled`): the first was missing
its `%@`, the second still described an older sentence.

Tests: swift test 500 tests, 0 failures; python -m unittest discover -s
frontend-qt/tests 188 tests OK.
@v0lumehi
v0lumehi deleted the fix/qt-locale-and-table branch November 2, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Workflows and repository tooling windows Windows (the Qt front end)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants