mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-06-26 06:54:38 +08:00
i18n: centralize command guidance text
This commit is contained in:
parent
4fb531771b
commit
0cf8ac6759
5 changed files with 73 additions and 47 deletions
|
|
@ -29,6 +29,8 @@
|
||||||
including the narrow-terminal fallback.
|
including the narrow-terminal fallback.
|
||||||
- Full-screen help and COMMAND-mode help now live in a dedicated `help_text`
|
- Full-screen help and COMMAND-mode help now live in a dedicated `help_text`
|
||||||
module, keeping large bilingual help copy out of TUI and command flow code.
|
module, keeping large bilingual help copy out of TUI and command flow code.
|
||||||
|
- Session language, unknown-command, suggestion, and continuation prompts now
|
||||||
|
use the shared i18n table instead of inline command-flow conditionals.
|
||||||
|
|
||||||
### 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
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,14 @@ typedef enum {
|
||||||
I18N_MUTE_JOINS_FORMAT,
|
I18N_MUTE_JOINS_FORMAT,
|
||||||
I18N_MUTE_JOINS_MUTED,
|
I18N_MUTE_JOINS_MUTED,
|
||||||
I18N_MUTE_JOINS_UNMUTED,
|
I18N_MUTE_JOINS_UNMUTED,
|
||||||
I18N_CLEAR_DONE
|
I18N_CLEAR_DONE,
|
||||||
|
I18N_LANG_CURRENT_FORMAT,
|
||||||
|
I18N_LANG_SET_FORMAT,
|
||||||
|
I18N_LANG_UNSUPPORTED_FORMAT,
|
||||||
|
I18N_UNKNOWN_COMMAND_FORMAT,
|
||||||
|
I18N_DID_YOU_MEAN_FORMAT,
|
||||||
|
I18N_UNKNOWN_GUIDANCE,
|
||||||
|
I18N_CONTINUE_PROMPT
|
||||||
} i18n_text_id_t;
|
} i18n_text_id_t;
|
||||||
|
|
||||||
bool i18n_try_parse_lang(const char *value, help_lang_t *lang);
|
bool i18n_try_parse_lang(const char *value, help_lang_t *lang);
|
||||||
|
|
|
||||||
|
|
@ -189,38 +189,21 @@ void commands_dispatch(client_t *client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!arg || arg[0] == '\0') {
|
if (!arg || arg[0] == '\0') {
|
||||||
if (client->help_lang == LANG_ZH) {
|
buffer_appendf(output, sizeof(output), &pos,
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
i18n_text(client->help_lang,
|
||||||
"当前语言: %s\n"
|
I18N_LANG_CURRENT_FORMAT),
|
||||||
"用法: lang <en|zh>\n",
|
i18n_lang_code(client->help_lang));
|
||||||
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)) {
|
} else if (i18n_try_parse_lang(arg, &next_lang)) {
|
||||||
client->help_lang = next_lang;
|
client->help_lang = next_lang;
|
||||||
if (client->help_lang == LANG_ZH) {
|
buffer_appendf(output, sizeof(output), &pos,
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
i18n_text(client->help_lang,
|
||||||
"语言已切换为: %s\n",
|
I18N_LANG_SET_FORMAT),
|
||||||
i18n_lang_code(client->help_lang));
|
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 {
|
} else {
|
||||||
if (client->help_lang == LANG_ZH) {
|
buffer_appendf(output, sizeof(output), &pos,
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
i18n_text(client->help_lang,
|
||||||
"不支持的语言: %s\n"
|
I18N_LANG_UNSUPPORTED_FORMAT),
|
||||||
"用法: lang <en|zh>\n", arg);
|
arg);
|
||||||
} else {
|
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
|
||||||
"Unsupported language: %s\n"
|
|
||||||
"Usage: lang <en|zh>\n", arg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(cmd, "msg") == 0 || strcmp(cmd, "w") == 0 ||
|
} else if (strcmp(cmd, "msg") == 0 || strcmp(cmd, "w") == 0 ||
|
||||||
|
|
@ -477,28 +460,22 @@ void commands_dispatch(client_t *client) {
|
||||||
} else {
|
} else {
|
||||||
const char *suggestion = suggest_command(cmd);
|
const char *suggestion = suggest_command(cmd);
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
buffer_appendf(output, sizeof(output), &pos,
|
||||||
client->help_lang == LANG_ZH ?
|
i18n_text(client->help_lang,
|
||||||
"未知命令: %s\n" : "Unknown command: %s\n", cmd);
|
I18N_UNKNOWN_COMMAND_FORMAT),
|
||||||
|
cmd);
|
||||||
if (suggestion) {
|
if (suggestion) {
|
||||||
if (client->help_lang == LANG_ZH) {
|
buffer_appendf(output, sizeof(output), &pos,
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
i18n_text(client->help_lang,
|
||||||
"你是想输入 :%s 吗?\n", suggestion);
|
I18N_DID_YOU_MEAN_FORMAT),
|
||||||
} else {
|
suggestion);
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
|
||||||
"Did you mean :%s?\n", suggestion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
buffer_appendf(output, sizeof(output), &pos, "%s",
|
||||||
client->help_lang == LANG_ZH ?
|
i18n_text(client->help_lang, I18N_UNKNOWN_GUIDANCE));
|
||||||
"输入 :support 查看引导,或 :help 查看命令\n" :
|
|
||||||
"Type :support for guidance or :help for commands\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_done:
|
cmd_done:
|
||||||
buffer_appendf(output, sizeof(output), &pos,
|
buffer_appendf(output, sizeof(output), &pos, "%s",
|
||||||
client->help_lang == LANG_ZH ?
|
i18n_text(client->help_lang, I18N_CONTINUE_PROMPT));
|
||||||
"\n按任意键继续..." :
|
|
||||||
"\nPress any key to continue...");
|
|
||||||
|
|
||||||
snprintf(client->command_output, sizeof(client->command_output), "%s", output);
|
snprintf(client->command_output, sizeof(client->command_output), "%s", output);
|
||||||
client->command_input[0] = '\0';
|
client->command_input[0] = '\0';
|
||||||
|
|
|
||||||
32
src/i18n.c
32
src/i18n.c
|
|
@ -154,6 +154,22 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
|
||||||
return "已开启";
|
return "已开启";
|
||||||
case I18N_CLEAR_DONE:
|
case I18N_CLEAR_DONE:
|
||||||
return "命令输出已清空\n";
|
return "命令输出已清空\n";
|
||||||
|
case I18N_LANG_CURRENT_FORMAT:
|
||||||
|
return "当前语言: %s\n"
|
||||||
|
"用法: lang <en|zh>\n";
|
||||||
|
case I18N_LANG_SET_FORMAT:
|
||||||
|
return "语言已切换为: %s\n";
|
||||||
|
case I18N_LANG_UNSUPPORTED_FORMAT:
|
||||||
|
return "不支持的语言: %s\n"
|
||||||
|
"用法: lang <en|zh>\n";
|
||||||
|
case I18N_UNKNOWN_COMMAND_FORMAT:
|
||||||
|
return "未知命令: %s\n";
|
||||||
|
case I18N_DID_YOU_MEAN_FORMAT:
|
||||||
|
return "你是想输入 :%s 吗?\n";
|
||||||
|
case I18N_UNKNOWN_GUIDANCE:
|
||||||
|
return "输入 :support 查看引导,或 :help 查看命令\n";
|
||||||
|
case I18N_CONTINUE_PROMPT:
|
||||||
|
return "\n按任意键继续...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,6 +257,22 @@ const char *i18n_text(help_lang_t lang, i18n_text_id_t id) {
|
||||||
return "unmuted";
|
return "unmuted";
|
||||||
case I18N_CLEAR_DONE:
|
case I18N_CLEAR_DONE:
|
||||||
return "Command output cleared\n";
|
return "Command output cleared\n";
|
||||||
|
case I18N_LANG_CURRENT_FORMAT:
|
||||||
|
return "Current language: %s\n"
|
||||||
|
"Usage: lang <en|zh>\n";
|
||||||
|
case I18N_LANG_SET_FORMAT:
|
||||||
|
return "Language set to: %s\n";
|
||||||
|
case I18N_LANG_UNSUPPORTED_FORMAT:
|
||||||
|
return "Unsupported language: %s\n"
|
||||||
|
"Usage: lang <en|zh>\n";
|
||||||
|
case I18N_UNKNOWN_COMMAND_FORMAT:
|
||||||
|
return "Unknown command: %s\n";
|
||||||
|
case I18N_DID_YOU_MEAN_FORMAT:
|
||||||
|
return "Did you mean :%s?\n";
|
||||||
|
case I18N_UNKNOWN_GUIDANCE:
|
||||||
|
return "Type :support for guidance or :help for commands\n";
|
||||||
|
case I18N_CONTINUE_PROMPT:
|
||||||
|
return "\nPress any key to continue...";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,14 @@ TEST(text_lookup_matches_language) {
|
||||||
"Search") != NULL);
|
"Search") != NULL);
|
||||||
assert(strstr(i18n_text(LANG_ZH, I18N_SEARCH_HEADER_FORMAT),
|
assert(strstr(i18n_text(LANG_ZH, I18N_SEARCH_HEADER_FORMAT),
|
||||||
"搜索") != NULL);
|
"搜索") != NULL);
|
||||||
|
assert(strstr(i18n_text(LANG_EN, I18N_LANG_CURRENT_FORMAT),
|
||||||
|
"Current language") != NULL);
|
||||||
|
assert(strstr(i18n_text(LANG_ZH, I18N_LANG_CURRENT_FORMAT),
|
||||||
|
"当前语言") != NULL);
|
||||||
|
assert(strstr(i18n_text(LANG_EN, I18N_UNKNOWN_COMMAND_FORMAT),
|
||||||
|
"Unknown command") != NULL);
|
||||||
|
assert(strstr(i18n_text(LANG_ZH, I18N_UNKNOWN_COMMAND_FORMAT),
|
||||||
|
"未知命令") != NULL);
|
||||||
assert(strcmp(i18n_lang_code(LANG_EN), "en") == 0);
|
assert(strcmp(i18n_lang_code(LANG_EN), "en") == 0);
|
||||||
assert(strcmp(i18n_lang_code(LANG_ZH), "zh") == 0);
|
assert(strcmp(i18n_lang_code(LANG_ZH), "zh") == 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue