mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-14 16:50:47 +08:00
feat(i18n): add English support for host-side chat messages
Wrap all user-facing chat text in src/channels with a host-side t() translator (Chinese is the identity default, so untranslated text is always sent verbatim in Chinese). English is selected via the host plugin config `language: en` or the DSH_IM_LANGUAGE environment variable, and the settings UI keeps following the DSH web locale. - add src/channels/shared/i18n.mjs with setImHostLanguage/t() and a Chinese-key -> English dictionary split by area (shared + channels) - complete the English dictionary for every t() key in src/channels, including the feishu channel (welcome/help, repair flow, interactive cards, watch flow) and the shared command/approval/stream text - wrap previously untranslated chat-facing strings in feishu bridge, feishu runtime, editable-message-stream, harness-client, connection-test and image-prompt - dedupe dictionary entries that existed in multiple channel files and canonicalize conflicting translations into the shared dictionaries - extend the i18n unit test to decode string-literal escapes so keys containing \n are checked correctly - document the language switch in README.md, README.en.md and CHANGELOG.md, and rebuild lib/index.js Added English support for bot chat messages across all nine IM channels and AI Office without changing any Chinese output.
This commit is contained in:
parent
3ff8c2a519
commit
dcd7cd64d8
78 changed files with 2283 additions and 992 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
import { connectionTestMessage } from '../shared/connection-test.mjs';
|
||||
import { t } from '../shared/i18n.mjs';
|
||||
import {
|
||||
deriveWhatsappBotId,
|
||||
maskWhatsappAccount,
|
||||
|
|
@ -83,8 +84,8 @@ export class WhatsappController {
|
|||
this.#errors.set(config.botId, safeError(
|
||||
error?.code === 'relink-required' ? 'relink-required' : 'connection-failed',
|
||||
error?.code === 'relink-required'
|
||||
? 'WhatsApp 关联设备已失效,请移除后重新扫码。'
|
||||
: 'WhatsApp 连接未就绪,插件会自动重试。',
|
||||
? t('WhatsApp 关联设备已失效,请移除后重新扫码。')
|
||||
: t('WhatsApp 连接未就绪,插件会自动重试。'),
|
||||
));
|
||||
this.#logger.warn?.(`[dsh-im:whatsapp] bot ${config.botId} failed to initialize`);
|
||||
} finally {
|
||||
|
|
@ -172,7 +173,7 @@ export class WhatsappController {
|
|||
await record.task?.catch(() => undefined);
|
||||
if (!TERMINAL_ATTEMPT_STATES.has(record.state)) {
|
||||
record.state = 'cancelled';
|
||||
record.error = safeError('cancelled', '扫码接入已取消。');
|
||||
record.error = safeError('cancelled', t('扫码接入已取消。'));
|
||||
}
|
||||
await this.#deleteAuth(record.authDirectory).catch(() => undefined);
|
||||
}
|
||||
|
|
@ -192,8 +193,8 @@ export class WhatsappController {
|
|||
this.#errors.set(botId, safeError(
|
||||
error?.code === 'relink-required' ? 'relink-required' : 'connection-failed',
|
||||
error?.code === 'relink-required'
|
||||
? 'WhatsApp 关联设备已失效,请移除后重新扫码。'
|
||||
: 'WhatsApp 连接仍未就绪,请稍后重试。',
|
||||
? t('WhatsApp 关联设备已失效,请移除后重新扫码。')
|
||||
: t('WhatsApp 连接仍未就绪,请稍后重试。'),
|
||||
));
|
||||
throw error;
|
||||
} finally {
|
||||
|
|
@ -209,14 +210,14 @@ export class WhatsappController {
|
|||
return this.#withBotTransition(botId, async () => {
|
||||
const runtime = this.#runtimes.get(botId);
|
||||
if (!runtime?.status?.ready || typeof runtime.sendConnectionTest !== 'function') {
|
||||
const error = new Error('WhatsApp机器人尚未连接');
|
||||
const error = new Error(t('WhatsApp机器人尚未连接'));
|
||||
error.code = 'test-target-unavailable';
|
||||
throw error;
|
||||
}
|
||||
return runtime.sendConnectionTest(
|
||||
connectionTestMessage(
|
||||
`${config.name}(${maskWhatsappAccount(config.accountJid)})`,
|
||||
'WhatsApp机器人',
|
||||
t('WhatsApp机器人'),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
|
@ -275,8 +276,8 @@ export class WhatsappController {
|
|||
bot: { name: config.name, idMasked: maskWhatsappAccount(config.accountJid) },
|
||||
health: {
|
||||
status: connected ? 'healthy' : state === 'error' ? 'error' : 'offline',
|
||||
summary: connected ? 'WhatsApp Web 关联设备运行正常'
|
||||
: state === 'error' ? 'WhatsApp 连接未就绪' : 'WhatsApp 连接当前离线',
|
||||
summary: connected ? t('WhatsApp Web 关联设备运行正常')
|
||||
: state === 'error' ? t('WhatsApp 连接未就绪') : t('WhatsApp 连接当前离线'),
|
||||
lastCheckedAt: runtimeStatus?.lastCheckedAt ?? null,
|
||||
lastConnectedAt: runtimeStatus?.lastConnectedAt ?? null,
|
||||
},
|
||||
|
|
@ -340,7 +341,7 @@ export class WhatsappController {
|
|||
await this.#startRuntime(config);
|
||||
this.#errors.delete(botId);
|
||||
} catch (error) {
|
||||
this.#errors.set(botId, safeError('connection-failed', 'WhatsApp 已绑定,消息连接暂未就绪。'));
|
||||
this.#errors.set(botId, safeError('connection-failed', t('WhatsApp 已绑定,消息连接暂未就绪。')));
|
||||
this.#logger.warn?.(`[dsh-im:whatsapp] bot ${botId} did not reconnect after QR binding`);
|
||||
}
|
||||
if (previous?.authDirectory && previous.authDirectory !== config.authDirectory) {
|
||||
|
|
@ -363,11 +364,11 @@ export class WhatsappController {
|
|||
await this.#deleteAuth(record.authDirectory).catch(() => undefined);
|
||||
if (previous) await this.#startRuntime(previous).catch(() => undefined);
|
||||
record.state = 'cancelled';
|
||||
record.error = safeError('cancelled', '扫码接入已取消。');
|
||||
record.error = safeError('cancelled', t('扫码接入已取消。'));
|
||||
} else {
|
||||
await this.#deleteAuth(record.authDirectory).catch(() => undefined);
|
||||
record.state = 'failed';
|
||||
record.error = safeError('activation-failed', 'WhatsApp 已扫码,但无法保存关联设备。');
|
||||
record.error = safeError('activation-failed', t('WhatsApp 已扫码,但无法保存关联设备。'));
|
||||
this.#logger.error?.('[dsh-im:whatsapp] unable to persist linked-device session');
|
||||
}
|
||||
} finally {
|
||||
|
|
@ -380,10 +381,10 @@ export class WhatsappController {
|
|||
if (TERMINAL_ATTEMPT_STATES.has(record.state)) return;
|
||||
if (record.controller.signal.aborted || error?.name === 'AbortError') {
|
||||
record.state = 'cancelled';
|
||||
record.error = safeError('cancelled', '扫码接入已取消。');
|
||||
record.error = safeError('cancelled', t('扫码接入已取消。'));
|
||||
} else {
|
||||
record.state = 'failed';
|
||||
record.error = safeError('qr-connect-failed', '无法连接 WhatsApp,请重新生成二维码。');
|
||||
record.error = safeError('qr-connect-failed', t('无法连接 WhatsApp,请重新生成二维码。'));
|
||||
}
|
||||
if (this.#activeAttemptId === record.id) this.#activeAttemptId = null;
|
||||
await record.session?.close().catch(() => undefined);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue