From 67116a387fbd19948c46f9f68add98ecc39d9b39 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Fri, 30 Oct 2026 13:27:19 +0300 Subject: [PATCH] Map the zh-CN and zh-TW game languages to zh-Hans and zh-Hant Choosing Simplified Chinese in the installer wrote lang = zh-CN to totk.ini and the game showed Japanese: ov_language() handed the code to nn::oe::GetDesiredLanguage unchanged, and TotK only accepts zh-Hans and zh-Hant for Chinese. Reported in #72 and #68. ov_language() now maps both old spellings, so existing totk.ini files keep working and cfg.c still accepts them. The F1 menu offers one row per language under the canonical codes. The installer lists only zh-Hans and zh-Hant, writes them, and reads zh-CN or zh-TW from the CLI or from a recorded totk-install.json as the canonical code, so a repair or update of an old install does not fail with check.lang_unknown and rewrites the ini. --probe-services prints the configured language and checks the four Chinese codes. Co-Authored-By: Claude Opus 5.5 --- installer/gui.py | 5 +++-- installer/ini.py | 16 ++++++++++++---- installer/steps.py | 2 +- installer/text/en.json | 2 -- installer/text/ru.json | 2 -- runtime/ov_probe.c | 4 +++- runtime/ov_system.c | 10 +++++++--- runtime/ui/menu.cpp | 2 +- tests/installer_test.py | 10 ++++++++++ 9 files changed, 37 insertions(+), 16 deletions(-) diff --git a/installer/gui.py b/installer/gui.py index 391918de..bbda6a2d 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -266,8 +266,9 @@ class App: state = form.installed_state() if state is not None: self.update_hint.configure(text=self.cat('ui.update_mode')) - if state.get('lang') in ini.LANGUAGES and not self.lang_touched: - self.vars['lang'].set(self.lang_label(state['lang'])) + recorded = ini.canonical_language(state.get('lang')) + if recorded in ini.LANGUAGES and not self.lang_touched: + self.vars['lang'].set(self.lang_label(recorded)) else: self.update_hint.configure(text='') self.fit() diff --git a/installer/ini.py b/installer/ini.py index 6bcc341f..13147862 100644 --- a/installer/ini.py +++ b/installer/ini.py @@ -9,19 +9,27 @@ import os import re from pathlib import Path -# runtime/ov_system.c: the codes TOTK_LANG accepts. +# runtime/ov_system.c: the codes TOTK_LANG offers. Each language appears once, under the code the game accepts. LANGUAGES = ('ja', 'en-US', 'en-GB', 'fr', 'fr-CA', 'de', 'it', 'es', 'es-419', 'nl', 'pt', 'pt-BR', 'ru', 'ko', - 'zh-CN', 'zh-TW', 'zh-Hans', 'zh-Hant') + 'zh-Hans', 'zh-Hant') +# Older installer builds wrote these two codes; they are read as the canonical ones and rewritten on the next install. +ALIASES = {'zh-CN': 'zh-Hans', 'zh-TW': 'zh-Hant'} # Their text falls back to the Switch shared fonts (runtime/ov_system.c), which the installer does not extract. -NEED_SHARED_FONTS = ('ko', 'zh-CN', 'zh-TW', 'zh-Hans', 'zh-Hant') +NEED_SHARED_FONTS = ('ko', 'zh-Hans', 'zh-Hant') ACTIVE = re.compile(r'^(\s*)(?:totk_)?lang(\s*=\s*)(.*?)(\s*)$', re.IGNORECASE) COMMENTED = re.compile(r'^\s*[#;]\s*(?:totk_)?lang\s*=.*$', re.IGNORECASE) SECTION = re.compile(r'^\s*\[(.*)\]\s*$') +def canonical_language(lang): + """The code LANGUAGES lists for lang: an alias of an older installer build is mapped, anything else is kept.""" + return ALIASES.get(lang, lang) + + def set_language(text, lang): - """text with `lang = `; see the module docstring.""" + """text with `lang = ` (an alias written as its canonical code); see the module docstring.""" + lang = canonical_language(lang) lines = text.splitlines() for i, line in enumerate(lines): m = ACTIVE.match(line) diff --git a/installer/steps.py b/installer/steps.py index c7d9c40a..3984f784 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -203,7 +203,7 @@ class Check(Step): raise InstallError('check.dest_not_folder', path=str(dest)) if ctx.mode == 'install' and dest.is_dir() and any(dest.iterdir()): raise InstallError('check.dest_not_empty', path=str(dest)) - lang = ctx.options.lang or ctx.state.get('lang') + lang = ini.canonical_language(ctx.options.lang or ctx.state.get('lang')) if not lang: raise InstallError('check.lang_missing') if lang not in ini.LANGUAGES: diff --git a/installer/text/en.json b/installer/text/en.json index 92c24197..5964a0f6 100644 --- a/installer/text/en.json +++ b/installer/text/en.json @@ -166,8 +166,6 @@ "lang.pt-BR": "Portuguese (Brazil)", "lang.ru": "Russian", "lang.ko": "Korean", - "lang.zh-CN": "Chinese (Simplified, China)", - "lang.zh-TW": "Chinese (Traditional, Taiwan)", "lang.zh-Hans": "Chinese (Simplified)", "lang.zh-Hant": "Chinese (Traditional)" } diff --git a/installer/text/ru.json b/installer/text/ru.json index ad3e9666..c3a87db8 100644 --- a/installer/text/ru.json +++ b/installer/text/ru.json @@ -166,8 +166,6 @@ "lang.pt-BR": "Португальский (Бразилия)", "lang.ru": "Русский", "lang.ko": "Корейский", - "lang.zh-CN": "Китайский (упрощённый, КНР)", - "lang.zh-TW": "Китайский (традиционный, Тайвань)", "lang.zh-Hans": "Китайский (упрощённый)", "lang.zh-Hant": "Китайский (традиционный)" } diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index 487ca5da..4668bf0a 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -250,8 +250,10 @@ static void probe_oe(void) { {NULL, "en-US", "en-US"}, {NULL, "be-BY", "en-US"}, {NULL, "xx", "en-US"}, {NULL, "ja-JP", "ja"}, {NULL, "fr-CA", "fr-CA"}, {NULL, "es-MX", "es-419"}, {NULL, "es_ES", "es"}, {NULL, "zh-Hant-TW", "zh-Hant"}, {NULL, "zh-CN", "zh-Hans"}, {NULL, "en-GB", "en-GB"}, {NULL, "ru", "ru"}, {"ja", "fr-FR", "ja"}, - {"en-US", NULL, "en-US"}}; + {"en-US", NULL, "en-US"}, {"zh-CN", NULL, "zh-Hans"}, {"zh-TW", NULL, "zh-Hant"}, + {"zh-Hans", NULL, "zh-Hans"}, {"zh-Hant", NULL, "zh-Hant"}}; int bad = 0; + printf("oe: configured language (TOTK_LANG=%s) is %s\n", keep_lang ? keep_lang : "", lang()); for (size_t i = 0; i < sizeof cases / sizeof *cases; i++) { set_env("TOTK_LANG", cases[i].lang); set_env("TOTK_LOCALE", cases[i].locale); diff --git a/runtime/ov_system.c b/runtime/ov_system.c index d3d98878..c3b5c6f7 100644 --- a/runtime/ov_system.c +++ b/runtime/ov_system.c @@ -88,12 +88,16 @@ static const char *switch_language(const char *tag) { return "en-US"; } -// The game's language as a Switch language code (TOTK_LANG, else TOTK_LOCALE, else the Windows user locale). +// The game's language as a Switch language code (TOTK_LANG, else TOTK_LOCALE, else the Windows user locale). TotK +// accepts "zh-Hans" and "zh-Hant" for Chinese and falls back to Japanese for "zh-CN" and "zh-TW", so those two +// spellings, which older totk.ini files and menus wrote, are mapped to them. const char *ov_language(void) { - static const char *const codes[] = {"ja", "en-US", "fr", "de", "it", "es", "zh-CN", "ko", "nl", "pt", "ru", - "zh-TW", "en-GB", "fr-CA", "es-419", "zh-Hans", "zh-Hant", "pt-BR"}; + static const char *const codes[] = {"ja", "en-US", "fr", "de", "it", "es", "ko", "nl", "pt", "ru", + "en-GB", "fr-CA", "es-419", "zh-Hans", "zh-Hant", "pt-BR"}; const char *code = cfg_get("TOTK_LANG"); // no fixed default: TOTK_LOCALE or the Windows user locale decides when unset if (code && *code) { + if (!strcmp(code, "zh-CN")) return "zh-Hans"; + if (!strcmp(code, "zh-TW")) return "zh-Hant"; for (size_t i = 0; i < sizeof codes / sizeof *codes; i++) if (!strcmp(code, codes[i])) return codes[i]; rt_fatal("TOTK_LANG '%s' is not a Switch language code", code); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 64c3c4c0..ccb1bbb0 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -458,7 +458,7 @@ static void row_game_lang(void) { {"en-US", UI_MENU_LANGNAME_EN}, {"ja", UI_MENU_LANGNAME_JA}, {"fr", UI_MENU_LANGNAME_FR}, {"de", UI_MENU_LANGNAME_DE}, {"it", UI_MENU_LANGNAME_IT}, {"es", UI_MENU_LANGNAME_ES}, {"nl", UI_MENU_LANGNAME_NL}, {"ru", UI_MENU_LANGNAME_RU}, - {"zh-CN", UI_MENU_LANGNAME_ZH_HANS}, {"zh-TW", UI_MENU_LANGNAME_ZH_HANT}, {"ko", UI_MENU_LANGNAME_KO}, + {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT}, {"ko", UI_MENU_LANGNAME_KO}, }; enum { N = sizeof langs / sizeof *langs + 1 }; const char *vals[N], *names[N]; diff --git a/tests/installer_test.py b/tests/installer_test.py index d9d325e4..d7404929 100644 --- a/tests/installer_test.py +++ b/tests/installer_test.py @@ -217,6 +217,16 @@ class IniTest(unittest.TestCase): self.assertEqual(ini.set_language('[language]\nlocale = de-DE\n', 'fr'), '[language]\nlang = fr\nlocale = de-DE\n') + def test_old_chinese_codes_are_written_as_the_canonical_ones(self): + self.assertEqual(ini.canonical_language('zh-CN'), 'zh-Hans') + self.assertEqual(ini.canonical_language('zh-TW'), 'zh-Hant') + self.assertEqual(ini.canonical_language('ja'), 'ja') + self.assertNotIn('zh-CN', ini.LANGUAGES) + self.assertNotIn('zh-TW', ini.LANGUAGES) + out = ini.set_language(self.EXAMPLE, 'zh-CN') + self.assertEqual(ini.get_language(out), 'zh-Hans') + self.assertEqual(ini.get_language(ini.set_language(out, 'zh-TW')), 'zh-Hant') + def test_write_keeps_user_lines(self): with tempfile.TemporaryDirectory() as d: d = Path(d)