i18n: localize idle timeout notice

This commit is contained in:
m1ngsama 2026-05-23 20:10:51 +08:00
parent 73655d0e70
commit 6ec86eb016
5 changed files with 13 additions and 1 deletions

View file

@ -38,6 +38,7 @@
command output.
- Startup CLI help and option errors now live in a dedicated `cli_text` module
and follow `TNT_LANG` / locale for English and Chinese users.
- Idle-timeout disconnect notices now follow the session UI language.
### Changed
- NORMAL mode now opens at the latest visible messages instead of the oldest

View file

@ -22,6 +22,7 @@ typedef enum {
I18N_TITLE_ONLINE_FORMAT,
I18N_TITLE_MUTED,
I18N_TITLE_HELP_HINT,
I18N_IDLE_TIMEOUT_FORMAT,
I18N_SYSTEM_USERNAME,
I18N_SYSTEM_JOIN_FORMAT,
I18N_SYSTEM_LEAVE_FORMAT,

View file

@ -107,6 +107,8 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
return "静音";
case I18N_TITLE_HELP_HINT:
return "? 帮助";
case I18N_IDLE_TIMEOUT_FORMAT:
return "\r\n\033[33m已断开: 空闲超时 (%d 分钟)\033[0m\r\n";
case I18N_SYSTEM_USERNAME:
return "系统";
case I18N_SYSTEM_JOIN_FORMAT:
@ -237,6 +239,8 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
return "muted";
case I18N_TITLE_HELP_HINT:
return "? help";
case I18N_IDLE_TIMEOUT_FORMAT:
return "\r\n\033[33mDisconnected: idle timeout (%d min)\033[0m\r\n";
case I18N_SYSTEM_USERNAME:
return "system";
case I18N_SYSTEM_JOIN_FORMAT:

View file

@ -787,7 +787,9 @@ main_loop:
if (g_idle_timeout > 0 && joined_room &&
time(NULL) - client->last_active >= g_idle_timeout) {
client_printf(client, "\r\n\033[33mDisconnected: idle timeout (%d min)\033[0m\r\n",
client_printf(client,
i18n_text(client->help_lang,
I18N_IDLE_TIMEOUT_FORMAT),
g_idle_timeout / 60);
break;
}

View file

@ -82,6 +82,10 @@ TEST(text_lookup_matches_language) {
"online") != NULL);
assert(strstr(i18n_text(LANG_ZH, I18N_TITLE_ONLINE_FORMAT),
"在线") != NULL);
assert(strstr(i18n_text(LANG_EN, I18N_IDLE_TIMEOUT_FORMAT),
"idle timeout") != NULL);
assert(strstr(i18n_text(LANG_ZH, I18N_IDLE_TIMEOUT_FORMAT),
"空闲超时") != NULL);
assert(strstr(i18n_text(LANG_EN, I18N_MSG_USAGE),
"msg <username>") != NULL);
assert(strstr(i18n_text(LANG_ZH, I18N_MSG_USAGE),