Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Qt front end: ask Windows for the ISO language code, and regenerate the language table
LNPANDY49801f7dac01
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex aa326231..d8f0948f 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -227,6 +227,14 @@ jobs:# Pure Python: the Windows toolchain, IPA and shim logic with the system calls mocked; the few tests that need PySide6 skip without it- name: Testsrun: python -m unittest discover -s frontend-qt/tests -v+ # The Qt table is generated from the SwiftUI one and says so at its top. A string added to+ # Localization.swift without regenerating it left 18 keys missing here for a day (a source run+ # of the Qt app shows those as raw keys), so the regeneration is the check: any difference+ # means the committed table is stale.+ - name: The Qt language table matches Localization.swift+ run: |+ python frontend-qt/gen_localization.py+ git diff --exit-code -- frontend-qt/nspb_qt/localization.pytriage-scripts:name: Triage script tests (.github/scripts)diff --git a/frontend-qt/nspb_qt/i18n.py b/frontend-qt/nspb_qt/i18n.pyindex 93a88286..0ff7227e 100644--- a/frontend-qt/nspb_qt/i18n.py+++ b/frontend-qt/nspb_qt/i18n.py@@ -41,13 +41,19 @@ class Lang(Enum):# (the Windows report of "the exe is still not Chinese").import ctypestry:- lang = ctypes.windll.kernel32.GetUserDefaultUILanguage() & 0xFF # primary id+ lang = ctypes.windll.kernel32.GetUserDefaultUILanguage() & 0x3FF # LANGID: the primary languagebuf = ctypes.create_unicode_buffer(85)- if ctypes.windll.kernel32.GetLocaleInfoW(lang, 0x00000002, buf, 85): # LOCALE_SISO639LANGNAME- low = buf.value.lower()+ # LOCALE_SISO639LANGNAME (0x59) is the ISO 639 code ("zh", "sv", "de"). 0x02 (LOCALE_SLANGUAGE)+ # is the *localized display name* — "中文(简体,中国)" — so a Chinese Windows never matched+ # the prefix test here and the early return handed that user an English interface.+ if ctypes.windll.kernel32.GetLocaleInfoW(lang, 0x00000059, buf, 85):+ low = buf.value.strip().lower()if low.startswith('zh'):return Lang.ZH- return Lang.SV if low.startswith('sv') else Lang.EN+ if low.startswith('sv'):+ return Lang.SV+ if low: # a real code we do not translate: this device is neither+ return Lang.ENexcept Exception:pass # fall through to the environmenttry:diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.pyindex d0fa8274..43f81568 100644--- a/frontend-qt/nspb_qt/localization.py+++ b/frontend-qt/nspb_qt/localization.py@@ -542,6 +542,15 @@ TABLE: dict[str, tuple[str, str, str]] = {'data.change': ('更换…', 'Change…', 'Ändra …'),'data.noBase': ('这个文件夹里没有本体 NSP([xxxx…000])', 'No base game NSP in this folder ([xxxx…000])', 'Det finns ingen NSP för grundspelet ([titel-id…000]) i den här mappen'),'data.noNsp': ('这个文件夹里没有 NSP/XCI', 'No NSP/XCI in this folder', 'Ingen NSP/XCI i den här mappen'),+ 'data.notSelectedDlc': ('未选择(可选,可一次选择多个文件)', 'Not selected (optional, several files can be selected)', 'Inte vald (valfri, flera filer kan väljas)'),+ 'data.updateNewest': ('v%d,共 %d 个更新中最新的一个。更新包含之前所有更新的内容。', 'v%d, the newest of %d. An update contains the earlier ones.', 'v%d, den senaste av %d. En uppdatering innehåller de tidigare.'),+ 'data.rowNotBase': ('%@ 不是本体(标题 ID %@)。本体的标题 ID 以 000 结尾。', "%@ is not a base game (title ID %@). A base game's title ID ends in 000.", '%@ är inte ett grundspel (titel-id %@). Ett grundspels titel-id slutar på 000.'),+ 'data.rowNotUpdate': ('%@ 不是更新(标题 ID %@)。更新的标题 ID 以 800 结尾。', "%@ is not an update (title ID %@). An update's title ID ends in 800.", '%@ är inte en uppdatering (titel-id %@). En uppdatering har ett titel-id som slutar på 800.'),+ 'data.rowNotDLC': ('%@ 不是 DLC(标题 ID %@)。DLC 的标题 ID 不以 000 或 800 结尾。', '%@ is not DLC (title ID %@). DLC does not end in 000 or 800. Those are the base game and its update.', '%@ är inte DLC (titel-id %@). DLC slutar inte på 000 eller 800, de är grundspelet och uppdateringen.'),+ 'data.rowOtherGame': ('%@ 属于另一个游戏,不是所选的本体。', '%@ belongs to another game than the selected base game.', '%@ hör till ett annat spel än det valda grundspelet.'),+ 'data.dlcPanelMessage': ('选择一个或多个 DLC 文件(按住 ⌘ 点按可多选)', 'Select one or more DLC files (hold ⌘ and click to select several)', 'Välj en eller flera DLC-filer (håll ⌘ och klicka för att välja flera)'),+ 'data.dlcPanelPrompt': ('添加 DLC', 'Add DLC', 'Lägg till DLC'),+ 'data.updatePanelMessage': ('选择最新的更新。更新包含之前所有更新的内容。', 'Select the newest update. An update contains the earlier ones.', 'Välj den senaste uppdateringen. En uppdatering innehåller de tidigare.'),'build.start': ('开始构建', 'Start build', 'Starta bygget'),'notify.doneTitle': ('%@ 构建完成', '%@ is built', '%@ är byggt'),'notify.failedTitle': ('%@ 构建失败', '%@ couldn’t be built', '%@ kunde inte byggas'),@@ -554,9 +563,18 @@ TABLE: dict[str, tuple[str, str, str]] = {'onboarding.error.xcode': ('Xcode 设置未能完成。', 'Xcode setup could not finish.', 'Xcode-inställningen kunde inte slutföras.'),'onboarding.error.metal': ('Metal 工具链未能下载。请检查网络后重试。', 'The Metal Toolchain could not be downloaded. Check your connection and try again.', 'Metal-verktygskedjan kunde inte hämtas. Kontrollera anslutningen och försök igen.'),'onboarding.error.ios': ('iOS 平台未能下载。请检查网络和磁盘空间后重试。', 'The iOS platform could not be downloaded. Check your connection and disk space, then try again.', 'iOS-plattformen kunde inte hämtas. Kontrollera anslutningen och ledigt utrymme och försök igen.'),+ 'launch.frameTimes': ('帧时间', 'Frame times', 'Bildtider'),+ 'launch.frameTimesRecord': ('录制帧时间', 'Record frame times', 'Spela in bildtider'),+ 'launch.frameTimesNote': ('开着时每次 Play 都记一份:每帧一行,帧时间、上屏时间和 GPU 时间,用来找卡顿和慢的地方。关着时不记录。', 'While on, every Play writes one: a row per frame with its frame time, time on screen and GPU time, to find stutters and slow places. Nothing is recorded while off.', 'När det är på sparas en inspelning för varje Spela: en rad per bildruta med dess bildtid, tid på skärmen och GPU-tid, för att hitta hack och långsamma ställen. Inget spelas in när det är av.'),+ 'launch.frameTimesNone': ('还没有记录', 'No recordings yet', 'Inga inspelningar ännu'),+ 'launch.frameTimesEmpty': ('这份记录还没有帧(游戏刚开始,或没有画面)', 'No frames in this recording yet (the game just started, or showed nothing)', 'Inga bildrutor i den här inspelningen ännu (spelet har just startat eller visade ingenting)'),+ 'launch.frameTimesOpen': ('打开文件夹', 'Open folder', 'Öppna mapp'),+ 'launch.frameTimesSummary': ('%d 帧 · %.0f fps · 中位 %.1f ms · 99%% %.1f ms · 最慢 %.0f ms · 卡顿 %d · 丢帧 %d', '%d frames · %.0f fps · median %.1f ms · 99%% %.1f ms · slowest %.0f ms · hitches %d · dropped %d', '%d bildrutor · %.0f fps · median %.1f ms · 99 %% %.1f ms · långsammast %.0f ms · hack %d · tappade %d'),'settings.notify': ('构建完成时通知', 'Notify when a build ends', 'Meddela när ett bygge är klart'),'settings.notifyNote': ('仅在 NX2Apple 不在前台时,构建完成或失败都会通知', 'When a build finishes or fails while NX2Apple is in the background', 'När ett bygge blir klart eller misslyckas medan NX2Apple körs i bakgrunden'),'settings.notifyUnbundled': ('需要 NX2Apple.app:用 swift run 启动时没有通知', 'Needs NX2Apple.app: no notifications when started with swift run', 'NX2Apple.app krävs: inga notiser när appen startas med swift run'),+ 'settings.returnAfterPlay': ('游戏退出后回到启动器', 'Come back when a game quits', 'Kom tillbaka när ett spel avslutas'),+ 'settings.returnAfterPlayNote': ('从游戏库点 Play 或在主机模式里启动的游戏退出时,启动器回到前台,可以接着选下一个游戏', 'When a game started with Play or in console mode quits, the launcher comes to the front to pick the next one', 'När ett spel som startats med Spela eller i konsolläget avslutas kommer startprogrammet fram, så att du kan välja nästa'),'build.cancel': ('取消构建', 'Cancel build', 'Avbryt bygget'),'msg.macAppDone': ('Mac App 已生成,可在访达里双击运行', 'Mac app ready — double-click it in the Finder', 'Mac-appen är klar. Dubbelklicka på den i Finder.'),'msg.macAppMissing': ('构建结束但没有找到 .app(仓库里缺 dm/mac/pack_app.py?)', 'Build finished but no .app was produced (is dm/mac/pack_app.py in the checkout?)', 'Bygget blev klart men ingen .app hittades. Saknas dm/mac/pack_app.py i förrådet?'),diff --git a/frontend-qt/tests/test_i18n_detect.py b/frontend-qt/tests/test_i18n_detect.pyindex 60b76fc6..57472a3c 100644--- a/frontend-qt/tests/test_i18n_detect.py+++ b/frontend-qt/tests/test_i18n_detect.py@@ -69,6 +69,35 @@ class Detect(unittest.TestCase):mock.patch.object(sys, 'platform', 'win32'):self.assertEqual(Lang.initial(), Lang.ZH)+ def win_language(self, kind_value: str, langid: int = 0x04) -> tuple[Lang, list[int]]:+ """Lang.initial() on Windows, with GetLocaleInfoW answering `kind_value`; the kinds it was asked for come back too."""+ asked: list[int] = []+ fake = mock.Mock()+ fake.windll.kernel32.GetUserDefaultUILanguage.return_value = langid++ def getlocale(lang, kind, buf, n):+ asked.append(kind)+ buf.value = kind_value+ return 1+ fake.windll.kernel32.GetLocaleInfoW.side_effect = getlocale+ with mock.patch.dict(os.environ, {}, clear=True), \+ mock.patch.dict(sys.modules, {'ctypes': fake}), \+ mock.patch('locale.getlocale', return_value=('English_United States', None)), \+ mock.patch.object(sys, 'platform', 'win32'):+ return Lang.initial(), asked++ def test_windows_is_asked_for_the_iso_language_code(self):+ """LOCALE_SISO639LANGNAME (0x59), not LOCALE_SLANGUAGE (0x02): 0x02 answers the *localized display+ name* ("中文(简体,中国)"), so a Chinese Windows fell through to English and nobody noticed because the+ call was only mocked for its return value."""+ _, asked = self.win_language('zh')+ self.assertEqual(asked, [0x00000059], "the ISO 639 code is what the prefix test can read")++ def test_a_windows_display_name_still_selects_the_language(self):+ for name, want in (('zh', Lang.ZH), ('zh-Hans', Lang.ZH), ('sv', Lang.SV), ('de', Lang.EN), ('en-US', Lang.EN)):+ lang, _ = self.win_language(name)+ self.assertEqual(lang, want, name)+def test_an_empty_locale_falls_through_to_the_environment(self):self.assertEqual(detect('', env={'LANG': 'zh_CN.UTF-8'}), Lang.ZH)self.assertEqual(detect('', env={'LANG': 'en_US.UTF-8'}), Lang.EN)