manual: use shared localized string helper

This commit is contained in:
m1ngsama 2026-05-24 16:15:27 +08:00
parent f196bfaf6d
commit ed92aeb1e6
3 changed files with 48 additions and 42 deletions

View file

@ -60,6 +60,8 @@
summaries. summaries.
- Startup CLI help and option error formats now use the shared - Startup CLI help and option error formats now use the shared
localized-string helper and English fallback path. localized-string helper and English fallback path.
- The concise `:help` manual text now uses the shared localized-string helper
around the command-catalog rows.
- Documented i18n and user-facing text rules for English-first source text, - Documented i18n and user-facing text rules for English-first source text,
stable command syntax, concise help copy, and translation-only localization. stable command syntax, concise help copy, and translation-only localization.

View file

@ -1,51 +1,50 @@
#include "manual_text.h" #include "manual_text.h"
#include "command_catalog.h" #include "command_catalog.h"
#include "i18n.h"
void manual_text_append_interactive(char *buffer, size_t buf_size, void manual_text_append_interactive(char *buffer, size_t buf_size,
size_t *pos, ui_lang_t lang) { size_t *pos, ui_lang_t lang) {
if (lang == UI_LANG_ZH) { static const i18n_string_t intro = I18N_STRING(
buffer_appendf(buffer, buf_size, pos, "\033[1;36mTNT(1) help\033[0m\n"
"\033[1;36mTNT(1) 帮助\033[0m\n" "\n"
"\n" "\033[1;37mName\033[0m\n"
"\033[1;37m名称\033[0m\n" " TNT - SSH terminal chat room\n"
" TNT - SSH 终端聊天室\n" "\n"
"\n" "\033[1;37mUse\033[0m\n"
"\033[1;37m使用\033[0m\n" " Type a message and press Enter; Esc browses; G latest; i types\n"
" 输入消息并 Enter 发送Esc 浏览历史G 最新i 输入\n" " : runs commands; ? opens the full key reference\n"
" : 运行命令;? 打开完整按键参考\n" "\n"
"\n" "\033[1;37mCommands\033[0m\n",
"\033[1;37m命令\033[0m\n"); "\033[1;36mTNT(1) 帮助\033[0m\n"
command_catalog_append_manual(buffer, buf_size, pos, lang); "\n"
buffer_appendf(buffer, buf_size, pos, "\033[1;37m名称\033[0m\n"
"\n" " TNT - SSH 终端聊天室\n"
"\033[1;37m语言\033[0m\n" "\n"
" :lang 显示当前语言\n" "\033[1;37m使用\033[0m\n"
" :lang en|zh 切换语言\n" " 输入消息并 Enter 发送Esc 浏览历史G 最新i 输入\n"
"\n" " : 运行命令;? 打开完整按键参考\n"
"\033[1;37m参见\033[0m\n" "\n"
" ? 完整按键参考\n"); "\033[1;37m命令\033[0m\n"
return; );
} static const i18n_string_t outro = I18N_STRING(
"\n"
"\033[1;37mLanguage\033[0m\n"
" :lang show current language\n"
" :lang en|zh switch language\n"
"\n"
"\033[1;37mSee also\033[0m\n"
" ? full key reference\n",
"\n"
"\033[1;37m语言\033[0m\n"
" :lang 显示当前语言\n"
" :lang en|zh 切换语言\n"
"\n"
"\033[1;37m参见\033[0m\n"
" ? 完整按键参考\n"
);
buffer_appendf(buffer, buf_size, pos, buffer_appendf(buffer, buf_size, pos, "%s", i18n_string(intro, lang));
"\033[1;36mTNT(1) help\033[0m\n"
"\n"
"\033[1;37mName\033[0m\n"
" TNT - SSH terminal chat room\n"
"\n"
"\033[1;37mUse\033[0m\n"
" Type a message and press Enter; Esc browses; G latest; i types\n"
" : runs commands; ? opens the full key reference\n"
"\n"
"\033[1;37mCommands\033[0m\n");
command_catalog_append_manual(buffer, buf_size, pos, lang); command_catalog_append_manual(buffer, buf_size, pos, lang);
buffer_appendf(buffer, buf_size, pos, buffer_appendf(buffer, buf_size, pos, "%s", i18n_string(outro, lang));
"\n"
"\033[1;37mLanguage\033[0m\n"
" :lang show current language\n"
" :lang en|zh switch language\n"
"\n"
"\033[1;37mSee also\033[0m\n"
" ? full key reference\n");
} }

View file

@ -48,6 +48,11 @@ TEST(interactive_manual_matches_language) {
assert(strstr(en, ":commands") == NULL); assert(strstr(en, ":commands") == NULL);
assert(count_lines(en) <= 20); assert(count_lines(en) <= 20);
memset(en, 0, sizeof(en));
en_pos = 0;
manual_text_append_interactive(en, sizeof(en), &en_pos, (ui_lang_t)99);
assert(strstr(en, "TNT(1) help") != NULL);
assert(strstr(zh, "TNT(1) 帮助") != NULL); assert(strstr(zh, "TNT(1) 帮助") != NULL);
assert(strstr(zh, "使用") != NULL); assert(strstr(zh, "使用") != NULL);
assert(strstr(zh, "命令") != NULL); assert(strstr(zh, "命令") != NULL);