diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ea61960..0ee3622 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,6 +25,8 @@ - Join, leave, and nickname-change system messages now use a dedicated `system_message` module, follow the sender's session language, and keep `:mute-joins` filtering compatible with both Chinese and English logs. +- The interactive welcome screen now follows the selected UI language, + including the narrow-terminal fallback. ### 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 4ab5302..2a5ebcd 100644 --- a/include/i18n.h +++ b/include/i18n.h @@ -7,6 +7,9 @@ typedef enum { I18N_USERNAME_PROMPT, I18N_INVALID_USERNAME, I18N_ROOM_FULL, + I18N_WELCOME_SUBTITLE, + I18N_WELCOME_TAGLINE, + I18N_WELCOME_FALLBACK_FORMAT, I18N_INSERT_HINT_WIDE, I18N_INSERT_HINT_NARROW, I18N_NORMAL_LATEST, diff --git a/src/i18n.c b/src/i18n.c index 7dde39f..0611e30 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -77,6 +77,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return "用户名无效,已改用 anonymous。\r\n"; case I18N_ROOM_FULL: return "房间已满\r\n"; + case I18N_WELCOME_SUBTITLE: + return "匿名聊天室 · SSH"; + case I18N_WELCOME_TAGLINE: + return "键盘友好的终端交流"; + case I18N_WELCOME_FALLBACK_FORMAT: + return "TNT %s - SSH 匿名聊天室\r\n\r\n"; case I18N_INSERT_HINT_WIDE: return "Enter 发送 · Esc 浏览 · :support"; case I18N_INSERT_HINT_NARROW: @@ -158,6 +164,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return "Invalid username. Using 'anonymous' instead.\r\n"; case I18N_ROOM_FULL: return "Room is full\r\n"; + case I18N_WELCOME_SUBTITLE: + return "anonymous chat · SSH"; + case I18N_WELCOME_TAGLINE: + return "keyboard-first terminal chat"; + case I18N_WELCOME_FALLBACK_FORMAT: + return "TNT %s - anonymous chat over SSH\r\n\r\n"; case I18N_INSERT_HINT_WIDE: return "Enter send · Esc browse · :support"; case I18N_INSERT_HINT_NARROW: diff --git a/src/tui.c b/src/tui.c index 9df356a..1bab30e 100644 --- a/src/tui.c +++ b/src/tui.c @@ -153,8 +153,8 @@ void tui_render_welcome(client_t *client) { /* Lines, in display order. Width is computed in display columns. */ const char *line1 = "TNT · " TNT_VERSION; - const char *line2 = "匿名聊天室 · SSH"; - const char *line3 = "Anonymous chat over SSH"; + const char *line2 = i18n_text(client->help_lang, I18N_WELCOME_SUBTITLE); + const char *line3 = i18n_text(client->help_lang, I18N_WELCOME_TAGLINE); int inner_w = utf8_string_width(line1); int w2 = utf8_string_width(line2); @@ -165,11 +165,13 @@ void tui_render_welcome(client_t *client) { /* Fall back to plain prompt if the terminal is too narrow for the frame. */ if (inner_w + 2 > rw) { + char fallback_text[96]; char fallback[128]; - int n = snprintf(fallback, sizeof(fallback), - ANSI_CLEAR ANSI_HOME - "TNT %s — anonymous chat over SSH\r\n\r\n", - TNT_VERSION); + snprintf(fallback_text, sizeof(fallback_text), + i18n_text(client->help_lang, I18N_WELCOME_FALLBACK_FORMAT), + TNT_VERSION); + int n = snprintf(fallback, sizeof(fallback), ANSI_CLEAR ANSI_HOME "%s", + fallback_text); if (n > 0) client_send(client, fallback, (size_t)n); return; } diff --git a/tests/unit/test_i18n.c b/tests/unit/test_i18n.c index 8667734..691d945 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_WELCOME_SUBTITLE), + "anonymous chat") != NULL); + assert(strstr(i18n_text(LANG_ZH, I18N_WELCOME_SUBTITLE), + "匿名聊天室") != NULL); assert(strstr(i18n_text(LANG_EN, I18N_HELP_STATUS_FORMAT), "HELP") != NULL); assert(strstr(i18n_text(LANG_ZH, I18N_HELP_STATUS_FORMAT),