diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 81c1782..3a4552e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,8 @@ their current session. - COMMAND-mode `:help`, unknown-command guidance, language command output, and continuation prompts now follow the session UI language. +- The full-screen help title and footer now follow the session UI language, + with UTF-8-aware title padding for Chinese. ### Changed - NORMAL mode now opens at the latest visible messages instead of the oldest diff --git a/include/i18n.h b/include/i18n.h index 8c6210e..70020c7 100644 --- a/include/i18n.h +++ b/include/i18n.h @@ -10,7 +10,9 @@ typedef enum { I18N_INSERT_HINT_WIDE, I18N_INSERT_HINT_NARROW, I18N_NORMAL_LATEST, - I18N_NORMAL_NEW_MESSAGES + I18N_NORMAL_NEW_MESSAGES, + I18N_HELP_TITLE, + I18N_HELP_STATUS_FORMAT } i18n_text_id_t; bool i18n_try_parse_lang(const char *value, help_lang_t *lang); diff --git a/src/i18n.c b/src/i18n.c index 3bc6c72..cee3ee8 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -85,6 +85,10 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return "G 最新"; case I18N_NORMAL_NEW_MESSAGES: return "新消息"; + case I18N_HELP_TITLE: + return " 帮助 "; + case I18N_HELP_STATUS_FORMAT: + return "-- 帮助 -- (%d/%d) j/k:滚动 g/G:首尾 e/z:语言 q:关闭"; } } @@ -103,6 +107,10 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return "G latest"; case I18N_NORMAL_NEW_MESSAGES: return "new"; + case I18N_HELP_TITLE: + return " HELP "; + case I18N_HELP_STATUS_FORMAT: + return "-- HELP -- (%d/%d) j/k:scroll g/G:top/bottom e/z:lang q:close"; } return ""; diff --git a/src/tui.c b/src/tui.c index 31edf3a..0c15135 100644 --- a/src/tui.c +++ b/src/tui.c @@ -3,6 +3,7 @@ #include "ssh_server.h" #include "chat_room.h" #include "history_view.h" +#include "i18n.h" #include "tui_status.h" #include "utf8.h" #include @@ -875,8 +876,8 @@ void tui_render_help(client_t *client) { buffer_appendf(buffer, sizeof(buffer), &pos, ANSI_CLEAR ANSI_HOME); /* Title */ - const char *title = " HELP "; - int title_width = strlen(title); + const char *title = i18n_text(client->help_lang, I18N_HELP_TITLE); + int title_width = utf8_string_width(title); int padding = rw - title_width; if (padding < 0) padding = 0; @@ -921,7 +922,7 @@ void tui_render_help(client_t *client) { /* Status line */ buffer_appendf(buffer, sizeof(buffer), &pos, - "-- HELP -- (%d/%d) j/k:scroll g/G:top/bottom e/z:lang q:close", + i18n_text(client->help_lang, I18N_HELP_STATUS_FORMAT), start + 1, max_scroll + 1); client_send(client, buffer, pos); diff --git a/tests/unit/test_i18n.c b/tests/unit/test_i18n.c index d39f301..2a0a8e5 100644 --- a/tests/unit/test_i18n.c +++ b/tests/unit/test_i18n.c @@ -62,6 +62,10 @@ TEST(text_lookup_matches_language) { "display name") != NULL); assert(strstr(i18n_text(LANG_ZH, I18N_USERNAME_PROMPT), "用户名") != NULL); + assert(strstr(i18n_text(LANG_EN, I18N_HELP_STATUS_FORMAT), + "HELP") != NULL); + assert(strstr(i18n_text(LANG_ZH, I18N_HELP_STATUS_FORMAT), + "帮助") != NULL); assert(strcmp(i18n_lang_code(LANG_EN), "en") == 0); assert(strcmp(i18n_lang_code(LANG_ZH), "zh") == 0); }