Merge task/zhlang: map zh-CN and zh-TW to the Chinese codes TotK accepts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-30 13:27:46 +03:00
commit 184d5798cd
9 files changed
+37 -16

No files matched your search

+3 -2
View File
@@ -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()
+12 -4
View File
@@ -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 = <lang>`; see the module docstring."""
"""text with `lang = <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)
+1 -1
View File
@@ -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:
-2
View File
@@ -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)"
}
-2
View File
@@ -166,8 +166,6 @@
"lang.pt-BR": "Португальский (Бразилия)",
"lang.ru": "Русский",
"lang.ko": "Корейский",
"lang.zh-CN": "Китайский (упрощённый, КНР)",
"lang.zh-TW": "Китайский (традиционный, Тайвань)",
"lang.zh-Hans": "Китайский (упрощённый)",
"lang.zh-Hant": "Китайский (традиционный)"
}
+3 -1
View File
@@ -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);
+7 -3
View File
@@ -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);
+1 -1
View File
@@ -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];
+10
View File
@@ -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)