From cd4951905861cae7a52b02bb2a14ad1b2f89de0d Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Sun, 24 May 2026 16:28:56 +0800 Subject: [PATCH] exec: use localized strings for catalog chrome --- docs/CHANGELOG.md | 2 ++ src/exec_catalog.c | 19 ++++++++----------- tests/unit/test_exec_catalog.c | 6 ++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 36f3197..0af2db2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -64,6 +64,8 @@ around the command-catalog rows. - The full-screen key reference now uses the shared localized-string helper around the command-catalog rows. +- SSH exec help headers and usage prefixes now use the shared + localized-string helper and English fallback path. - Documented i18n and user-facing text rules for English-first source text, stable command syntax, concise help copy, and translation-only localization. diff --git a/src/exec_catalog.c b/src/exec_catalog.c index bdafdc8..20bd420 100644 --- a/src/exec_catalog.c +++ b/src/exec_catalog.c @@ -134,11 +134,11 @@ bool exec_catalog_args_valid(tnt_exec_command_id_t id, const char *args) { void exec_catalog_append_help(char *buffer, size_t buf_size, size_t *pos, ui_lang_t lang) { - if (lang == UI_LANG_ZH) { - buffer_appendf(buffer, buf_size, pos, "TNT exec 接口\n命令:\n"); - } else { - buffer_appendf(buffer, buf_size, pos, "TNT exec interface\nCommands:\n"); - } + static const i18n_string_t header = + I18N_STRING("TNT exec interface\nCommands:\n", + "TNT exec 接口\n命令:\n"); + + buffer_appendf(buffer, buf_size, pos, "%s", i18n_string(header, lang)); for (size_t i = 0; i < sizeof(entries) / sizeof(entries[0]); i++) { const char *summary = i18n_string(entries[i].summary, lang); @@ -150,15 +150,12 @@ void exec_catalog_append_help(char *buffer, size_t buf_size, size_t *pos, void exec_catalog_append_usage(char *buffer, size_t buf_size, size_t *pos, tnt_exec_command_id_t id, ui_lang_t lang) { const exec_catalog_entry_t *entry = entry_for_id(id); + static const i18n_string_t usage_format = + I18N_STRING("%s: usage: %s\n", "%s: 用法: %s\n"); if (!entry) { return; } - if (lang == UI_LANG_ZH) { - buffer_appendf(buffer, buf_size, pos, "%s: 用法: %s\n", - entry->name, entry->usage_syntax); - return; - } - buffer_appendf(buffer, buf_size, pos, "%s: usage: %s\n", + buffer_appendf(buffer, buf_size, pos, i18n_string(usage_format, lang), entry->name, entry->usage_syntax); } diff --git a/tests/unit/test_exec_catalog.c b/tests/unit/test_exec_catalog.c index 061ca66..480960e 100644 --- a/tests/unit/test_exec_catalog.c +++ b/tests/unit/test_exec_catalog.c @@ -107,6 +107,12 @@ TEST(generates_localized_usage) { assert(strcmp(en, "tail: usage: tail [N] | tail -n N\n") == 0); assert(strcmp(zh, "post: 用法: post MESSAGE\n") == 0); + + memset(en, 0, sizeof(en)); + en_pos = 0; + exec_catalog_append_usage(en, sizeof(en), &en_pos, + TNT_EXEC_COMMAND_TAIL, (ui_lang_t)99); + assert(strcmp(en, "tail: usage: tail [N] | tail -n N\n") == 0); } int main(void) {