i18n: localize common command outputs

This commit is contained in:
m1ngsama 2026-05-23 18:29:30 +08:00
parent 92123d208d
commit 22ab85acef
3 changed files with 67 additions and 6 deletions

View file

@ -12,6 +12,8 @@
continuation prompts now follow the session UI language.
- The full-screen help title and footer now follow the session UI language,
with UTF-8-aware title padding for Chinese.
- Common COMMAND-mode outputs now respect the session language, including
`:users` headers and `:mute-joins` state text.
### Changed
- NORMAL mode now opens at the latest visible messages instead of the oldest

View file

@ -193,9 +193,15 @@ void commands_dispatch(client_t *client) {
strcmp(cmd, "who") == 0) {
pthread_rwlock_rdlock(&g_room->lock);
int total = g_room->client_count;
buffer_appendf(output, sizeof(output), &pos,
"\033[1;36m在线用户 · online\033[0m "
"\033[2;37m· %d\033[0m\n", total);
if (client->help_lang == LANG_ZH) {
buffer_appendf(output, sizeof(output), &pos,
"\033[1;36m在线用户\033[0m "
"\033[2;37m· %d\033[0m\n", total);
} else {
buffer_appendf(output, sizeof(output), &pos,
"\033[1;36mOnline users\033[0m "
"\033[2;37m· %d\033[0m\n", total);
}
time_t now = time(NULL);
for (int i = 0; i < total; i++) {
@ -488,9 +494,15 @@ void commands_dispatch(client_t *client) {
} else if (strcmp(cmd, "mute-joins") == 0 || strcmp(cmd, "mute") == 0) {
client->mute_joins = !client->mute_joins;
buffer_appendf(output, sizeof(output), &pos,
"Join/leave notifications: %s\n",
client->mute_joins ? "muted" : "unmuted");
if (client->help_lang == LANG_ZH) {
buffer_appendf(output, sizeof(output), &pos,
"加入/离开提示: %s\n",
client->mute_joins ? "已静音" : "已开启");
} else {
buffer_appendf(output, sizeof(output), &pos,
"Join/leave notifications: %s\n",
client->mute_joins ? "muted" : "unmuted");
}
} else if (strcmp(cmd, "q") == 0 || strcmp(cmd, "quit") == 0 ||
strcmp(cmd, "exit") == 0) {

View file

@ -204,6 +204,53 @@ else
FAIL=$((FAIL + 1))
fi
LOCALIZED_COMMANDS_SCRIPT="$STATE_DIR/localized-commands.expect"
cat >"$LOCALIZED_COMMANDS_SCRIPT" <<EOF
set timeout 10
spawn ssh $SSH_OPTS anonymous@127.0.0.1
sleep 1
send -- "localized\r"
expect ":support"
send -- "\033"
expect "NORMAL"
send -- ":"
expect ":"
send -- "mute-joins\r"
expect "加入/离开提示"
expect "已静音"
expect "按任意键"
send -- "q"
expect "NORMAL"
send -- ":"
expect ":"
send -- "lang en\r"
expect "Language set to: en"
expect "Press any key"
send -- "q"
expect "NORMAL"
send -- ":"
expect ":"
send -- "users\r"
expect "Online users"
expect "Press any key"
send -- "q"
sleep 0.2
send -- "\003"
sleep 0.2
send -- "\003"
expect eof
EOF
if expect "$LOCALIZED_COMMANDS_SCRIPT" >"$STATE_DIR/localized-commands.log" 2>&1; then
echo "✓ common command output follows session language"
PASS=$((PASS + 1))
else
echo "x localized command output failed"
sed -n '1,200p' "$STATE_DIR/localized-commands.log"
sed -n '1,120p' "$STATE_DIR/server.log"
FAIL=$((FAIL + 1))
fi
echo ""
echo "PASSED: $PASS"
echo "FAILED: $FAIL"