diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e7ea16..2f29545 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -20,6 +20,8 @@ unknown-command guidance. - Command output text for common interactive commands is now centralized in the i18n table instead of being scattered through command flow logic. +- TUI title-bar status labels, including online count, mute marker, and help + hint, now follow the session UI language. ### 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 aa7fa15..bf56f2e 100644 --- a/include/i18n.h +++ b/include/i18n.h @@ -16,6 +16,9 @@ typedef enum { I18N_COMMAND_OUTPUT_TITLE, I18N_MOTD_TITLE, I18N_MOTD_CONTINUE_HINT, + I18N_TITLE_ONLINE_FORMAT, + I18N_TITLE_MUTED, + I18N_TITLE_HELP_HINT, I18N_USERS_TITLE, I18N_MSG_USAGE, I18N_MSG_SENT_FORMAT, diff --git a/src/i18n.c b/src/i18n.c index 961e625..19ee198 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -95,6 +95,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return " 公告 "; case I18N_MOTD_CONTINUE_HINT: return " 按任意键继续 "; + case I18N_TITLE_ONLINE_FORMAT: + return "在线 %d"; + case I18N_TITLE_MUTED: + return "静音"; + case I18N_TITLE_HELP_HINT: + return "? 帮助"; case I18N_USERS_TITLE: return "在线用户"; case I18N_MSG_USAGE: @@ -162,6 +168,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) { return " NOTICE "; case I18N_MOTD_CONTINUE_HINT: return " Press any key "; + case I18N_TITLE_ONLINE_FORMAT: + return "online %d"; + case I18N_TITLE_MUTED: + return "muted"; + case I18N_TITLE_HELP_HINT: + return "? help"; case I18N_USERS_TITLE: return "Online users"; case I18N_MSG_USAGE: diff --git a/src/tui.c b/src/tui.c index 6d0e3a9..b099607 100644 --- a/src/tui.c +++ b/src/tui.c @@ -356,7 +356,9 @@ void tui_render_screen(client_t *client) { chip_count++; char online_buf[32]; - snprintf(online_buf, sizeof(online_buf), "在线 %d", online); + snprintf(online_buf, sizeof(online_buf), + i18n_text(client->help_lang, I18N_TITLE_ONLINE_FORMAT), + online); chips[chip_count].value = online_buf; chips[chip_count].value_color = "\033[37m"; chip_count++; @@ -373,9 +375,10 @@ void tui_render_screen(client_t *client) { chips[chip_count].value_color = mode_color; chip_count++; - const char *hint = "? 帮助"; + const char *hint = i18n_text(client->help_lang, I18N_TITLE_HELP_HINT); int hint_width = utf8_string_width(hint); - int mute_width = client->mute_joins ? 6 : 0; /* " 静音" = 2 + 4 */ + const char *mute_label = i18n_text(client->help_lang, I18N_TITLE_MUTED); + int mute_width = client->mute_joins ? utf8_string_width(mute_label) + 2 : 0; /* Unread @-mentions chip — high-priority, gets a bright yellow star. * Sits between mode and hint when present, and survives degradation @@ -442,7 +445,8 @@ void tui_render_screen(client_t *client) { left_width += utf8_string_width(chips[i].value); } if (show_mute) { - buffer_appendf(left, sizeof(left), &lpos, " \033[2;37m静音\033[0m"); + buffer_appendf(left, sizeof(left), &lpos, + " \033[2;37m%s\033[0m", mute_label); left_width += mute_width; } if (show_unread) { diff --git a/tests/test_interactive_input.sh b/tests/test_interactive_input.sh index f965321..f2474a1 100755 --- a/tests/test_interactive_input.sh +++ b/tests/test_interactive_input.sh @@ -229,6 +229,7 @@ expect "Language set to: en" expect "Press any key" send -- "q" expect "NORMAL" +expect "online" send -- ":" expect ":" send -- "users\r" diff --git a/tests/unit/test_i18n.c b/tests/unit/test_i18n.c index 9fcab6e..8667734 100644 --- a/tests/unit/test_i18n.c +++ b/tests/unit/test_i18n.c @@ -74,6 +74,10 @@ TEST(text_lookup_matches_language) { "Press any key") != NULL); assert(strstr(i18n_text(LANG_ZH, I18N_MOTD_CONTINUE_HINT), "按任意键") != NULL); + assert(strstr(i18n_text(LANG_EN, I18N_TITLE_ONLINE_FORMAT), + "online") != NULL); + assert(strstr(i18n_text(LANG_ZH, I18N_TITLE_ONLINE_FORMAT), + "在线") != NULL); assert(strstr(i18n_text(LANG_EN, I18N_MSG_USAGE), "msg ") != NULL); assert(strstr(i18n_text(LANG_ZH, I18N_MSG_USAGE),