mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-06-26 05:44:38 +08:00
i18n: localize welcome screen
This commit is contained in:
parent
07e47e65c8
commit
8009887be9
5 changed files with 29 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
12
src/i18n.c
12
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:
|
||||
|
|
|
|||
14
src/tui.c
14
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in a new issue