From 859ed28735cc349dd7563c9300c6ff7f4a6be9e3 Mon Sep 17 00:00:00 2001 From: tuwary <47059291+tuwary@users.noreply.github.com> Date: Sat, 31 Oct 2026 16:33:53 +0800 Subject: [PATCH] Add Simplified Chinese to the setup window and the in-game menu The setup window gets installer/text/zh-Hans.json, a full copy of the English catalog, and a third entry in its language switch. A Windows display language of zh-CN or zh-SG picks it; zh-TW, zh-HK and zh-MO write Traditional Chinese and stay on English. A Chinese window still starts with English as the game language, because Chinese game text needs the Switch shared fonts the installer does not extract. The launcher's message box and make_release.py's launcher_text.h carry the Chinese strings too. The menu and the performance overlay get a text_zh_hans table for every menu id, and TOTK_MENU_LANG takes zh-Hans. Left unset, the menu follows the system UI language with the same Simplified Chinese regions. The font atlas merges in every glyph of the menu language's text from the system font (Microsoft YaHei, else SimSun) and is built again when the menu language changes. ov_probe checks that every menu id has Chinese text, that the printf formats keep the English conversions, and how system language tags map to menu languages; installer_gui_test checks the new catalog the same way as the Russian one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DcYzeu7eb2tXZMU4bRVcGh --- README.md | 1 + docs/architecture.md | 4 +- docs/installer.md | 11 +- installer/gui.py | 14 +- installer/guilogic.py | 23 +++- installer/launcher/launcher.c | 14 +- installer/text/zh-Hans.json | 175 +++++++++++++++++++++++++ runtime/cfg.c | 2 +- runtime/ov_probe.c | 71 ++++++++--- runtime/ui/menu.cpp | 27 ++-- runtime/ui_text.c | 232 ++++++++++++++++++++++++++++++++-- runtime/ui_text.h | 12 +- tests/installer_gui_test.py | 48 +++++-- tools/make_release.py | 10 +- totk.ini.example | 4 +- 15 files changed, 574 insertions(+), 74 deletions(-) create mode 100644 installer/text/zh-Hans.json diff --git a/README.md b/README.md index 089d3f2b..560352d9 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ Report problems as issues, following [CONTRIBUTING.md](CONTRIBUTING.md). - 60 fps by default; up to 144 fps or the monitor's refresh rate (experimental) - Custom resolutions (1080p, 2k...), supersampling and AMD FSR 1 upscaling - In-game settings menu (F1) and performance overlay (F10) +- Setup and in-game menu in English, Russian and Simplified Chinese - Keyboard, mouse and gamepad with remapping, rumble and gyro - Xbox button prompts: a layout that keeps the Switch button positions and shows the Xbox labels - Shaders prepared at install instead of during play diff --git a/docs/architecture.md b/docs/architecture.md index 29967538..5fd80294 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -54,7 +54,9 @@ MacNativeGames cannot run on x86-64 as is: its CPU path executes ARM64 code nati libzstd on the host (`ov_zstd.c`, `TOTK_ZSTD_NATIVE`); the lifted decoder took almost three times as long. - Settings and menu: every key with its default is in one table (`cfg.c`), read from `totk.ini` and `TOTK_*` variables and written back when the in-game menu changes it. The menu and the performance overlay are Dear ImGui, - drawn into the swapchain image (`runtime/ui/`); their text is in `ui_text.c` (English, Russian). + drawn into the swapchain image (`runtime/ui/`); their text is in `ui_text.c` (English, Russian, Simplified Chinese). + The Chinese glyphs come from a system font (Microsoft YaHei, `plat_font_path`) merged into the font atlas for the menu + language. - OS calls the host makes go through `runtime/platform/` (`platform.h`, `win32.c`), so a Linux or macOS host adds one file instead of touching the rest. The split is not finished: `tools/check_platform.py` lists the Win32 uses left in the other files. #### Threads and cores diff --git a/docs/installer.md b/docs/installer.md index e6ad004c..cf123dd6 100644 --- a/docs/installer.md +++ b/docs/installer.md @@ -79,9 +79,12 @@ python -m installer --base FILE --update FILE --keys FILE --lang CODE --dest DIR the merged RomFS (15.9 GiB) before it deletes them. The check computes the exact figure. - Window (`python -m installer.gui`, `installer/gui.py` draws, `installer/guilogic.py` decides): form, step list with progress, space line, collapsible log, Cancel (Ctrl+Break to the CLI's process group, then it waits for the exit), - finish screen with Open folder. English or Russian, chosen from the Windows display language, switchable in the - window; every sentence is an id in `installer/text/.json`. A folder with `totk-install.json` needs only the - folder. `--selftest [--shots DIR]` builds every screen in both languages and closes itself. + finish screen with Open folder. English, Russian or Simplified Chinese, chosen from the Windows display language + (zh-CN and zh-SG give Chinese; the Traditional Chinese regions give English), switchable in the window; every + sentence is an id in `installer/text/.json`. A Chinese window still starts with English as the game + language, because Chinese game text needs the Switch shared fonts the installer does not extract. A folder with + `totk-install.json` needs only the folder. `--selftest [--shots DIR]` builds every screen in every language and + closes itself. - `tests/installer_gui_test.py`: event model, form, catalogs, cancel, the self-closing window and one end-to-end run of the CLI in `--verify` mode (needs `build/install-test` and `build/extracted/v121`; see its docstring). - `tests/installer_test.py`: bookkeeping with fake steps. `tests/installer_e2e.py`: a dev-mode run with the files of @@ -93,7 +96,7 @@ The unpacked release; `tools/make_release.py` assembles it and `--zip` packs it: ``` TotK-Setup.exe starts python/pythonw.exe -m installer.gui (installer/launcher/launcher.c, no console) -installer/ the installer: steps, CLI, window, en/ru text catalog +installer/ the installer: steps, CLI, window, en/ru/zh-Hans text catalog python/ Python 3.14.9 embeddable + numpy, lz4, cryptography, cffi, pycparser (+ tkinter for the window) recomp/, tools/ the lifter and the build, extraction and shader scripts the steps run (copied from the repo) llvm/ llvm-mingw, x86_64-only subset (Apache-2.0 with LLVM exception; mingw-w64 parts permissive) diff --git a/installer/gui.py b/installer/gui.py index bbda6a2d..c93215db 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -2,10 +2,10 @@ A front end over the CLI (docs/installer.md): it collects the game files, the keys file path, the game language and the install folder, runs `python -m installer ...` as a subprocess and shows its JSON events. Decisions live in guilogic.py; -this file only draws. The window text is in installer/text/.json under "ui.*" and "launcher.*" ids. +this file only draws. The window text is in installer/text/.json under "ui.*" and "launcher.*" ids. - --selftest [--shots DIR] build every screen in both languages and close by itself (PNG per screen with --shots) - --lang en|ru window language (default: the Windows display language) + --selftest [--shots DIR] build every screen in every language and close by itself (PNG per screen with --shots) + --lang en|ru|zh-Hans window language (default: the Windows display language) """ import argparse import json @@ -22,8 +22,8 @@ except ImportError: from . import ini from . import layout as layouts -from .guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, UI_LANGUAGES, Catalog, Form, Model, Process, - amount, default_game_language, describe_event, parse_line, windows_ui_language) +from .guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, UI_LANGUAGE_LABELS, UI_LANGUAGES, Catalog, Form, Model, + Process, amount, default_game_language, describe_event, parse_line, windows_ui_language) POLL_MS = 100 GLYPH = {PENDING: '\u25cb', RUNNING: '\u25b6', DONE: '\u2714', SKIPPED: '\u2013', FAILED: '\u2716'} @@ -78,7 +78,7 @@ class App: sw.pack(side='right') self.ui_var = tk.StringVar(value=self.cat.lang) for code in UI_LANGUAGES: - ttk.Radiobutton(sw, text=code.upper(), value=code, variable=self.ui_var, style='Toolbutton', + ttk.Radiobutton(sw, text=UI_LANGUAGE_LABELS[code], value=code, variable=self.ui_var, style='Toolbutton', command=self.switch_language).pack(side='left', padx=1) self.body = ttk.Frame(root, padding=PAD) self.body.pack(fill='both', expand=True) @@ -523,7 +523,7 @@ def grab(root, path): def selftest(layout, shots=None): - """Every screen in both languages; the window closes itself. Returns 0 when nothing raised.""" + """Every screen in every language; the window closes itself. Returns 0 when nothing raised.""" fix_tcl_paths() root = tk.Tk() root.geometry('+60+40') diff --git a/installer/guilogic.py b/installer/guilogic.py index 7d517024..6f9157ab 100644 --- a/installer/guilogic.py +++ b/installer/guilogic.py @@ -23,11 +23,16 @@ from . import state as statefile from .events import render TEXT = Path(__file__).resolve().parent / 'text' -UI_LANGUAGES = ('en', 'ru') +UI_LANGUAGES = ('en', 'ru', 'zh-Hans') +# what the language switch in the window's corner shows for each +UI_LANGUAGE_LABELS = {'en': 'EN', 'ru': 'RU', 'zh-Hans': '中文'} STEP_ORDER = ('check', 'extract', 'lift', 'compile', 'prepare', 'cleanup') # message parameter -> catalog id prefix of the names that replace its raw values PARAM_NAMES = {'lang': 'lang.', 'known': 'lang.', 'step': 'step.', 'input': 'param.input.'} LANG_RU = 0x19 # primary language id of Russian in a Windows LANGID +# Windows LANGIDs that write Simplified Chinese: zh-CN, zh-SG. zh-TW, zh-HK and zh-MO write Traditional Chinese, which +# the window does not have. +LANGIDS_ZH_HANS = (0x0804, 0x1004) def load_texts(lang): @@ -75,15 +80,27 @@ def flat(value): def windows_ui_language(): - """'ru' when the Windows display language is Russian, else 'en'.""" + """The window language for the Windows display language (ui_language_for_langid).""" try: langid = ctypes.windll.kernel32.GetUserDefaultUILanguage() except (AttributeError, OSError): return 'en' - return 'ru' if langid & 0x3ff == LANG_RU else 'en' + return ui_language_for_langid(langid) + + +def ui_language_for_langid(langid): + """'ru' for a Russian Windows LANGID, 'zh-Hans' for a Simplified Chinese one, else 'en'.""" + if langid & 0x3ff == LANG_RU: + return 'ru' + if langid in LANGIDS_ZH_HANS: + return 'zh-Hans' + return 'en' def default_game_language(ui): + """The game language the form starts with. A Chinese window still starts with English: Chinese game text needs + the Switch shared fonts (ini.NEED_SHARED_FONTS), which the installer does not extract, and the game stops when + they are missing; the player can still pick Chinese.""" return 'ru' if ui == 'ru' else 'en-US' diff --git a/installer/launcher/launcher.c b/installer/launcher/launcher.c index 11994cd9..9571b70f 100644 --- a/installer/launcher/launcher.c +++ b/installer/launcher/launcher.c @@ -12,11 +12,19 @@ #define LANGID_RUSSIAN 0x19 #define PATH_CHARS (MAX_PATH * 2) +/* The language of the window (installer/guilogic.py ui_language_for_langid): Russian, Simplified Chinese (zh-CN and + zh-SG; the Traditional Chinese regions get English, as the window has no Traditional Chinese), else English. */ static void fail(void) { - int russian = (GetUserDefaultUILanguage() & 0x3ff) == LANGID_RUSSIAN; - MessageBoxW(NULL, russian ? LAUNCHER_PYTHON_MISSING_RU : LAUNCHER_PYTHON_MISSING_EN, - russian ? LAUNCHER_TITLE_RU : LAUNCHER_TITLE_EN, MB_OK | MB_ICONERROR); + LANGID ui = GetUserDefaultUILanguage(); + int russian = (ui & 0x3ff) == LANGID_RUSSIAN; + int chinese = ui == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) || + ui == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE); + MessageBoxW(NULL, + russian ? LAUNCHER_PYTHON_MISSING_RU : chinese ? LAUNCHER_PYTHON_MISSING_ZH_HANS + : LAUNCHER_PYTHON_MISSING_EN, + russian ? LAUNCHER_TITLE_RU : chinese ? LAUNCHER_TITLE_ZH_HANS : LAUNCHER_TITLE_EN, + MB_OK | MB_ICONERROR); } int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR command_line, int show) diff --git a/installer/text/zh-Hans.json b/installer/text/zh-Hans.json new file mode 100644 index 00000000..54facdea --- /dev/null +++ b/installer/text/zh-Hans.json @@ -0,0 +1,175 @@ +{ + "step.check": "检查电脑和游戏文件", + "step.extract": "解包游戏", + "step.lift": "将游戏代码转换为 C 代码", + "step.compile": "编译 totk.exe", + "step.prepare": "准备着色器", + "step.cleanup": "清理", + + "phase.check.host": "检查处理器和显卡", + "phase.check.verify": "检查已安装的文件", + "phase.check.verify_romfs": "检查已安装的游戏数据", + "phase.check.inputs": "用密钥打开游戏文件", + "phase.check.versions": "检查游戏版本", + "phase.extract.hash_base": "计算游戏本体的校验和", + "phase.extract.hash_update": "计算更新的校验和", + "phase.extract.exefs": "解包游戏代码", + "phase.extract.copy": "复制游戏数据", + "phase.extract.merge": "将更新应用到游戏数据", + "phase.extract.diagnose": "查找损坏的游戏文件", + "phase.extract.index": "校验游戏数据", + "phase.lift.discover": "查找函数", + "phase.lift.emit": "生成 C 代码", + "phase.compile.compile": "编译", + "phase.compile.link": "链接 totk.exe", + "phase.prepare.romfs_patches": "写入 60 帧游戏数据补丁", + "phase.prepare.seed": "从游戏数据中读取着色器", + "phase.prepare.translate": "转译着色器", + "phase.prepare.libraries": "为显卡驱动构建着色器", + "phase.prepare.pack": "将着色器缓存打包成一个文件", + "phase.cleanup.ini": "写入 totk.ini", + "phase.cleanup.temp": "删除临时文件", + + "cli.usage": "命令行无效:{detail}", + "internal": "意外错误({exception}):{detail}", + "state.unreadable": "无法读取 {path}。请选择其他文件夹,或删除该文件。", + "state.newer_format": "{path} 是由更新版本的安装程序写入的。请使用那个安装程序,或选择其他文件夹。", + "state.output_changed": "步骤“{step}”生成的已安装文件在生成后被改动过;该步骤将重新运行。", + + "check.release_incomplete": "安装程序文件夹不完整,缺少:{paths}。请重新解压发布包。", + "check.dest_not_folder": "安装位置 {path} 是一个文件,而不是文件夹。", + "check.dest_not_empty": "安装文件夹 {path} 不是空的,其中也没有之前的安装。请选择一个空文件夹。", + "check.lang_missing": "请选择游戏语言。", + "check.lang_unknown": "未知语言“{lang}”。可用语言:{known}。", + "check.toolchain_broken": "自带的编译器无法工作:{detail}", + "check.host_probe_failed": "电脑检查未能运行(退出代码 {code})。", + "check.cpu_no_avx2": "此处理器不支持游戏所需的 AVX2(x86-64-v3)。Intel Haswell(2013 年)或 AMD Excavator / Zen 及更新的处理器才支持。", + "check.vulkan_missing": "未安装 Vulkan 驱动。请为你的显卡安装最新的驱动程序。", + "check.vulkan_no_device": "Vulkan 找不到显卡。请为你的显卡安装最新的驱动程序。", + "check.vulkan_too_old": "游戏需要支持 Vulkan 1.3 的显卡;检测到:{devices}。请更新显卡驱动程序。", + "check.inputs_needed": "需要游戏文件:请选择游戏本体、1.2.1 或 1.4.3 更新以及 prod.keys。", + "check.input_missing": "找不到文件({input}):{path}", + "check.keys_unreadable": "无法读取密钥文件。请选择一个 prod.keys 文件。", + "check.keys_no_header_key": "密钥文件中没有 header_key。请从你的主机重新导出 prod.keys。", + "check.keys_wrong": "这些密钥无法打开{input}文件。请使用你自己主机的 prod.keys。", + "check.keys_too_old": "密钥文件对{input}文件来说太旧(需要密钥代数 {generation})。请从固件更新的主机导出 prod.keys。", + "check.not_game_file": "{input}文件不是 XCI 或 NSP 游戏文件。", + "check.file_unreadable": "无法读取{input}文件:{detail}", + "check.ticket_personalized": "{input}文件带有个人化票据(personalized ticket);需要通用票据(common ticket)。", + "check.ticket_missing": "{input}文件缺少其内容所需的票据(ticket)。", + "check.base_not_totk": "游戏本体文件不是《塞尔达传说 王国之泪》({detail})。", + "check.update_not_nsp": "更新必须是 NSP 文件。", + "check.update_is_base": "更新文件里是游戏本体。请选择 1.2.1 或 1.4.3 的更新 NSP。", + "check.update_not_totk": "更新文件不是《王国之泪》的更新({detail})。", + "check.exefs_failed": "{input}文件的游戏代码未通过检查;详见 {log}。", + "check.input_damaged": "{input}文件已损坏或不完整:{path}({detail})。请从来源重新复制该文件或重新导出,然后再次运行安装程序。", + "check.base_wrong_version": "游戏本体不是 1.0.0 版本({modules} 不一致)。", + "check.update_wrong_version": "更新的版本是 {found};此发布版需要 {wanted}。", + "check.disk_space": "{path} 的可用空间不足:需要 {need_gb} GB,可用 {free_gb} GB。", + + "extract.exefs_mismatch": "解包出的游戏代码与 {version} 版本不符({modules})。", + "extract.romfs_merge_failed": "将更新应用到游戏数据失败:{detail}。详情:{log}", + "extract.romfs_mismatch": "解包出的游戏数据与 {version} 版本不符(大小 {size},校验和 {sha256}...)。", + "lift.failed": "游戏代码转换失败(退出代码 {code})。详情:{log}", + "compile.failed": "编译 totk.exe 失败(退出代码 {code})。详情:{log}", + "compile.exe_in_use": "{path} 正在使用中。请关闭游戏后重新运行安装程序。", + "prepare.shader_list_missing": "缺少着色器列表。", + "prepare.romfs_patches_failed": "写入游戏数据补丁失败(退出代码 {code})。详情:{log}", + "prepare.shaders_failed": "准备着色器失败(退出代码 {code})。详情:{log}", + "cleanup.romfs_unreadable": "安装完成后,{path} 中的游戏数据缺失或无法读取。请重启 Windows,然后对同一文件夹再次运行安装程序:它会重新提取游戏数据,其余内容保留。", + "prepare.pack_failed": "打包着色器缓存失败(退出代码 {code})。详情:{log}", + "cleanup.ini_failed": "无法写入 totk.ini:{detail}", + + "warn.lang_needs_fonts": "{lang}文本需要 Switch 系统字体,而安装程序不会提取这些字体;部分文字可能无法显示。", + "warn.npdm_differs": "main.npdm 与参考的 {version} 导出不同;只使用其中的代码模块。", + "warn.xbox_prompts_failed": "无法准备 Xbox 按键提示(退出代码 {code});游戏将继续使用 Switch 按键提示。详情:{log}", + + "ui.title": "TotK 安装程序", + "ui.version": "版本 {version}", + "ui.intro": "用你自己的游戏文件构建一个可以游玩的《王国之泪》文件夹。耗时较长,只需运行一次。", + "ui.notice": "此安装程序构建的文件夹包含游戏本身,仅供你个人使用;请勿分享或上传。", + "ui.keys_private": "密钥文件只在原位置读取,其内容绝不会被显示、复制或保存。", + "ui.base": "游戏本体(NSP 或 XCI)", + "ui.update": "1.2.1 或 1.4.3 更新(NSP)", + "ui.keys": "prod.keys", + "ui.game_language": "游戏语言", + "ui.dest": "安装文件夹", + "ui.browse": "浏览...", + "ui.pick_game": "选择游戏本体文件", + "ui.pick_update": "选择 1.2.1 或 1.4.3 更新文件", + "ui.pick_keys": "选择 prod.keys", + "ui.pick_dest": "选择安装文件夹", + "ui.type_game": "游戏文件(NSP、XCI)", + "ui.type_nsp": "NSP 文件", + "ui.type_keys": "密钥文件(*.keys)", + "ui.type_all": "所有文件", + "ui.start": "开始", + "ui.cancel": "取消", + "ui.cancelling": "正在取消...", + "ui.show_log": "显示日志", + "ui.hide_log": "隐藏日志", + "ui.close": "关闭", + "ui.back": "返回", + "ui.open_folder": "打开文件夹", + "ui.update_mode": "此文件夹中已有之前的安装。安装程序会继续或更新它;只有在需要时才会再次要求提供游戏文件。", + "ui.need_dest": "请选择安装文件夹。", + "ui.need_base": "请选择游戏本体文件。", + "ui.need_update": "请选择 1.2.1 或 1.4.3 更新文件。", + "ui.need_keys": "请选择 prod.keys 文件。", + "ui.need_lang": "请选择游戏语言。", + "ui.missing_base": "游戏本体文件不存在。", + "ui.missing_update": "更新文件不存在。", + "ui.missing_keys": "密钥文件不存在。", + "ui.running_install": "正在安装", + "ui.running_resume": "正在继续之前的安装", + "ui.running_update": "正在更新安装", + "ui.state_started": "已开始", + "ui.state_done": "完成", + "ui.state_skipped": "已跳过", + "ui.state_pending": "等待中", + "ui.state_running": "进行中", + "ui.state_failed": "失败", + "ui.log_warning": "警告", + "ui.log_error": "错误", + "ui.log_space": "所需空间:{need} GB,可用:{free} GB", + "ui.log_end": "已结束", + "ui.result_ok": "游戏已准备就绪", + "ui.result_failed": "安装失败", + "ui.result_cancelled": "安装已取消", + "ui.done_text": "从 {dest} 启动 totk.exe。安装程序和你选择的游戏文件都不再需要了。", + "ui.cancelled_text": "已完成的步骤会保留。用同一个文件夹再次运行安装程序即可继续。", + "ui.log_file": "日志文件:{path}", + "ui.process_died": "安装程序意外停止(退出代码 {code})。", + "ui.confirm_cancel": "安装正在进行。要取消安装并关闭窗口吗?", + "ui.space_one": "{path} 需要的可用空间:{need} GB(可用:{free} GB)。", + "ui.space_two": "{path} 需要的可用空间:{need} GB(可用:{free} GB);{temp} 需要:{temp_need} GB(可用:{temp_free} GB)。", + "ui.amount_bytes": "{done} / {total} GB", + "ui.amount_chunks": "{done} / {total} 部分", + "ui.amount_objects": "{done} / {total} 个文件", + "ui.amount_shaders": "{done} / {total} 个着色器", + "ui.amount_other": "{done} / {total} {unit}", + "ui.seconds": "{n} 秒", + "param.input.base": "游戏本体", + "param.input.update": "更新", + "param.input.keys": "密钥", + + "launcher.title": "TotK 安装程序", + "launcher.python_missing": "安装文件不完整:TotK-Setup.exe 旁边缺少 python 文件夹。请重新解压整个压缩包,然后从解压出的文件夹中启动 TotK-Setup.exe。", + + "lang.ja": "日语", + "lang.en-US": "英语(美国)", + "lang.en-GB": "英语(英国)", + "lang.fr": "法语", + "lang.fr-CA": "法语(加拿大)", + "lang.de": "德语", + "lang.it": "意大利语", + "lang.es": "西班牙语", + "lang.es-419": "西班牙语(拉丁美洲)", + "lang.nl": "荷兰语", + "lang.pt": "葡萄牙语", + "lang.pt-BR": "葡萄牙语(巴西)", + "lang.ru": "俄语", + "lang.ko": "韩语", + "lang.zh-Hans": "中文(简体)", + "lang.zh-Hant": "中文(繁体)" +} diff --git a/runtime/cfg.c b/runtime/cfg.c index 25a30f18..12718200 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -106,7 +106,7 @@ static const CfgMeta metas[] = { {"MOTION", "1", "0|1", LIVE}, {"RUMBLE_STRENGTH", "130", "0..300", LIVE}, {"RUMBLE_CURVE", "0.6", "0.2..1.5", LIVE}, {"RUMBLE_TRIGGERS", "0", "0|1", LIVE}, {"PAD_LAYOUT", "auto", "auto|nintendo|xbox|xbox_prompts", LIVE}, {"STICK_DEADZONE", "8", "0..50", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE}, - {"MENU_LANG", "", "en|ru", LIVE}, + {"MENU_LANG", "", "en|ru|zh-Hans", LIVE}, // Advanced: scheduling {"ASYNC_PREEMPT", "1", "0|1|2", RESTART}, {"REPLAY_ASYNC", "0", "0|1", RESTART}, {"FREE_CORES", "0", "0|1", RESTART}, {"TIMER_1MS", "1", "0|1", RESTART}, diff --git a/runtime/ov_probe.c b/runtime/ov_probe.c index c0ffa181..6ee6b153 100644 --- a/runtime/ov_probe.c +++ b/runtime/ov_probe.c @@ -814,13 +814,47 @@ static void probe_fonts(void) { (unsigned long long)size, path); } -// The host catalog (ui_text.c): every menu id has its own English and Russian text, the software keyboard keeps its -// game-language rows, and menu_text follows TOTK_MENU_LANG. +// The printf conversions of a format, in order and without the text between them: "%s, game %.0f%%" -> "%s%.0f%%". +static void conversions(const char *fmt, char *out, size_t cap) { + size_t n = 0; + for (const char *p = fmt; *p;) { + if (*p++ != '%') continue; + const char *start = p - 1; + while (*p && strchr(".-+ #0123456789", *p)) p++; + if (*p) p++; // the conversion letter, or the second '%' of "%%" + for (; start < p; start++) + if (n + 1 < cap) out[n++] = *start; + } + out[n] = 0; +} + +// The host catalog (ui_text.c): every menu id has its own English, Russian and Simplified Chinese text, the formats +// keep the English conversions, the software keyboard keeps its game-language rows, and menu_text follows +// TOTK_MENU_LANG. static void probe_menu_text(void) { static const char *const langs[] = {"en", "ja", "fr", "de", "it", "es", "nl", "pt", "ru", "zh-Hans", "zh-Hant", "ko"}; - for (int id = UI_MENU_FIRST; id <= UI_MENU_LAST_ID; id++) { - CHECK(ui_text_defined("en", (UiTextId)id) && ui_text_defined("ru", (UiTextId)id), "menu text id %d lacks en or ru", id); - CHECK(*ui_text_in("en", (UiTextId)id) && *ui_text_in("ru", (UiTextId)id), "menu text id %d is empty", id); + static const char *const menu_langs[] = {"en", "ru", "zh-Hans"}; + for (int id = UI_MENU_FIRST; id <= UI_MENU_LAST_ID; id++) + for (size_t i = 0; i < sizeof menu_langs / sizeof *menu_langs; i++) + CHECK(ui_text_defined(menu_langs[i], (UiTextId)id) && *ui_text_in(menu_langs[i], (UiTextId)id), + "menu text id %d lacks %s", id, menu_langs[i]); + // the texts the host passes to printf + static const UiTextId formats[] = { + UI_MENU_VERSION, UI_MENU_PRESENT_IN_USE, UI_PERF_LINE_FPS, UI_MENU_FPS_DISPLAY_HZ, UI_MENU_PAD_LAYOUT_IN_USE, + UI_BINDS_PRESS_KEY, UI_BINDS_PRESS_PAD, UI_BINDS_CANCEL_HINT, UI_BINDS_TAKEN, UI_BINDS_SWAPPED, UI_KEY_NUM_FMT, + UI_MENU_OV_FPS, UI_MENU_OV_FRAME_MS, UI_MENU_OV_GAME_PCT, UI_MENU_OV_MAX_MS, UI_MENU_OV_FMT_PCT, + UI_MENU_OV_FMT_TEMP, UI_MENU_OV_FMT_POWER, UI_MENU_OV_FMT_MHZ, UI_MENU_OV_FMT_GB, UI_MENU_OV_FMT_GB_OF, + UI_MENU_OV_GAME_GB, UI_MENU_OV_FMT_MS, UI_MENU_OV_PER_FRAME, UI_MENU_OV_FMT_SIZE, UI_MENU_OV_FMT_SCENE, + UI_MENU_OV_FMT_FSR, + }; + for (size_t f = 0; f < sizeof formats / sizeof *formats; f++) { + char want[64], got[64]; + conversions(ui_text_in("en", formats[f]), want, sizeof want); + for (size_t i = 1; i < sizeof menu_langs / sizeof *menu_langs; i++) { + conversions(ui_text_in(menu_langs[i], formats[f]), got, sizeof got); + CHECK(!strcmp(want, got), "format id %d in %s has conversions '%s', English '%s'", (int)formats[f], + menu_langs[i], got, want); + } } CHECK(!ui_text_defined("en", UI_TEXT_COUNT) && !*ui_text_in("ru", UI_TEXT_COUNT), "an id past the catalog gives text"); // other languages fall back to English for the menu, and keep their own keyboard texts @@ -832,18 +866,25 @@ static void probe_menu_text(void) { for (size_t i = 1; i < sizeof langs / sizeof *langs; i++) CHECK(!strcmp(ui_text_in(langs[i], (UiTextId)id), ui_text_in("en", (UiTextId)id)), "language name %d differs in %s", id, langs[i]); CHECK(!strcmp(ui_text_in("en", UI_MENU_LANGNAME_RU), "Русский"), "Russian is not shown as Russian"); - // the overlay formats keep their conversions - CHECK(strstr(ui_text_in("ru", UI_MENU_OV_GAME_PCT), "%.0f%%") && strstr(ui_text_in("ru", UI_MENU_OV_MAX_MS), "%.1f"), - "overlay format lost its conversion"); + // the system UI language picks the menu language when the setting is unset + static const struct { const char *tag, *lang; } sys_langs[] = { + {"ru", "ru"}, {"ru-RU", "ru"}, {"zh-CN", "zh-Hans"}, {"zh-SG", "zh-Hans"}, {"zh-Hans-CN", "zh-Hans"}, + {"zh-TW", "en"}, {"zh-HK", "en"}, {"zh-Hant-TW", "en"}, {"en-US", "en"}, {"rue", "en"}, {"", "en"}, + }; + for (size_t i = 0; i < sizeof sys_langs / sizeof *sys_langs; i++) + CHECK(!strcmp(menu_lang_for_system(sys_langs[i].tag), sys_langs[i].lang), "system language '%s' gives menu %s", + sys_langs[i].tag, menu_lang_for_system(sys_langs[i].tag)); // menu_text follows the setting live - cfg_set("TOTK_MENU_LANG", "ru"); - CHECK(menu_text(UI_MENU_CONTINUE) == ui_text_in("ru", UI_MENU_CONTINUE), "menu_text ignores MENU_LANG=ru"); - cfg_set("TOTK_MENU_LANG", "en"); - CHECK(menu_text(UI_MENU_CONTINUE) == ui_text_in("en", UI_MENU_CONTINUE), "menu_text did not follow MENU_LANG=en"); + for (size_t i = 0; i < sizeof menu_langs / sizeof *menu_langs; i++) { + cfg_set("TOTK_MENU_LANG", menu_langs[i]); + CHECK(!strcmp(menu_language(), menu_langs[i]) && + menu_text(UI_MENU_CONTINUE) == ui_text_in(menu_langs[i], UI_MENU_CONTINUE), + "menu_text did not follow MENU_LANG=%s", menu_langs[i]); + } cfg_set("TOTK_MENU_LANG", ""); - const char *sys = plat_ui_language(); - int ru = !strncmp(sys, "ru", 2); - CHECK(menu_text(UI_MENU_CONTINUE) == ui_text_in(ru ? "ru" : "en", UI_MENU_CONTINUE), "menu_text auto ignores the system language"); + const char *auto_lang = menu_lang_for_system(plat_ui_language()); + CHECK(menu_text(UI_MENU_CONTINUE) == ui_text_in(auto_lang, UI_MENU_CONTINUE), + "menu_text auto ignores the system language"); } static void probe_main(Cpu *c) { diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 865f6b17..b73a59e6 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -169,6 +169,7 @@ static int g_failed_flag() { return g_failed.load(std::memory_order_relaxed); } static int g_vk_ok; // back end initialised for g_vk_fmt static VkFormat g_vk_fmt; static float g_font_scale; // the scale of the uploaded font atlas; 0 when none is uploaded +static const char *g_font_lang; // the menu language whose glyphs the uploaded atlas holds static float g_style_scale; // the scale the style was last sized for static ImGuiStyle g_base_style; // the menu's style at 1080 lines static uint64_t g_last_ns; @@ -253,16 +254,18 @@ static int vk_up(const MenuTarget *t) { return 1; } -// Roboto Medium (Latin, Cyrillic, dashes and quotes) at 26 px per 1080 lines, with the glyphs of the Japanese, Korean -// and Chinese language names merged in from a system font when there is one (each language is named in its own script). -// Made again when the window height changes; the old texture goes after the queue is idle (CreateFontsTexture). +// Roboto Medium (Latin, Cyrillic, dashes and quotes) at 26 px per 1080 lines. For the Japanese, Korean and Chinese +// languages, glyphs are merged in from a system font when there is one: those of the language's own name (each language +// is named in its own script in the language lists) and, for the menu language, every glyph of the menu and overlay +// text. Made again when the window height or the menu language changes; the old texture goes after the queue is idle +// (CreateFontsTexture). static const ImWchar kRanges[] = {0x0020, 0x00FF, 0x0400, 0x052F, 0x2010, 0x2027, 0}; static const struct { const char *lang; UiTextId name; } kCjk[] = { {"ja", UI_MENU_LANGNAME_JA}, {"ko", UI_MENU_LANGNAME_KO}, {"zh-Hans", UI_MENU_LANGNAME_ZH_HANS}, {"zh-Hant", UI_MENU_LANGNAME_ZH_HANT}, }; -static int fonts_up(float scale) { +static int fonts_up(float scale, const char *menu_lang) { enum { N = sizeof kCjk / sizeof *kCjk }; ImFontAtlas *fa = ImGui::GetIO().Fonts; fa->Clear(); @@ -279,6 +282,8 @@ static int fonts_up(float scale) { merged++; ImFontGlyphRangesBuilder b; b.AddText(ui_text_in("en", kCjk[i].name)); + if (!strcmp(kCjk[i].lang, menu_lang)) + for (int id = UI_MENU_FIRST; id <= UI_MENU_LAST_ID; id++) b.AddText(ui_text_in(menu_lang, (UiTextId)id)); b.BuildRanges(&ranges[i]); ImFontConfig mc; mc.MergeMode = true; @@ -291,8 +296,10 @@ static int fonts_up(float scale) { fa->ClearInputData(); // the glyphs are in the texture: the font files and the pixels are not needed again fa->ClearTexData(); for (uint8_t *d : data) free(d); - rt_log("menu: font atlas at %.1f px, language names from %d of %d system fonts", 26.0f * scale, merged, (int)N); + rt_log("menu: font atlas at %.1f px for menu language %s, CJK glyphs from %d of %d system fonts", 26.0f * scale, + menu_lang, merged, (int)N); g_font_scale = ok ? scale : 0; + g_font_lang = menu_lang; return ok; } @@ -596,8 +603,10 @@ static void tab_controls(float scale) { static void tab_menu(float scale) { opt_begin("##menu", scale); - static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU}; - opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, 3, UI_MENU_MENU_LANG_DESC); + // one name per TOTK_MENU_LANG value (cfg.c), after the automatic choice + static const UiTextId langs[] = {UI_MENU_MENU_LANG_AUTO, UI_MENU_LANGNAME_EN, UI_MENU_LANGNAME_RU, + UI_MENU_LANGNAME_ZH_HANS}; + opt_choice("TOTK_MENU_LANG", UI_MENU_MENU_LANG, langs, (int)(sizeof langs / sizeof *langs), UI_MENU_MENU_LANG_DESC); opt_end(); } @@ -1112,7 +1121,9 @@ extern "C" int menu_overlay_frame(uint64_t frame, const MenuTarget *t, const cha uint64_t t0 = plat_now_ns(); if (!g_ctx_ok) make_context(); float scale = menu_scale(t->height); - if (!vk_up(t) || (g_font_scale != scale && !fonts_up(scale))) { + const char *lang = menu_language(); + // vk_up first: a new back end drops the atlas (g_font_scale 0) + if (!vk_up(t) || ((g_font_scale != scale || !g_font_lang || strcmp(g_font_lang, lang)) && !fonts_up(scale, lang))) { rt_log("menu: Dear ImGui Vulkan back end set-up failed; the menu stays closed"); g_failed.store(1); set_open(0); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 65a1926e..272483b9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -1,6 +1,6 @@ // Catalog of the text the host shows the player (ui_text.h). One array per catalog language, indexed by UiTextId: a new // string gets an id in ui_text.h and an entry in every language that has one (a missing entry falls back to English). -// The software keyboard has every language; the menu has English and Russian. +// The software keyboard has every language; the menu has English, Russian and Simplified Chinese. #include #include @@ -496,6 +496,198 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_OV_SCALE_BILINEAR] = "билинейное", }; +static const char *const text_zh_hans[UI_TEXT_COUNT] = { + SWKBD("文字输入", "请输入名字", "马儿", "确定", "取消", "手柄:A 确定,B 取消"), + + [UI_MENU_TITLE] = "设置", [UI_MENU_TAB_SCREEN] = "显示", [UI_MENU_TAB_GAME] = "游戏", [UI_MENU_TAB_SOUND] = "声音", + [UI_MENU_TAB_CONTROLS] = "操作", [UI_MENU_TAB_MENU] = "菜单", [UI_MENU_TAB_ADVANCED] = "高级", + [UI_MENU_CONTINUE] = "继续", [UI_MENU_QUIT] = "退出游戏", [UI_MENU_ON] = "开", [UI_MENU_OFF] = "关", + [UI_MENU_AUTO] = "自动", [UI_MENU_DEFAULT_MARK] = "默认", [UI_MENU_AFTER_RESTART] = "重启后生效", + [UI_MENU_SET_BY_ENV] = "由环境变量设定", [UI_MENU_SAVE_FAILED] = "无法保存设置", + [UI_MENU_VERSION] = "TotK Recomp %s,游戏 %s", + + [UI_MENU_FULLSCREEN] = "全屏", [UI_MENU_FULLSCREEN_DESC] = "让游戏画面铺满屏幕;按 F11 切换。", + [UI_MENU_WINDOW_SIZE] = "窗口大小", [UI_MENU_WINDOW_SIZE_DESC] = "非全屏时游戏窗口的大小。", + [UI_MENU_WINDOW_SIZE_CUSTOM] = "自定义", [UI_MENU_PRESENT] = "呈现方式", + [UI_MENU_PRESENT_DESC] = "渲染完成的帧如何显示到屏幕上。", [UI_MENU_PRESENT_MAILBOX] = "Mailbox", + [UI_MENU_PRESENT_VSYNC] = "垂直同步", [UI_MENU_PRESENT_IMMEDIATE] = "立即", + [UI_MENU_PRESENT_IN_USE] = "实际使用:%s", [UI_MENU_GPU] = "显卡", + [UI_MENU_GPU_DESC] = "用于渲染游戏的 Vulkan 设备。", [UI_MENU_GPU_AUTO] = "自动", + [UI_MENU_PERF_OVERLAY] = "性能叠加层", + [UI_MENU_PERF_OVERLAY_DESC] = "在右上角显示帧率。“完整”模式还会显示帧时间曲线、CPU、GPU 和内存占用、温度," + "以及渲染线程的等待时间。按 F10 循环切换模式。", + [UI_MENU_PERF_OFF] = "关", [UI_MENU_PERF_FPS] = "帧率", [UI_MENU_PERF_FULL] = "完整", + [UI_PERF_LINE_FPS] = "%.0f FPS", [UI_MENU_GRAPHICS] = "画面", [UI_MENU_OUTPUT_RES] = "游戏分辨率", + [UI_MENU_OUTPUT_RES_DESC] = "游戏绘制画面和界面所用的尺寸。高于 1920 x 1080 时,游戏需要更多显存和 GPU 时间。" + "更宽的尺寸(21:9)会拓宽镜头视野,并把 HUD 移到屏幕四角。", + [UI_MENU_RENDER_SCALE] = "3D 渲染比例", + [UI_MENU_RENDER_SCALE_DESC] = "3D 场景相对于游戏分辨率的大小;游戏自带的 FSR 会把它缩放到游戏分辨率。高于 100 % " + "时可平滑锯齿边缘(超级采样),但 GPU 开销很大。", + [UI_MENU_RENDER_SCALE_GAME] = "游戏默认(83 %)", [UI_MENU_UPSCALER] = "缩放到窗口", + [UI_MENU_UPSCALER_DESC] = "窗口大于游戏分辨率时画面的缩放方式。FSR 比双线性保留更锐利的边缘和细节。", + [UI_MENU_UPSCALER_FSR] = "AMD FSR 1", [UI_MENU_UPSCALER_BILINEAR] = "双线性", [UI_MENU_ASPECT] = "画面比例", + [UI_MENU_ASPECT_DESC] = "窗口的比例与游戏分辨率不同时(例如 21:9 屏幕上的 16:9 画面):保持画面比例并加黑边," + "或拉伸铺满窗口。", + [UI_MENU_ASPECT_FIT] = "黑边", [UI_MENU_ASPECT_STRETCH] = "拉伸", [UI_MENU_SHARPNESS] = "FSR 锐度", + [UI_MENU_SHARPNESS_DESC] = "FSR 缩放后的锐化强度;0 为关闭。", + + [UI_MENU_FPS_LIMIT] = "帧率上限", + [UI_MENU_FPS_LIMIT_DESC] = "游戏每秒最多绘制的帧数。高于 60 为实验性功能,且需要开启“游戏速度跟随时钟”。", + [UI_MENU_FPS_30] = "30 FPS", [UI_MENU_FPS_60] = "60 FPS", [UI_MENU_FPS_90] = "90 FPS", + [UI_MENU_FPS_120] = "120 FPS", [UI_MENU_FPS_144] = "144 FPS", [UI_MENU_FPS_DISPLAY] = "显示器刷新率", + [UI_MENU_FPS_DISPLAY_HZ] = "显示器刷新率(%.0f Hz)", [UI_MENU_REALTIME] = "游戏速度跟随时钟", + [UI_MENU_REALTIME_DESC] = "按真实时间推进游戏,帧变慢时游戏不会随之变慢。", + [UI_MENU_CLOTH_REALTIME] = "布料跟随时钟", [UI_MENU_CLOTH_REALTIME_DESC] = "布料和头发也按真实时间推进。", + [UI_MENU_HIGHFPS_FIX] = "高帧率修正", + [UI_MENU_HIGHFPS_FIX_DESC] = "修正帧率高于 30 时出现异常的物理效果,以及帧率高于 60 时一直半透明或不可见的物体。", + [UI_MENU_GAME_LANG] = "游戏语言", [UI_MENU_GAME_LANG_DESC] = "游戏文本和语音的语言。", + [UI_MENU_GAME_LANG_AUTO] = "自动", [UI_MENU_OPERATION_MODE] = "运行模式", + [UI_MENU_OPERATION_MODE_DESC] = "让游戏认为自己处于 TV 模式(插在底座上)还是掌机模式。", + [UI_MENU_MODE_DOCKED] = "TV 模式", [UI_MENU_MODE_HANDHELD] = "掌机模式", + + [UI_MENU_VOLUME] = "音量", [UI_MENU_VOLUME_DESC] = "游戏的主音量。", + + [UI_MENU_MOTION] = "体感操作", [UI_MENU_MOTION_DESC] = "使用手柄的陀螺仪瞄准。", + [UI_MENU_RUMBLE_STRENGTH] = "振动强度", [UI_MENU_RUMBLE_STRENGTH_DESC] = "手柄振动的强弱。", + [UI_MENU_RUMBLE_CURVE] = "振动曲线", [UI_MENU_RUMBLE_CURVE_DESC] = "数值越低,弱振动越明显。", + [UI_MENU_RUMBLE_TRIGGERS] = "扳机振动(Xbox)", [UI_MENU_RUMBLE_TRIGGERS_DESC] = "同时让 Xbox 手柄的扳机键振动。", + [UI_MENU_PAD_LAYOUT] = "按键布局", + [UI_MENU_PAD_LAYOUT_DESC] = "哪个按键作为 A。Nintendo:右侧按键,与 Switch 相同。Xbox:下方按键,即 Xbox " + "手柄上标着 A 的键(PlayStation 手柄上为叉键)。自动:带 Nintendo 标注的手柄用 " + "Nintendo,其他手柄用 Xbox。Xbox 按键提示:A 与 Nintendo 布局一样在右侧,游戏显示 " + "Xbox 的按键标注(A 显示为 B,B 显示为 A,X 显示为 Y,Y 显示为 X);" + "按键提示重启后更改。这些字母属于游戏文件,所以在“操作”中重新映射过的按键," + "屏幕上仍显示原来的字母。", + [UI_MENU_PAD_LAYOUT_AUTO] = "自动", [UI_MENU_PAD_LAYOUT_NINTENDO] = "Nintendo(A 在右)", + [UI_MENU_PAD_LAYOUT_XBOX] = "Xbox(A 在下)", [UI_MENU_PAD_LAYOUT_XBOX_PROMPTS] = "Xbox 按键提示(A 在右)", + [UI_MENU_PAD_LAYOUT_IN_USE] = "实际使用:%s", + [UI_MENU_PAD_LAYOUT_PROMPTS_MISSING] = "缺少按键提示文件:请重新运行安装程序", + [UI_MENU_PAD_LAYOUT_PROMPTS_RESTART] = "按键提示重启后更改", [UI_MENU_STICK_DEADZONE] = "摇杆死区", + [UI_MENU_STICK_DEADZONE_DESC] = "手柄摇杆推动多远后游戏才会识别。如果角色或视角会自行移动,请调高此值。", + [UI_MENU_MOUSE_SENS] = "鼠标视角灵敏度", [UI_MENU_MOUSE_SENS_DESC] = "鼠标转动视角的速度。", + + [UI_BINDS_HELP] = "选中一个格子并按 A 或 Enter,然后按下键盘按键、鼠标按键或手柄按键。按 Delete 或 X 清空格子。" + "已被占用的键盘按键会移到这里;手柄按键则与被替换的按键互换。", + [UI_BINDS_COL_KEY1] = "按键 1", [UI_BINDS_COL_KEY2] = "按键 2", [UI_BINDS_COL_PAD] = "手柄", + [UI_BINDS_GROUP_BUTTONS] = "按钮", [UI_BINDS_GROUP_MOVE] = "移动", [UI_BINDS_GROUP_CAMERA] = "视角", + [UI_BINDS_PRESS_KEY] = "请为“%s”按下键盘按键或鼠标按键", [UI_BINDS_PRESS_PAD] = "请为“%s”按下手柄按键", + [UI_BINDS_CANCEL_HINT] = "按 Esc 取消,或等待 %d 秒", [UI_BINDS_TAKEN] = "%s 已从“%s”上移走", + [UI_BINDS_SWAPPED] = "“%s”与“%s”已互换", [UI_BINDS_RESET] = "重置所有按键", + [UI_BINDS_RESET_DESC] = "恢复默认的键盘按键和手柄按键。上方的按键布局将重新生效:在执行此重置之前," + "重新映射过的手柄按键会一直保持在你设定的位置。", + [UI_BIND_A] = "A", [UI_BIND_B] = "B", [UI_BIND_X] = "X", [UI_BIND_Y] = "Y", [UI_BIND_LCLICK] = "按下左摇杆", + [UI_BIND_RCLICK] = "按下右摇杆", [UI_BIND_L] = "L", [UI_BIND_R] = "R", [UI_BIND_ZL] = "ZL", [UI_BIND_ZR] = "ZR", + [UI_BIND_PLUS] = "+ 键", [UI_BIND_MINUS] = "- 键", [UI_BIND_LEFT] = "十字键左", [UI_BIND_UP] = "十字键上", + [UI_BIND_RIGHT] = "十字键右", [UI_BIND_DOWN] = "十字键下", [UI_BIND_LSTICK_LEFT] = "向左移动", + [UI_BIND_LSTICK_UP] = "向前移动", [UI_BIND_LSTICK_RIGHT] = "向右移动", [UI_BIND_LSTICK_DOWN] = "向后移动", + [UI_BIND_RSTICK_LEFT] = "视角向左", [UI_BIND_RSTICK_UP] = "视角向上", [UI_BIND_RSTICK_RIGHT] = "视角向右", + [UI_BIND_RSTICK_DOWN] = "视角向下", [UI_BIND_DESC_A] = "调查、拾取、对话。", + [UI_BIND_DESC_B] = "奔跑、取消、返回。", [UI_BIND_DESC_X] = "跳跃。", [UI_BIND_DESC_Y] = "攻击。", + [UI_BIND_DESC_LCLICK] = "蹲下。", [UI_BIND_DESC_RCLICK] = "第一人称视角。", [UI_BIND_DESC_L] = "能力。", + [UI_BIND_DESC_R] = "投掷武器。", [UI_BIND_DESC_ZL] = "举盾、锁定。", [UI_BIND_DESC_ZR] = "弓。", + [UI_BIND_DESC_PLUS] = "菜单、道具。", [UI_BIND_DESC_MINUS] = "地图。", [UI_BIND_DESC_DPAD] = "快捷选择。", + [UI_BIND_DESC_MOVE] = "像左摇杆一样移动林克。手柄的左摇杆也始终可用。", + [UI_BIND_DESC_CAMERA] = "像右摇杆一样转动视角。鼠标和手柄的右摇杆也始终可用。", [UI_KEY_SPACE] = "空格", + [UI_KEY_TAB] = "Tab", [UI_KEY_LSHIFT] = "左 Shift", [UI_KEY_LCTRL] = "左 Ctrl", [UI_KEY_UP] = "上方向键", + [UI_KEY_DOWN] = "下方向键", [UI_KEY_LEFT] = "左方向键", [UI_KEY_RIGHT] = "右方向键", [UI_KEY_MOUSE_L] = "鼠标左键", + [UI_KEY_MOUSE_R] = "鼠标右键", [UI_KEY_MOUSE_M] = "鼠标中键", [UI_KEY_MOUSE_X1] = "鼠标侧键 4", + [UI_KEY_MOUSE_X2] = "鼠标侧键 5", [UI_KEY_ENTER] = "Enter", [UI_KEY_BACKSPACE] = "Backspace", + [UI_KEY_RSHIFT] = "右 Shift", [UI_KEY_RCTRL] = "右 Ctrl", [UI_KEY_LALT] = "Alt", [UI_KEY_CAPSLOCK] = "Caps Lock", + [UI_KEY_INSERT] = "Insert", [UI_KEY_DELETE] = "Delete", [UI_KEY_HOME] = "Home", [UI_KEY_END] = "End", + [UI_KEY_PAGEUP] = "Page Up", [UI_KEY_PAGEDOWN] = "Page Down", [UI_KEY_NUM_FMT] = "小键盘 %s", + [UI_PAD_SOUTH] = "下方按键", [UI_PAD_EAST] = "右侧按键", [UI_PAD_WEST] = "左侧按键", [UI_PAD_NORTH] = "上方按键", + [UI_PAD_LSTICK] = "左摇杆", [UI_PAD_RSTICK] = "右摇杆", [UI_PAD_L] = "左肩键", [UI_PAD_R] = "右肩键", + [UI_PAD_START] = "Start 键", [UI_PAD_BACK] = "Back 键", [UI_PAD_DPAD_LEFT] = "十字键左", + [UI_PAD_DPAD_UP] = "十字键上", [UI_PAD_DPAD_RIGHT] = "十字键右", [UI_PAD_DPAD_DOWN] = "十字键下", + [UI_PAD_ZL] = "左扳机", [UI_PAD_ZR] = "右扳机", [UI_PAD_LPADDLE1] = "左背键", [UI_PAD_RPADDLE1] = "右背键", + [UI_PAD_LPADDLE2] = "左背键 2", [UI_PAD_RPADDLE2] = "右背键 2", [UI_PAD_CROSS] = "叉键", [UI_PAD_CIRCLE] = "圆圈键", + [UI_PAD_SQUARE] = "方块键", [UI_PAD_TRIANGLE] = "三角键", + + [UI_MENU_MENU_LANG] = "菜单语言", [UI_MENU_MENU_LANG_DESC] = "本菜单和性能叠加层的语言。", + [UI_MENU_MENU_LANG_AUTO] = "自动(跟随 Windows)", + + [UI_MENU_ADV_WARNING] = "这些设置用于测试和排查问题。除非清楚修改的原因,否则请勿改动。", + [UI_MENU_GROUP_SCHED] = "调度", [UI_MENU_GROUP_SHADERS] = "着色器与管线", [UI_MENU_GROUP_TEXMEM] = "纹理与内存", + [UI_MENU_GROUP_FIXES] = "渲染修正", [UI_MENU_GROUP_VULKAN] = "Vulkan", [UI_MENU_GROUP_DIAG] = "诊断", + [UI_MENU_ASYNC_PREEMPT] = "虚拟核心抢占", + [UI_MENU_ASYNC_PREEMPT_DESC] = "允许一个游戏线程打断同一虚拟核心上的另一个线程。", [UI_MENU_PREEMPT_OFF] = "关", + [UI_MENU_PREEMPT_ON] = "开", [UI_MENU_PREEMPT_INHERIT] = "仅继承", + [UI_MENU_REPLAY_ASYNC] = "在独立线程上准备 GPU 帧", + [UI_MENU_REPLAY_ASYNC_DESC] = "在独立线程而不是游戏线程上为 GPU 准备帧。最多增加一帧延迟。", + [UI_MENU_FREE_CORES] = "虚拟核心闸门", [UI_MENU_FREE_CORES_DESC] = "每个虚拟核心只允许运行一个线程,与主机上相同。", + [UI_MENU_TIMER_1MS] = "1 ms Windows 计时器", + [UI_MENU_TIMER_1MS_DESC] = "将系统计时器精度提高到 1 ms,使帧间隔更平稳。", + [UI_MENU_PIPE_WAIT] = "等待中绘制的处理", + [UI_MENU_PIPE_WAIT_DESC] = "“默认”保持当前的调度方式,并为等待中的绘制保留一个工作线程;“旧版(draw)”" + "使用之前的调度方式。", + [UI_MENU_PIPE_WAIT_DEFAULT] = "默认", [UI_MENU_PIPE_WAIT_DRAW] = "旧版(draw)", + [UI_MENU_PIPE_SKIP] = "管线构建期间跳过的绘制", + [UI_MENU_PIPE_SKIP_DESC] = "哪些绘制会被直接丢弃,而不是等待其管线构建完成。", [UI_MENU_PIPE_SKIP_STRICT] = "严格", + [UI_MENU_PIPE_SKIP_ANY] = "任意", [UI_MENU_PIPE_SKIP_FULLSCREEN] = "全屏通道", + [UI_MENU_LIB_PREBUILD] = "阶段库预构建", [UI_MENU_LIB_PREBUILD_DESC] = "在后台提前构建着色器阶段库。", + [UI_MENU_LIB_PREBUILD_THREADS] = "阶段库预构建线程数", + [UI_MENU_LIB_PREBUILD_THREADS_DESC] = "预构建使用的线程数;“自动”会根据你的 CPU 选择。", + [UI_MENU_PIPE_PREBUILD] = "管线预构建", [UI_MENU_PIPE_PREBUILD_DESC] = "提前构建已知的管线。", + [UI_MENU_PREWARM_XLATE] = "着色器转译预热", + [UI_MENU_PREWARM_XLATE_DESC] = "启动时转译已知着色器的线程数;“自动”使用 CPU 线程数的一半,最多 16 个。", + [UI_MENU_GPL] = "图形管线库", + [UI_MENU_GPL_DESC] = "使用 Vulkan 管线库扩展;如果你的驱动程序在此模式下出现异常,请关闭。", + [UI_MENU_ASTC] = "ASTC 纹理解码", [UI_MENU_ASTC_DESC] = "压缩的 ASTC 纹理在何处解码。", + [UI_MENU_ASTC_AUTO] = "自动", [UI_MENU_ASTC_GPU] = "GPU 着色器", [UI_MENU_ASTC_NATIVE] = "原生", + [UI_MENU_ASTC_CPU] = "CPU", [UI_MENU_MEMORY] = "GPU 内存模式", + [UI_MENU_MEMORY_DESC] = "游戏内存与 GPU 的共享方式。", [UI_MENU_MEMORY_AUTO] = "自动", + [UI_MENU_MEMORY_IMPORT] = "导入", [UI_MENU_MEMORY_MIRROR] = "镜像", [UI_MENU_MEMORY_VERIFY] = "校验", + [UI_MENU_TEX_ALIAS] = "纹理别名", + [UI_MENU_TEX_ALIAS_DESC] = "在仍在使用的纹理内存上新建纹理时,新纹理沿用原有内容,而不是从空白开始。", + [UI_MENU_TEX_VRAM_PRESSURE] = "纹理显存上限", + [UI_MENU_TEX_VRAM_PRESSURE_DESC] = "显存占用超过这个百分比时,丢弃游戏已释放的纹理(再次用到时会从存储重新载入)。" + "0 表示一律保留。", + [UI_MENU_ASTC_BC] = "ASTC 压缩为 BC3", + [UI_MENU_ASTC_BC_DESC] = "配合 GPU 解码器使用:把解码后的 ASTC 纹理重新编码为 BC3,显存占用只有四分之一。适合显存 " + "4 GB 及以下的显卡;纹理会略显块状。", + [UI_MENU_LOD_GUARD] = "LOD 保护", + [UI_MENU_LOD_GUARD_DESC] = "等游戏改写完细节层次(LOD)数据后再让 GPU 读取,防止物体在错误位置闪现," + "或远景在某一帧变平。", + [UI_MENU_FIX_C0] = "常量缓冲区修正", + [UI_MENU_FIX_C0_DESC] = "填充驱动保留的常量库 c0(存储大小、调度大小、点大小、基础实例),而不是读到零。", + [UI_MENU_FIX_ZERO] = "新 GPU 内存清零", + [UI_MENU_FIX_ZERO_DESC] = "新的 GPU 内存池初始内容为零,与 Switch 内存一致。", [UI_MENU_BIND_SKIP] = "跳过重复绑定", + [UI_MENU_BIND_SKIP_DESC] = "优化:跳过没有变化的绑定。", [UI_MENU_SHADER_MEMO] = "着色器查找缓存", + [UI_MENU_SHADER_MEMO_DESC] = "优化:记住着色器的查找结果。", [UI_MENU_PIPE_MEMO] = "管线缓存", + [UI_MENU_PIPE_MEMO_DESC] = "优化:状态重复时复用上一次绘制的管线。", [UI_MENU_TEX_MEMO] = "纹理绑定缓存", + [UI_MENU_TEX_MEMO_DESC] = "优化:在多次绘制之间记住纹理描述符。", [UI_MENU_DESC_TEMPLATE] = "描述符模板", + [UI_MENU_DESC_TEMPLATE_DESC] = "优化:批量更新描述符。", [UI_MENU_PUSH_SKIP] = "跳过重复的推送常量", + [UI_MENU_PUSH_SKIP_DESC] = "优化:跳过没有变化的推送常量。", [UI_MENU_SPLIT_DRAWS] = "提前提交 GPU 工作", + [UI_MENU_SPLIT_DRAWS_DESC] = "在渲染通道之间每隔 N 次绘制分批提交 GPU 工作,让 GPU 更早开始;0 为关闭。", + [UI_MENU_VK_VALIDATION] = "验证层", [UI_MENU_VK_VALIDATION_DESC] = "检查每一次 Vulkan 调用,会让游戏明显变慢。", + [UI_MENU_VK_VALIDATION_MISSING] = "未安装验证层。", [UI_MENU_VK_DYN_VERTEX] = "动态顶点状态", + [UI_MENU_VK_DYN_VERTEX_DESC] = "强制开启或关闭动态顶点输入;默认值取决于 GPU。", + [UI_MENU_VK_SUBGROUP_PIN] = "固定子组大小", [UI_MENU_VK_SUBGROUP_PIN_DESC] = "固定着色器的子组大小。", + [UI_MENU_TRACE] = "性能日志", [UI_MENU_TRACE_DESC] = "将每帧耗时写入文件。", [UI_MENU_FLIGHT] = "飞行记录器", + [UI_MENU_FLIGHT_DESC] = "保留一小段近期记录,在画面卡住时存盘。", [UI_MENU_FLIGHT_SPIKE_MS] = "卡顿阈值(毫秒)", + [UI_MENU_FLIGHT_SPIKE_MS_DESC] = "帧时间超过多少算作卡顿。", [UI_MENU_INPUT_RECORD] = "输入录制", + [UI_MENU_INPUT_RECORD_DESC] = "将你的输入写入文件,用于报告问题。", [UI_MENU_OPEN_LOG] = "打开日志文件夹", + [UI_MENU_OPEN_LOG_DESC] = "打开存放日志文件的文件夹。", [UI_MENU_COPY_INFO] = "复制系统信息", + [UI_MENU_COPY_INFO_DESC] = "将 GPU、驱动程序、CPU、内存和已修改的设置复制到剪贴板。", + [UI_MENU_COPY_INFO_DONE] = "已复制", [UI_MENU_ACTION_FAILED] = "操作失败", + [UI_MENU_RESET] = "将所有设置恢复为默认值", [UI_MENU_RESET_DESC] = "对所有标签页生效。", + [UI_MENU_RESET_CONFIRM] = "要将所有设置恢复为默认值吗?", [UI_MENU_RESET_YES] = "重置", [UI_MENU_RESET_NO] = "取消", + + [UI_MENU_OV_FPS] = "%.0f FPS", [UI_MENU_OV_FRAME_MS] = "%.1f ms", [UI_MENU_OV_GAME_PCT] = "游戏 %.0f%%", + [UI_MENU_OV_MAX_MS] = "最大 %.1f ms", [UI_MENU_OV_GPU] = "GPU", [UI_MENU_OV_CPU] = "CPU", [UI_MENU_OV_RAM] = "内存", + [UI_MENU_OV_VRAM] = "显存", [UI_MENU_OV_TEMP] = "温度", [UI_MENU_OV_POWER] = "功耗", [UI_MENU_OV_CLOCK] = "频率", + [UI_MENU_OV_NONE] = "-", [UI_MENU_OV_REPLAY] = "GPU 帧准备", [UI_MENU_OV_GPU_TIME] = "每帧 GPU 忙碌时间", + [UI_MENU_OV_PIPE_WAIT] = "管线等待", [UI_MENU_OV_SHADER_WAIT] = "着色器等待", [UI_MENU_OV_TEX_UPLOADS] = "纹理上传", + [UI_MENU_OV_FMT_PCT] = "%.0f%%", [UI_MENU_OV_FMT_TEMP] = "%.0f °C", [UI_MENU_OV_FMT_POWER] = "%.0f W", + [UI_MENU_OV_FMT_MHZ] = "%.0f MHz", [UI_MENU_OV_FMT_GB] = "%.1f GB", [UI_MENU_OV_FMT_GB_OF] = "/ %.1f GB", + [UI_MENU_OV_GAME_GB] = "游戏 %.1f GB", [UI_MENU_OV_FMT_MS] = "%.2f ms", [UI_MENU_OV_PER_FRAME] = "每帧 %.1f", + [UI_MENU_OV_WINDOW] = "窗口", [UI_MENU_OV_OUTPUT] = "游戏画面", [UI_MENU_OV_SCENE] = "3D 场景", + [UI_MENU_OV_SCALING] = "缩放", [UI_MENU_OV_LIMIT] = "帧率上限", [UI_MENU_OV_PRESENT] = "呈现方式", + [UI_MENU_OV_FMT_SIZE] = "%ux%u", [UI_MENU_OV_FMT_SCENE] = "%ux%u,%.0f%%", + [UI_MENU_OV_FMT_FSR] = "AMD FSR 1,锐度 %d%%", [UI_MENU_OV_SCALE_NONE] = "无(1:1)", + [UI_MENU_OV_SCALE_BILINEAR] = "双线性", +}; + #define SWKBD_ONLY(name, ...) static const char *const name[UI_TEXT_COUNT] = {SWKBD(__VA_ARGS__)} SWKBD_ONLY(text_ja, "文字入力", "名前を入力してください", "ウマ", "OK", "キャンセル", "コントローラー: A = OK、B = キャンセル"); SWKBD_ONLY(text_fr, "Saisie de texte", "Entrez un nom", "Cheval", "OK", "Annuler", "Manette : A = OK, B = Annuler"); @@ -505,7 +697,6 @@ SWKBD_ONLY(text_es, "Introducir texto", "Introduce un nombre", "Caballo", "Acept "Mando: A = Aceptar, B = Cancelar"); SWKBD_ONLY(text_nl, "Tekstinvoer", "Voer een naam in", "Paard", "OK", "Annuleren", "Controller: A = OK, B = Annuleren"); SWKBD_ONLY(text_pt, "Inserir texto", "Introduz um nome", "Cavalo", "OK", "Cancelar", "Comando: A = OK, B = Cancelar"); -SWKBD_ONLY(text_zh_hans, "文字输入", "请输入名字", "马儿", "确定", "取消", "手柄:A 确定,B 取消"); SWKBD_ONLY(text_zh_hant, "文字輸入", "請輸入名字", "馬兒", "確定", "取消", "手把:A 確定,B 取消"); SWKBD_ONLY(text_ko, "문자 입력", "이름을 입력하세요", "말", "확인", "취소", "컨트롤러: A 확인, B 취소"); @@ -543,17 +734,32 @@ const char *ui_text_in(const char *lang, UiTextId id) { const char *ui_text(UiTextId id) { return ui_text_in(ui_text_lang(ov_language()), id); } -// The menu language, re-read when cfg_version changes. TOTK_MENU_LANG "ru" or "en"; anything else (unset included) -// follows the system UI language: Russian for "ru", "ru-RU", ..., else English. -static const char *resolve_menu_lang(void) { - const char *v = cfg_value("TOTK_MENU_LANG"); - if (v && !strcmp(v, "ru")) return "ru"; - if (v && !strcmp(v, "en")) return "en"; - const char *sys = plat_ui_language(); - return sys && (!strcmp(sys, "ru") || !strncmp(sys, "ru-", 3)) ? "ru" : "en"; +// Matches "" and "-..." (a BCP 47 tag with that primary subtag or prefix). +static int tag_is(const char *tag, const char *lang) { + size_t n = strlen(lang); + return !strncmp(tag, lang, n) && (tag[n] == 0 || tag[n] == '-'); } -const char *menu_text(UiTextId id) { +const char *menu_lang_for_system(const char *tag) { + if (!tag) return "en"; + if (tag_is(tag, "ru")) return "ru"; + // Simplified Chinese: the script subtag when Windows gives one, else the regions that write it (China, Singapore). + // zh-TW, zh-HK and zh-MO write Traditional Chinese, which the menu does not have: English. + if (tag_is(tag, "zh-Hans") || tag_is(tag, "zh-CN") || tag_is(tag, "zh-SG")) return "zh-Hans"; + return "en"; +} + +// The menu language, re-read when cfg_version changes. TOTK_MENU_LANG "en", "ru" or "zh-Hans"; anything else (unset +// included) follows the system UI language (menu_lang_for_system). +static const char *resolve_menu_lang(void) { + static const char *const langs[] = {"en", "ru", "zh-Hans"}; + const char *v = cfg_value("TOTK_MENU_LANG"); + for (size_t i = 0; v && i < sizeof langs / sizeof *langs; i++) + if (!strcmp(v, langs[i])) return langs[i]; + return menu_lang_for_system(plat_ui_language()); +} + +const char *menu_language(void) { static _Atomic(const char *) lang = "en"; static _Atomic unsigned seen = ~0u; unsigned v = cfg_version(); @@ -561,5 +767,7 @@ const char *menu_text(UiTextId id) { atomic_store_explicit(&lang, resolve_menu_lang(), memory_order_relaxed); atomic_store_explicit(&seen, v, memory_order_relaxed); } - return ui_text_in(atomic_load_explicit(&lang, memory_order_relaxed), id); + return atomic_load_explicit(&lang, memory_order_relaxed); } + +const char *menu_text(UiTextId id) { return ui_text_in(menu_language(), id); } diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 13a328b6..d4361cad 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -11,7 +11,8 @@ typedef enum { UI_SWKBD_CANCEL, UI_SWKBD_PAD_HINT, // how a controller answers - // Menu: window, tabs, bottom row. UI_MENU_FIRST..UI_MENU_LAST_ID carry English and Russian texts. + // Menu: window, tabs, bottom row. UI_MENU_FIRST..UI_MENU_LAST_ID carry English, Russian and Simplified Chinese + // texts. UI_MENU_FIRST, UI_MENU_TITLE = UI_MENU_FIRST, UI_MENU_TAB_SCREEN, UI_MENU_TAB_GAME, UI_MENU_TAB_SOUND, UI_MENU_TAB_CONTROLS, UI_MENU_TAB_MENU, @@ -173,6 +174,11 @@ int ui_text_defined(const char *lang, UiTextId id); // The catalog language for a Switch language code ("en-GB" -> "en", "zh-CN" -> "zh-Hans", ...). const char *ui_text_lang(const char *switch_code); -// Menu text: ui_text_in(menu language, id). The menu language is TOTK_MENU_LANG ("en" / "ru"); unset, Russian when the -// system UI language is Russian, else English. Follows a live change of the setting. +// Menu text: ui_text_in(menu_language(), id). const char *menu_text(UiTextId id); +// The menu's catalog language: TOTK_MENU_LANG ("en", "ru" or "zh-Hans"); unset, menu_lang_for_system of the system UI +// language. Follows a live change of the setting. +const char *menu_language(void); +// The menu language for a system UI language tag: "ru" for Russian, "zh-Hans" for Simplified Chinese (zh-Hans..., +// zh-CN, zh-SG), else "en". +const char *menu_lang_for_system(const char *tag); diff --git a/tests/installer_gui_test.py b/tests/installer_gui_test.py index 4eb9c228..6df0d1c0 100644 --- a/tests/installer_gui_test.py +++ b/tests/installer_gui_test.py @@ -31,8 +31,9 @@ from installer import state as statefile # noqa: E402 from installer.events import Reporter # noqa: E402 from installer.runner import Context # noqa: E402 from installer.steps import all_steps # noqa: E402 -from installer.guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, Catalog, Form, Model, Process, # noqa: E402 - amount, describe_event, parse_line, windows_ui_language) +from installer.guilogic import (DONE, FAILED, PENDING, RUNNING, SKIPPED, UI_LANGUAGE_LABELS, # noqa: E402 + UI_LANGUAGES, Catalog, Form, Model, Process, amount, default_game_language, + describe_event, parse_line, ui_language_for_langid, windows_ui_language) INSTALLED = ROOT / 'build' / 'install-test' FIXTURE = ROOT / 'build' / 'inst-gui' / 'e2e-install' @@ -233,12 +234,27 @@ class FormTest(unittest.TestCase): class CatalogTest(unittest.TestCase): - def test_russian_covers_english_with_the_same_placeholders(self): - en, ru = Catalog('en').english, Catalog('ru').texts - self.assertEqual(sorted(set(en) - set(ru)), []) - self.assertEqual(sorted(set(ru) - set(en)), []) - holes = [k for k in en if sorted(re.findall(r'\{\w+\}', en[k])) != sorted(re.findall(r'\{\w+\}', ru[k]))] - self.assertEqual(holes, []) + def test_every_language_covers_english_with_the_same_placeholders(self): + en = Catalog('en').english + for lang in UI_LANGUAGES[1:]: + with self.subTest(lang=lang): + other = Catalog(lang).texts + self.assertEqual(sorted(set(en) - set(other)), []) + self.assertEqual(sorted(set(other) - set(en)), []) + holes = [k for k in en + if sorted(re.findall(r'\{\w+\}', en[k])) != sorted(re.findall(r'\{\w+\}', other[k]))] + self.assertEqual(holes, []) + + def test_language_names_tell_the_codes_apart(self): + # gui.App.selected_lang maps the shown name back to its code across every window language + names = {} + for lang in UI_LANGUAGES: + cat = Catalog(lang) + for id in cat.english: + if id.startswith('lang.'): + names.setdefault(cat(id), set()).add(id) + self.assertEqual({n: ids for n, ids in names.items() if len(ids) > 1}, {}) + self.assertEqual(sorted(UI_LANGUAGE_LABELS), sorted(UI_LANGUAGES)) def test_every_id_the_window_uses_exists(self): cat = Catalog('en') @@ -246,12 +262,13 @@ class CatalogTest(unittest.TestCase): 'process_died', 'result_ok', 'result_failed', 'result_cancelled')] ids += [f'step.{s}' for s in ('check', 'extract', 'lift', 'compile', 'prepare', 'cleanup')] ids += ['ui.state_' + n for n in ('started', 'done', 'skipped', 'pending', 'running', 'failed')] - for lang in ('en', 'ru'): + for lang in UI_LANGUAGES: cat.set_language(lang) + self.assertEqual(cat.lang, lang) self.assertEqual([i for i in ids if not cat.has(i)], []) def test_codes_become_names(self): - for lang, korean in (('en', 'Korean'), ('ru', 'Корейский')): + for lang, korean in (('en', 'Korean'), ('ru', 'Корейский'), ('zh-Hans', '韩语')): cat = Catalog(lang) self.assertIn(korean, cat('warn.lang_needs_fonts', lang='ko')) self.assertNotIn(' ko ', cat('warn.lang_needs_fonts', lang='ko')) @@ -280,7 +297,16 @@ class CatalogTest(unittest.TestCase): self.assertEqual(describe_event(cat, {'type': 'start'}), '') def test_windows_language_is_a_known_value(self): - self.assertIn(windows_ui_language(), ('en', 'ru')) + self.assertIn(windows_ui_language(), UI_LANGUAGES) + + def test_windows_langid_picks_the_window_language(self): + for langid, lang in ((0x0419, 'ru'), (0x0819, 'ru'), (0x0804, 'zh-Hans'), (0x1004, 'zh-Hans'), + (0x0404, 'en'), (0x0c04, 'en'), (0x1404, 'en'), (0x0409, 'en'), (0x0411, 'en')): + self.assertEqual(ui_language_for_langid(langid), lang, hex(langid)) + + def test_chinese_window_starts_with_a_game_language_that_needs_no_shared_fonts(self): + self.assertEqual(default_game_language('zh-Hans'), 'en-US') + self.assertEqual(default_game_language('ru'), 'ru') BREAK_CHILD = 'import time\nprint("ready", flush=True)\ntime.sleep(60)\n' diff --git a/tools/make_release.py b/tools/make_release.py index 067c2b34..85483a5e 100644 --- a/tools/make_release.py +++ b/tools/make_release.py @@ -390,12 +390,14 @@ def c_wide(text): def launcher_header(path): - """launcher_text.h: the launcher's two messages in English and Russian, taken from the installer's catalog.""" - lines = ['/* generated by tools/make_release.py from installer/text/{en,ru}.json */'] - for lang in ('en', 'ru'): + """launcher_text.h: the launcher's two messages in English, Russian and Simplified Chinese, taken from the + installer's catalog (macro suffixes EN, RU, ZH_HANS).""" + lines = ['/* generated by tools/make_release.py from installer/text/{en,ru,zh-Hans}.json */'] + for lang in ('en', 'ru', 'zh-Hans'): texts = json.loads((ROOT / 'installer' / 'text' / f'{lang}.json').read_text(encoding='utf-8')) + suffix = lang.upper().replace('-', '_') for key in ('title', 'python_missing'): - lines.append(f'#define LAUNCHER_{key.upper()}_{lang.upper()} {c_wide(texts["launcher." + key])}') + lines.append(f'#define LAUNCHER_{key.upper()}_{suffix} {c_wide(texts["launcher." + key])}') path.parent.mkdir(parents=True, exist_ok=True) path.write_text('\n'.join(lines) + '\n', encoding='ascii') diff --git a/totk.ini.example b/totk.ini.example index aba2432d..fb2d9704 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -134,8 +134,8 @@ # lang = en-US # System mode reported to the game: docked or handheld. # operation_mode = docked -# Language of the settings menu and the overlay: en or ru. Default: the Windows display language, English if it is -# neither. +# Language of the settings menu and the overlay: en, ru or zh-Hans (Simplified Chinese). Default: the Windows display +# language, English if it is none of them (Traditional Chinese included). # menu_lang = en [audio]