mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-06-26 05:34:39 +08:00
i18n: localize command mode guidance
This commit is contained in:
parent
2e69283e5c
commit
f535b928d1
3 changed files with 100 additions and 38 deletions
|
|
@ -8,6 +8,8 @@
|
|||
hints, help language, and `:support`.
|
||||
- Added `:lang <en|zh>` so users can switch the interactive UI language for
|
||||
their current session.
|
||||
- COMMAND-mode `:help`, unknown-command guidance, language command output, and
|
||||
continuation prompts now follow the session UI language.
|
||||
|
||||
### Changed
|
||||
- NORMAL mode now opens at the latest visible messages instead of the oldest
|
||||
|
|
|
|||
130
src/commands.c
130
src/commands.c
|
|
@ -104,6 +104,58 @@ static const char *suggest_command(const char *cmd) {
|
|||
return best_distance <= 2 ? best : NULL;
|
||||
}
|
||||
|
||||
static void append_command_help(char *output, size_t buf_size, size_t *pos,
|
||||
help_lang_t lang) {
|
||||
if (lang == LANG_ZH) {
|
||||
buffer_appendf(output, buf_size, pos,
|
||||
"========================================\n"
|
||||
" 可用命令\n"
|
||||
"========================================\n"
|
||||
"list, users, who - 显示在线用户\n"
|
||||
"nick/name <name> - 修改昵称\n"
|
||||
"msg/w <user> <text> - 私聊用户\n"
|
||||
"inbox - 查看私聊历史\n"
|
||||
"last [N] - 查看最近 N 条消息\n"
|
||||
"search <keyword> - 搜索消息历史\n"
|
||||
"mute-joins - 切换加入/离开提示\n"
|
||||
"support - 显示快速支持指南\n"
|
||||
"lang [en|zh] - 查看或切换界面语言\n"
|
||||
"help, commands - 显示此帮助\n"
|
||||
"clear, cls - 清空命令输出\n"
|
||||
"q, quit, exit - 断开连接\n"
|
||||
"上/下方向键 - 命令历史\n"
|
||||
"========================================\n"
|
||||
"INSERT 模式:\n"
|
||||
" /me <action> - 发送动作消息\n"
|
||||
" @username - 提及用户并响铃提示\n"
|
||||
"========================================\n");
|
||||
return;
|
||||
}
|
||||
|
||||
buffer_appendf(output, buf_size, pos,
|
||||
"========================================\n"
|
||||
" Available Commands\n"
|
||||
"========================================\n"
|
||||
"list, users, who - Show online users\n"
|
||||
"nick/name <name> - Change nickname\n"
|
||||
"msg/w <user> <text> - Whisper to user (private)\n"
|
||||
"inbox - Show whisper history\n"
|
||||
"last [N] - Show last N messages\n"
|
||||
"search <keyword> - Search message history\n"
|
||||
"mute-joins - Toggle join/leave notices\n"
|
||||
"support - Show quick support guide\n"
|
||||
"lang [en|zh] - Show or switch UI language\n"
|
||||
"help, commands - Show this help\n"
|
||||
"clear, cls - Clear command output\n"
|
||||
"q, quit, exit - Disconnect\n"
|
||||
"Up/Down arrows - Command history\n"
|
||||
"========================================\n"
|
||||
"In INSERT mode:\n"
|
||||
" /me <action> - Send action message\n"
|
||||
" @username - Mention (bell notify)\n"
|
||||
"========================================\n");
|
||||
}
|
||||
|
||||
void commands_dispatch(client_t *client) {
|
||||
char cmd_buf[256];
|
||||
strncpy(cmd_buf, client->command_input, sizeof(cmd_buf) - 1);
|
||||
|
|
@ -167,28 +219,7 @@ void commands_dispatch(client_t *client) {
|
|||
pthread_rwlock_unlock(&g_room->lock);
|
||||
|
||||
} else if (strcmp(cmd, "help") == 0 || strcmp(cmd, "commands") == 0) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"========================================\n"
|
||||
" Available Commands / 可用命令\n"
|
||||
"========================================\n"
|
||||
"list, users, who - Show online users\n"
|
||||
"nick/name <name> - Change nickname\n"
|
||||
"msg/w <user> <text> - Whisper to user (private)\n"
|
||||
"inbox - Show whisper history\n"
|
||||
"last [N] - Show last N messages\n"
|
||||
"search <keyword> - Search message history\n"
|
||||
"mute-joins - Toggle join/leave notices\n"
|
||||
"support - Show quick support guide\n"
|
||||
"lang [en|zh] - Show or switch UI language\n"
|
||||
"help, commands - Show this help\n"
|
||||
"clear, cls - Clear command output\n"
|
||||
"q, quit, exit - Disconnect\n"
|
||||
"Up/Down arrows - Command history\n"
|
||||
"========================================\n"
|
||||
"In INSERT mode:\n"
|
||||
" /me <action> - Send action message\n"
|
||||
" @username - Mention (bell notify)\n"
|
||||
"========================================\n");
|
||||
append_command_help(output, sizeof(output), &pos, client->help_lang);
|
||||
|
||||
} else if (strcmp(cmd, "support") == 0 || strcmp(cmd, "guide") == 0) {
|
||||
support_append_interactive_panel(output, sizeof(output), &pos,
|
||||
|
|
@ -207,19 +238,38 @@ void commands_dispatch(client_t *client) {
|
|||
}
|
||||
|
||||
if (!arg || arg[0] == '\0') {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Current language: %s\n"
|
||||
"Usage: lang <en|zh>\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
if (client->help_lang == LANG_ZH) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"当前语言: %s\n"
|
||||
"用法: lang <en|zh>\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
} else {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Current language: %s\n"
|
||||
"Usage: lang <en|zh>\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
}
|
||||
} else if (i18n_try_parse_lang(arg, &next_lang)) {
|
||||
client->help_lang = next_lang;
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Language set to: %s\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
if (client->help_lang == LANG_ZH) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"语言已切换为: %s\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
} else {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Language set to: %s\n",
|
||||
i18n_lang_code(client->help_lang));
|
||||
}
|
||||
} else {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Unsupported language: %s\n"
|
||||
"Usage: lang <en|zh>\n", arg);
|
||||
if (client->help_lang == LANG_ZH) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"不支持的语言: %s\n"
|
||||
"用法: lang <en|zh>\n", arg);
|
||||
} else {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Unsupported language: %s\n"
|
||||
"Usage: lang <en|zh>\n", arg);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (strncmp(cmd, "msg ", 4) == 0 || strncmp(cmd, "w ", 2) == 0) {
|
||||
|
|
@ -460,17 +510,27 @@ void commands_dispatch(client_t *client) {
|
|||
} else {
|
||||
const char *suggestion = suggest_command(cmd);
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Unknown command: %s\n", cmd);
|
||||
client->help_lang == LANG_ZH ?
|
||||
"未知命令: %s\n" : "Unknown command: %s\n", cmd);
|
||||
if (suggestion) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Did you mean :%s?\n", suggestion);
|
||||
if (client->help_lang == LANG_ZH) {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"你是想输入 :%s 吗?\n", suggestion);
|
||||
} else {
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
"Did you mean :%s?\n", suggestion);
|
||||
}
|
||||
}
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
client->help_lang == LANG_ZH ?
|
||||
"输入 :support 查看引导,或 :help 查看命令\n" :
|
||||
"Type :support for guidance or :help for commands\n");
|
||||
}
|
||||
|
||||
cmd_done:
|
||||
buffer_appendf(output, sizeof(output), &pos,
|
||||
client->help_lang == LANG_ZH ?
|
||||
"\n按任意键继续..." :
|
||||
"\nPress any key to continue...");
|
||||
|
||||
snprintf(client->command_output, sizeof(client->command_output), "%s", output);
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ send -- ":"
|
|||
expect ":"
|
||||
send -- "support\r"
|
||||
expect "支持"
|
||||
expect "Press any key"
|
||||
expect "按任意键"
|
||||
send -- "q"
|
||||
expect "NORMAL"
|
||||
send -- ":"
|
||||
|
|
@ -184,8 +184,8 @@ expect "NORMAL"
|
|||
send -- ":"
|
||||
expect ":"
|
||||
send -- "suport\r"
|
||||
expect "Did you mean :support"
|
||||
expect "Press any key"
|
||||
expect "你是想输入 :support 吗?"
|
||||
expect "按任意键"
|
||||
send -- "q"
|
||||
sleep 0.2
|
||||
send -- "\003"
|
||||
|
|
|
|||
Loading…
Reference in a new issue