i18n: localize title bar status

This commit is contained in:
m1ngsama 2026-05-23 19:21:01 +08:00
parent aca68824ac
commit 1d8fcea3fa
6 changed files with 30 additions and 4 deletions

View file

@ -20,6 +20,8 @@
unknown-command guidance. unknown-command guidance.
- Command output text for common interactive commands is now centralized in - Command output text for common interactive commands is now centralized in
the i18n table instead of being scattered through command flow logic. 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 ### Changed
- NORMAL mode now opens at the latest visible messages instead of the oldest - NORMAL mode now opens at the latest visible messages instead of the oldest

View file

@ -16,6 +16,9 @@ typedef enum {
I18N_COMMAND_OUTPUT_TITLE, I18N_COMMAND_OUTPUT_TITLE,
I18N_MOTD_TITLE, I18N_MOTD_TITLE,
I18N_MOTD_CONTINUE_HINT, I18N_MOTD_CONTINUE_HINT,
I18N_TITLE_ONLINE_FORMAT,
I18N_TITLE_MUTED,
I18N_TITLE_HELP_HINT,
I18N_USERS_TITLE, I18N_USERS_TITLE,
I18N_MSG_USAGE, I18N_MSG_USAGE,
I18N_MSG_SENT_FORMAT, I18N_MSG_SENT_FORMAT,

View file

@ -95,6 +95,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
return " 公告 "; return " 公告 ";
case I18N_MOTD_CONTINUE_HINT: case I18N_MOTD_CONTINUE_HINT:
return " 按任意键继续 "; return " 按任意键继续 ";
case I18N_TITLE_ONLINE_FORMAT:
return "在线 %d";
case I18N_TITLE_MUTED:
return "静音";
case I18N_TITLE_HELP_HINT:
return "? 帮助";
case I18N_USERS_TITLE: case I18N_USERS_TITLE:
return "在线用户"; return "在线用户";
case I18N_MSG_USAGE: case I18N_MSG_USAGE:
@ -162,6 +168,12 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
return " NOTICE "; return " NOTICE ";
case I18N_MOTD_CONTINUE_HINT: case I18N_MOTD_CONTINUE_HINT:
return " Press any key "; 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: case I18N_USERS_TITLE:
return "Online users"; return "Online users";
case I18N_MSG_USAGE: case I18N_MSG_USAGE:

View file

@ -356,7 +356,9 @@ void tui_render_screen(client_t *client) {
chip_count++; chip_count++;
char online_buf[32]; 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 = online_buf;
chips[chip_count].value_color = "\033[37m"; chips[chip_count].value_color = "\033[37m";
chip_count++; chip_count++;
@ -373,9 +375,10 @@ void tui_render_screen(client_t *client) {
chips[chip_count].value_color = mode_color; chips[chip_count].value_color = mode_color;
chip_count++; 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 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. /* Unread @-mentions chip — high-priority, gets a bright yellow star.
* Sits between mode and hint when present, and survives degradation * 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); left_width += utf8_string_width(chips[i].value);
} }
if (show_mute) { 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; left_width += mute_width;
} }
if (show_unread) { if (show_unread) {

View file

@ -229,6 +229,7 @@ expect "Language set to: en"
expect "Press any key" expect "Press any key"
send -- "q" send -- "q"
expect "NORMAL" expect "NORMAL"
expect "online"
send -- ":" send -- ":"
expect ":" expect ":"
send -- "users\r" send -- "users\r"

View file

@ -74,6 +74,10 @@ TEST(text_lookup_matches_language) {
"Press any key") != NULL); "Press any key") != NULL);
assert(strstr(i18n_text(LANG_ZH, I18N_MOTD_CONTINUE_HINT), assert(strstr(i18n_text(LANG_ZH, I18N_MOTD_CONTINUE_HINT),
"按任意键") != NULL); "按任意键") != 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), assert(strstr(i18n_text(LANG_EN, I18N_MSG_USAGE),
"msg <username>") != NULL); "msg <username>") != NULL);
assert(strstr(i18n_text(LANG_ZH, I18N_MSG_USAGE), assert(strstr(i18n_text(LANG_ZH, I18N_MSG_USAGE),