Files
ai-agent/web/i18n/config.test.mjs
T
mlogclub b128447a7e Refactor localization strings to English across various services and UI components
- Updated titles and subtitles in channel_service.go for web channel and WeChat MP channel configurations.
- Changed handoff messages in conversation_human_dispatch_service.go to English.
- Modified notification messages in event handlers for ticket and conversation assignments to English.
- Adjusted ticket creation messages in ticket_service.go to reflect English localization.
- Updated default locale settings in i18n configuration files to English (en-US).
- Changed HTML language attribute in layout.tsx to English.
- Refactored widget locale detection logic in agent-desk-sdk.ts to prioritize English.
2026-05-31 21:57:31 +08:00

61 lines
1.7 KiB
JavaScript

import assert from "node:assert/strict"
import test from "node:test"
import ts from "typescript"
import { readFile } from "node:fs/promises"
import vm from "node:vm"
async function loadConfig() {
const source = await readFile(new URL("./config.ts", import.meta.url), "utf8")
const compiled = ts.transpileModule(source, {
compilerOptions: {
target: ts.ScriptTarget.ES2017,
module: ts.ModuleKind.CommonJS,
},
fileName: "config.ts",
})
const sandbox = {
exports: {},
module: { exports: {} },
}
sandbox.exports = sandbox.module.exports
vm.runInNewContext(compiled.outputText, sandbox)
return sandbox.module.exports
}
test("normalizes supported locale aliases", async () => {
const { DEFAULT_LOCALE, normalizeLocale } = await loadConfig()
assert.equal(DEFAULT_LOCALE, "en-US")
assert.equal(normalizeLocale("zh-CN"), "zh-CN")
assert.equal(normalizeLocale("zh_CN"), "zh-CN")
assert.equal(normalizeLocale("zh"), "zh-CN")
assert.equal(normalizeLocale("en-US"), "en-US")
assert.equal(normalizeLocale("en_US"), "en-US")
assert.equal(normalizeLocale("en"), "en-US")
assert.equal(normalizeLocale("fr-FR"), DEFAULT_LOCALE)
})
test("resolves browser locale from stored value before navigator languages", async () => {
const { resolveBrowserLocale } = await loadConfig()
assert.equal(
resolveBrowserLocale({
storedLocale: "en-US",
navigatorLanguages: ["zh-CN"],
}),
"en-US"
)
})
test("falls back through navigator languages", async () => {
const { resolveBrowserLocale } = await loadConfig()
assert.equal(
resolveBrowserLocale({
storedLocale: "",
navigatorLanguages: ["fr-FR", "en"],
}),
"en-US"
)
})