test: drop source-text assertion tests and merge locale checks

This commit is contained in:
t8y2 committed 2026-09-23 22:10:06 +08:00
1 parent 349d77d180
commit 8897e12714
257 files changed
+166 -12815

No files matched your search

@@ -1,55 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import itLocale from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
type Messages = Record<string, unknown>;
const locales: Array<[string, Messages]> = [
["az", az],
["es", es],
["it", itLocale],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function offlineExportEntries(locale: Messages): Map<string, string> {
const driverStore = locale.driverStore as Record<string, unknown>;
return new Map(
Object.entries(driverStore)
.filter(([key, value]) => key.startsWith("offlineExport") && typeof value === "string")
.map(([key, value]) => [key, value as string]),
);
}
function placeholders(message: string): string[] {
return [...new Set([...message.matchAll(/\{([^{}]+)\}/g)].map((match) => match[1]))].sort();
}
describe("offline Agent export i18n parity", () => {
const englishEntries = offlineExportEntries(en);
it("declares the complete English message set", () => {
expect(englishEntries.size).toBe(29);
});
it.each(locales)("%s declares matching keys and placeholders", (_name, locale) => {
const localeEntries = offlineExportEntries(locale);
expect([...localeEntries.keys()].sort()).toEqual([...englishEntries.keys()].sort());
for (const [key, englishMessage] of englishEntries) {
expect(placeholders(localeEntries.get(key) ?? ""), key).toEqual(placeholders(englishMessage));
}
});
});
@@ -1,55 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import itLocale from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
type Messages = Record<string, unknown>;
const locales: Array<[string, Messages]> = [
["az", az],
["es", es],
["it", itLocale],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function offlineImportEntries(locale: Messages): Map<string, string> {
const driverStore = locale.driverStore as Record<string, unknown>;
return new Map(
Object.entries(driverStore)
.filter(([key, value]) => (key.startsWith("offlineImport") || key.startsWith("offlineJreImport")) && typeof value === "string")
.map(([key, value]) => [key, value as string]),
);
}
function placeholders(message: string): string[] {
return [...new Set([...message.matchAll(/\{([^{}]+)\}/g)].map((match) => match[1]))].sort();
}
describe("offline Agent import i18n parity", () => {
const englishEntries = offlineImportEntries(en);
it("declares the complete English message set", () => {
expect([...englishEntries.keys()].sort()).toEqual(["offlineImportFailed", "offlineImportPartial", "offlineImportSuccess", "offlineImportWithJreSuccess", "offlineJreImportSuccess"]);
});
it.each(locales)("%s declares matching keys and placeholders", (_name, locale) => {
const localeEntries = offlineImportEntries(locale);
expect([...localeEntries.keys()].sort()).toEqual([...englishEntries.keys()].sort());
for (const [key, englishMessage] of englishEntries) {
expect(placeholders(localeEntries.get(key) ?? ""), key).toEqual(placeholders(englishMessage));
}
});
});
@@ -1,62 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
// Keys the "Auto" picker entry (#9118) adds to the `ai` namespace: the menu
// entry, the slow-path status line, and the per-message routing chip. The picker
// and the chip render in whatever locale the user runs, so a missing key would
// leak a raw key into the toolbar.
const AI_AUTO_ROUTING_ACTIONS_KEYS = ["auto"] as const;
const AI_AUTO_ROUTING_KEYS = ["recognizing", "chip", "switchTo"] as const;
// Settings > AI toggle: new conversations start on the `auto` entry.
const AI_AUTO_ROUTING_SETTINGS_KEYS = ["defaultAutoRouting", "defaultAutoRoutingDescription"] as const;
describe("AI auto-routing locale parity", () => {
it.each(locales)("%s exposes ai.actions.auto with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: { actions: Record<string, unknown> } }).ai;
for (const key of AI_AUTO_ROUTING_ACTIONS_KEYS) {
expect(ai.actions[key], `${_name}: ai.actions.${key}`).toBeTypeOf("string");
expect(ai.actions[key] as string, `${_name}: ai.actions.${key}`).not.toHaveLength(0);
}
});
it.each(locales)("%s exposes the full ai.routing.* key set with non-empty copy", (_name, locale) => {
const routing = (locale as { ai: { routing: Record<string, unknown> } }).ai.routing;
for (const key of AI_AUTO_ROUTING_KEYS) {
expect(routing?.[key], `${_name}: ai.routing.${key}`).toBeTypeOf("string");
expect(routing?.[key] as string, `${_name}: ai.routing.${key}`).not.toHaveLength(0);
}
// The chip interpolates the resolved action label.
expect(routing.chip as string, `${_name}: ai.routing.chip`).toContain("{action}");
expect(routing.switchTo as string, `${_name}: ai.routing.switchTo`).toContain("{action}");
});
it.each(locales)("%s exposes the default auto-routing setting keys with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_AUTO_ROUTING_SETTINGS_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
});
@@ -1,39 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
// Keys the plugin AI conversation adds to the `ai` namespace. The panel renders
// in whatever locale the user runs, so a missing key would leak a raw key into
// the composer placeholder or the welcome copy.
const AI_PLUGIN_CONVERSATION_KEYS = ["pluginHttpModelOnly", "pluginWelcome", "pluginFollowUp"] as const;
describe("plugin AI conversation locale parity", () => {
it.each(locales)("%s exposes the plugin conversation copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_PLUGIN_CONVERSATION_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
});
@@ -1,63 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
// Keys the safe-HTML preview (PR2 of #6467) adds to the `ai` namespace. Every
// locale must expose all of them — the preview UI renders in whatever locale
// the user runs, and a missing key would leak raw keys into the toolbar.
const AI_HTML_PREVIEW_KEYS = ["htmlPreviewLabel", "htmlExpandPreview", "htmlExpandPreviewHint", "htmlSaveSafe", "htmlSaveFailed", "htmlCopySource", "htmlCopyRiskBody", "htmlCopyRiskAccept", "htmlCopyRiskRemember", "htmlCopyRiskToast"] as const;
// Keys the conversation export (PR3 of #6467) adds to the `ai` namespace —
// header menu entry, report role labels, failure marker, and empty-state copy.
const AI_CONVERSATION_EXPORT_KEYS = ["exportConversation", "conversationExportMarkdown", "conversationExportHtml", "conversationRoleUser", "conversationRoleAssistant", "conversationFailedMarker", "conversationExportEmpty"] as const;
// Keys conversation rename and the database picker add to the `ai` namespace —
// the picker renders in every locale and a missing key leaks raw keys into it.
const AI_CONVERSATION_MANAGEMENT_KEYS = ["renameConversation", "conversationRenameFailed", "clearDatabaseSelection", "searchDatabases", "noDatabasesFound"] as const;
describe("AI rich content locale parity", () => {
it.each(locales)("%s exposes the full ai.html* key set with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_HTML_PREVIEW_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
it.each(locales)("%s exposes the full conversation-export key set with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_CONVERSATION_EXPORT_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
it.each(locales)("%s exposes the full conversation-management key set with non-empty copy", (_name, locale) => {
const ai = (locale as { ai: Record<string, unknown> }).ai;
for (const key of AI_CONVERSATION_MANAGEMENT_KEYS) {
expect(ai[key], `${_name}: ai.${key}`).toBeTypeOf("string");
expect(ai[key] as string, `${_name}: ai.${key}`).not.toHaveLength(0);
}
});
});
@@ -1,45 +0,0 @@
import { readFileSync } from "node:fs";
import { describe, expect, it as test } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import it from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
const contentAreaSource = readFileSync(new URL("../../components/layout/ContentArea.vue", import.meta.url), "utf8");
function cachedResultMessages(messages: Record<string, unknown>): Record<string, unknown> {
return messages.grid as Record<string, unknown>;
}
describe("cached result messages", () => {
test.each([
["Azerbaijani", az],
["English", en],
["Spanish", es],
["Italian", it],
["Japanese", ja],
["Korean", ko],
["Brazilian Portuguese", ptBR],
["Turkish", tr],
["Simplified Chinese", zhCN],
["Traditional Chinese", zhTW],
])("provides the missing-result actions in %s", (_locale, messages) => {
const grid = cachedResultMessages(messages);
expect(grid.cachedResultUnavailable).toEqual(expect.any(String));
expect(grid.reexecuteQuery).toEqual(expect.any(String));
});
test("uses the grid namespace from the cached-result fallback UI", () => {
expect(contentAreaSource).toContain('t("grid.cachedResultUnavailable")');
expect(contentAreaSource).toContain('t("grid.reexecuteQuery")');
expect(contentAreaSource).not.toContain('t("editor.cachedResultUnavailable")');
expect(contentAreaSource).not.toContain('t("editor.reexecuteQuery")');
});
});
@@ -1,53 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
// Shared actions such as KafkaMessagesPanel and DoltVersionControl render
// `t("common.refresh")`. When the key is missing everywhere, vue-i18n echoes
// the key path itself (issue #8768). KafkaMessagesPanel.spec.ts mocks i18n as
// `t: (key) => key`, so that spec cannot catch a missing-from-everywhere key.
const locales: Array<[string, Record<string, unknown>]> = [
["az", az as Record<string, unknown>],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function commonRefresh(locale: Record<string, unknown>): unknown {
const common = locale["common"];
if (!common || typeof common !== "object") return undefined;
return (common as Record<string, unknown>)["refresh"];
}
describe("common.refresh i18n key", () => {
it("en resolves common.refresh to text", () => {
const value = commonRefresh(en as Record<string, unknown>);
expect(value, "common.refresh missing from locales/en.ts").toBeTypeOf("string");
expect(value).not.toBe("");
expect(value).not.toBe("common.refresh");
});
it.each(locales)("%s resolves common.refresh to text", (_name, locale) => {
const value = commonRefresh(locale);
expect(value, `${_name} common.refresh`).toBeTypeOf("string");
expect(value).not.toBe("");
expect(value).not.toBe("common.refresh");
});
it("zh-CN uses a Chinese refresh label", () => {
expect(commonRefresh(zhCN)).toBe("刷新");
});
});
-117
View File
@@ -1,117 +0,0 @@
import { describe, expect, it } from "vitest";
import { readFileSync } from "node:fs";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function leafKeys(value: unknown, prefix = ""): string[] {
if (value === null || typeof value !== "object" || Array.isArray(value)) return [prefix];
return Object.entries(value as Record<string, unknown>).flatMap(([key, child]) => leafKeys(child, prefix ? `${prefix}.${key}` : key));
}
describe("Consul advanced UI locale parity", () => {
const expected = leafKeys((en as { consul: { ui: unknown } }).consul.ui).sort();
const expectedTools = leafKeys((en as { consul: { tools: unknown } }).consul.tools).sort();
it.each(locales)("%s exposes the full consul.ui key set", (_name, locale) => {
const ui = (locale as { consul: { ui: unknown } }).consul.ui;
expect(leafKeys(ui).sort()).toEqual(expected);
});
it.each(locales)("%s exposes the full consul.tools key set", (_name, locale) => {
const tools = (locale as { consul: { tools: unknown } }).consul.tools;
expect(leafKeys(tools).sort()).toEqual(expectedTools);
});
it("uses Chinese labels for the Consul KV workflow", () => {
const consul = (zhCN as { consul: { tools: Record<string, unknown>; keyLabel: string; valueContent: string; format: string } }).consul;
const tools = consul.tools;
expect(tools.search).toBe("全文搜索");
expect(tools.exportPrefix).toBe("导出");
expect(tools.import).toBe("导入");
expect(tools.migrate).toBe("同步");
expect(tools.deletePrefix).toBe("前缀删除");
expect(consul.keyLabel).toBe("键(Key)");
expect(consul.valueContent).toBe("值");
expect(consul.format).toBe("格式");
});
it("localizes Consul service, Session, and capability labels", () => {
const ui = (zhCN as { consul: { ui: Record<string, unknown> } }).consul.ui;
expect(ui.serviceKind).toBe("服务类型(ServiceKind)");
expect(ui.serviceWeights).toBe("通过 / 警告权重");
expect(ui.behaviorRelease).toBe("释放锁(release)");
expect(ui.behaviorDelete).toBe("删除 Key(delete)");
expect(ui.capabilityDisabled).toBe("未启用");
});
it.each(["ConsulOverview", "ConsulServices", "ConsulHealth", "ConsulSessions", "ConsulAcl", "ConsulScope", "ConsulMesh", "ConsulTools", "ConsulOperator", "ConsulWorkspace"])("%s uses the i18n composable", (component) => {
const source = readFileSync(new URL(`../../components/consul/${component}.vue`, import.meta.url), "utf8");
expect(source).toContain('import { useI18n } from "vue-i18n"');
expect(source).toContain("useI18n()");
});
it("keeps Consul user-facing labels out of component templates", () => {
const components = ["ConsulServices", "ConsulHealth", "ConsulSessions", "ConsulMesh", "ConsulKeyBrowser", "ConsulOperator"];
const forbidden = [
"Catalog nodes",
"No visible services",
"No visible nodes",
"Agent target:",
"Watch paused",
"Watching index",
"Pause watch",
"Start watch",
"HTTP Agent registrations belong",
"Catalog instances",
"Node services",
"Local Agent services",
"Enable maintenance",
"Disable maintenance",
"No matching health checks",
"Service instances",
"Local Agent checks",
'placeholder="Watch prefix"',
">Key</Badge>",
">Value</Badge>",
'placeholder="UPDATE AUTOPILOT"',
'placeholder="CHANGE KEYRING"',
'placeholder="UPDATE LICENSE"',
">ServiceKind<",
">Passing / Warning<",
">Node ID<",
">TaggedAddresses<",
">EnableTagOverride<",
">Behavior<",
">CreateIndex<",
">ModifyIndex<",
"Session {{ row.session }}",
];
for (const component of components) {
const source = readFileSync(new URL(`../../components/consul/${component}.vue`, import.meta.url), "utf8");
const template = source.slice(source.indexOf("<template>"));
for (const literal of forbidden) expect(template, `${component} contains ${literal}`).not.toContain(literal);
}
});
});
@@ -1,32 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
type Messages = {
customType: typeof en.customType;
contextMenu: typeof en.contextMenu;
};
const locales = { az, es, it: itLocale, ja, ko, "pt-BR": ptBR, tr, "zh-CN": zhCN, "zh-TW": zhTW } as unknown as Record<string, Messages>;
describe("custom type translations", () => {
it("provides localized labels in every supported non-English locale", () => {
for (const [localeName, messages] of Object.entries(locales)) {
expect(messages.customType.kinds.composite, localeName).not.toBe(en.customType.kinds.composite);
expect(messages.customType.tabs.properties, localeName).not.toBe(en.customType.tabs.properties);
expect(messages.customType.members.empty, localeName).not.toBe(en.customType.members.empty);
expect(messages.customType.properties.empty, localeName).not.toBe(en.customType.properties.empty);
expect(messages.customType.ddl.empty, localeName).not.toBe(en.customType.ddl.empty);
expect(messages.customType.ddl.incomplete, localeName).not.toBe(en.customType.ddl.incomplete);
expect(messages.contextMenu.viewDetails, localeName).not.toBe(en.contextMenu.viewDetails);
}
});
});
@@ -1,31 +0,0 @@
import { describe, expect, it } from "vitest";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
type ViewMessages = {
contextMenu: { compileObjectFailedTitle: string; compileObjectFailedMessage: string };
objects: { validStatus: string; invalidStatus: string };
};
const locales = { en, es, it: itLocale, ja, ko, "pt-BR": ptBR, "zh-CN": zhCN, "zh-TW": zhTW } as unknown as Record<string, ViewMessages>;
describe.each(Object.entries(locales))("Dameng view messages: %s", (localeName, messages) => {
it("provides a localized compilation failure with both placeholders", () => {
expect(messages.contextMenu.compileObjectFailedTitle).toBeTypeOf("string");
expect(messages.contextMenu.compileObjectFailedMessage).toContain("{name}");
expect(messages.contextMenu.compileObjectFailedMessage).toContain("{message}");
expect(messages.contextMenu.compileObjectFailedMessage).toContain("\n");
if (localeName !== "en") expect(messages.contextMenu.compileObjectFailedTitle).not.toBe(en.contextMenu.compileObjectFailedTitle);
});
it("preserves the database validity labels", () => {
expect(messages.objects.validStatus).toBe("VALID");
expect(messages.objects.invalidStatus).toBe("INVALID");
});
});
@@ -1,4 +1,3 @@
import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import i18n, { setLocale } from "@/i18n";
import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay";
@@ -8,9 +7,6 @@ import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay";
// Editor Settings "Execute Mode" label hardcode "(Cmd+Enter)" in every locale, including
// English, so the hints can disagree with both the current platform and a customized binding.
const toolbarSource = readFileSync(new URL("../../components/layout/EditorToolbar.vue", import.meta.url), "utf8");
const settingsDialogSource = readFileSync(new URL("../../components/editor/EditorSettingsDialog.vue", import.meta.url), "utf8");
describe("execute-shortcut hints reflect the configured binding", () => {
it.each([
["MacIntel", "Mod+Enter", "⌘ ↵"],
@@ -35,18 +31,4 @@ describe("execute-shortcut hints reflect the configured binding", () => {
expect(i18n.global.t("settings.executeModeDescription", { shortcut })).toBe("执行 SQL 快捷键:Ctrl + Shift + ↵。用于控制默认执行全部 SQL 或光标所在语句。");
await setLocale("en");
});
it("EditorToolbar.vue uses the saved executeSql shortcut", () => {
expect(toolbarSource).toContain("formatShortcutDisplay(settingsStore.editorSettings.shortcuts.executeSql)");
expect(toolbarSource).toMatch(/t\(\s*"toolbar\.executeShortcut"\s*,\s*\{\s*shortcut:\s*executeShortcutDisplay\.value/);
});
it("EditorSettingsDialog.vue uses the currently edited executeSql shortcut", () => {
expect(settingsDialogSource).toMatch(/function translateWithExecuteShortcut\([^)]*\)[^}]*formatShortcutDisplay\(editShortcuts\.value\.executeSql\)/);
expect(settingsDialogSource).toContain('translateWithExecuteShortcut("settings.executeModeDescription")');
});
it("EditorSettingsDialog.vue uses the same edited shortcut in settings search", () => {
expect(settingsDialogSource).toMatch(/resolveSettingsSearchEntries\(\s*\[[^\]]*\]\s*,\s*\{[^}]*\}\s*,\s*translateWithExecuteShortcut\s*,/s);
});
});
@@ -1,54 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
type Messages = Record<string, unknown>;
const locales: Array<[string, Messages]> = [
["az", az],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
const namespaces = ["multiDbExecute", "exportProgress"] as const;
function leafEntries(value: unknown, prefix = ""): Array<[string, string]> {
if (typeof value === "string") return [[prefix, value]];
if (value === null || typeof value !== "object" || Array.isArray(value)) return [];
return Object.entries(value as Messages).flatMap(([key, child]) => leafEntries(child, prefix ? `${prefix}.${key}` : key));
}
function placeholders(message: string): string[] {
return [...new Set([...message.matchAll(/\{([^{}]+)\}/g)].map((match) => match[1]))].sort();
}
describe.each(namespaces)("%s i18n namespace parity", (namespace) => {
const englishEntries = new Map(leafEntries((en as Messages)[namespace]));
it("english declares the namespace", () => {
expect(englishEntries.size).toBeGreaterThan(0);
});
it.each(locales)("%s declares the same keys and placeholders", (_name, locale) => {
const localeEntries = new Map(leafEntries(locale[namespace]));
expect([...localeEntries.keys()].sort()).toEqual([...englishEntries.keys()].sort());
for (const [key, englishMessage] of englishEntries) {
expect(placeholders(localeEntries.get(key) ?? ""), `${namespace}.${key}`).toEqual(placeholders(englishMessage));
}
});
});
+154
View File
@@ -0,0 +1,154 @@
import { describe, expect, it, vi } from "vitest";
import { createI18n } from "vue-i18n";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import itLocale from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
// Non-English locales export `withEnglishFallback({ ... })`, which deep-merges
// English underneath at import time, so an imported locale always "has" every
// English key and a dropped translation is invisible. Swap the merge for the
// identity to read what each locale file itself declares; the runtime check
// below re-applies the real merge.
vi.mock("../locales/fallback", () => ({ withEnglishFallback: (messages: Record<string, unknown>) => messages }));
type Messages = Record<string, unknown>;
type Locale = "az" | "en" | "es" | "it" | "ja" | "ko" | "pt-BR" | "tr" | "zh-CN" | "zh-TW";
const declared: Record<Locale, Messages> = { az, en, es, it: itLocale, ja, ko, "pt-BR": ptBR, tr, "zh-CN": zhCN, "zh-TW": zhTW };
const ALL_LOCALES = Object.keys(declared) as Locale[];
const EXCEPT_AZ_TR = ALL_LOCALES.filter((locale) => locale !== "az" && locale !== "tr");
interface FeatureMessages {
feature: string;
/** `a.b.key`, `a.b.*` (whole namespace, no extra keys) or `a.b.prefix*`, resolved against English. */
keys: string[];
/** Locales whose own file must declare every key; the others may fall back to English. */
locales?: Locale[];
/** The declared text must also differ from English. */
translated?: boolean;
}
const under = (namespace: string, keys: string[]) => keys.map((key) => `${namespace}.${key}`);
// Message sets that render in every UI language: a key missing from `en`
// leaks the raw key path, and a key missing from a locale silently shows
// English.
const FEATURE_MESSAGES: FeatureMessages[] = [
{ feature: "AI HTML preview (#6467)", keys: under("ai", ["htmlPreviewLabel", "htmlExpandPreview", "htmlExpandPreviewHint", "htmlSaveSafe", "htmlSaveFailed", "htmlCopySource", "htmlCopyRiskBody", "htmlCopyRiskAccept", "htmlCopyRiskRemember", "htmlCopyRiskToast"]) },
{ feature: "AI conversation export (#6467)", keys: under("ai", ["exportConversation", "conversationExportMarkdown", "conversationExportHtml", "conversationRoleUser", "conversationRoleAssistant", "conversationFailedMarker", "conversationExportEmpty"]) },
{ feature: "AI conversation management", keys: under("ai", ["renameConversation", "conversationRenameFailed", "clearDatabaseSelection", "searchDatabases", "noDatabasesFound"]) },
{ feature: "AI auto routing (#9118)", keys: ["ai.actions.auto", "ai.routing.recognizing", "ai.routing.chip", "ai.routing.switchTo", "ai.defaultAutoRouting", "ai.defaultAutoRoutingDescription"] },
{ feature: "plugin AI conversation", keys: ["ai.pluginHttpModelOnly", "ai.pluginWelcome", "ai.pluginFollowUp"] },
{ feature: "quick open", keys: ["quickOpen.*", "settings.shortcutGlobalSearch"] },
{
feature: "editor tab context menu",
keys: under("contextMenu", ["changeOrientation", "closeAllTabs", "closeLeftTabs", "closeOtherTabs", "closeRightTabs", "closeTab", "closeTabGroup", "compactTabTitle", "copyName", "editTabGroup", "fullTabTitle", "pinTab", "resetTabGroup", "splitDown", "splitRight", "unpinTab", "unsplit"]),
},
{ feature: "offline Agent export", keys: ["driverStore.offlineExport*"] },
{ feature: "offline Agent import", keys: ["driverStore.offlineImport*", "driverStore.offlineJreImport*"] },
{ feature: "multi-database execution and export progress", keys: ["multiDbExecute.*", "exportProgress.*"], locales: ["en", "zh-CN"] },
{ feature: "process list batch terminate", keys: under("processList", ["batchTerminate", "batchTerminateTitle", "batchTerminateConfirm", "batchTerminateRunning", "batchTerminateSummary"]) },
{ feature: "cached result fallback", keys: ["grid.cachedResultUnavailable", "grid.reexecuteQuery"] },
{ feature: "Nacos global replace", keys: ["nacos.contentReplace*", "nacos.replaceHistory.*"], locales: EXCEPT_AZ_TR, translated: true },
{ feature: "SQLite table rebuild notice", keys: ["structureEditor.sqliteRebuildNotice"] },
{ feature: "custom types", keys: ["customType.kinds.composite", "customType.tabs.properties", "customType.members.empty", "customType.properties.empty", "customType.ddl.empty", "customType.ddl.incomplete", "contextMenu.viewDetails"], translated: true },
{ feature: "Dameng object compilation", keys: ["contextMenu.compileObjectFailedTitle", "contextMenu.compileObjectFailedMessage"], locales: EXCEPT_AZ_TR, translated: true },
{ feature: "user administration Host change", keys: ["userAdmin.changeHost", "userAdmin.newHost"], translated: true },
{ feature: "plugin batch actions", keys: ["pluginPlatform.batchDuplicateSources", "pluginPlatform.batchRefreshFailed"], locales: EXCEPT_AZ_TR },
{ feature: "shared refresh action (#8768)", keys: ["common.refresh"] },
{ feature: "transfer bulk select", keys: under("transfer", ["bulkSelectObjects", "bulkSelectTitle", "bulkSelectHint", "bulkSelectPlaceholder", "bulkSelectConfirm", "bulkSelectMatched", "bulkSelectUnmatched", "noMatchingObjects"]), translated: true },
{ feature: "table info pin", keys: ["grid.pinTableInfo", "grid.unpinTableInfo"], translated: true },
{ feature: "Consul workspace", keys: ["consul.ui.*", "consul.tools.*"] },
{ feature: "MQTT max packet size", keys: ["connection.mqttMaxPacketSize"] },
{ feature: "sidebar search skip hint", keys: ["sidebar.searchConnectionSkipped"] },
{ feature: "PostgreSQL legacy TLS", keys: ["connection.postgresLegacyTls", "connection.postgresLegacyTlsHint"] },
{ feature: "settings search sections", keys: ["settings.syncWebDavWebDescription", "settings.performanceSection"] },
{ feature: "Redis batch expiration", keys: under("redis", ["batchExpiry", "batchExpiryTitle", "batchExpirySelected", "batchExpiryApply", "batchExpirySuccess", "batchExpiryPartial"]) },
];
function lookup(messages: unknown, path: string): unknown {
return path.split(".").reduce<unknown>((node, key) => (node && typeof node === "object" ? (node as Messages)[key] : undefined), messages);
}
function leafPaths(value: unknown, prefix = ""): string[] {
if (typeof value === "string") return [prefix];
if (!value || typeof value !== "object" || Array.isArray(value)) return [];
return Object.entries(value as Messages).flatMap(([key, child]) => leafPaths(child, prefix ? `${prefix}.${key}` : key));
}
function resolveKeys(selector: string): string[] {
if (!selector.endsWith("*")) return [selector];
const dot = selector.lastIndexOf(".");
const parent = selector.slice(0, dot);
const stem = selector.slice(dot + 1, -1);
const keys = leafPaths(lookup(en, parent))
.filter((path) => path.startsWith(stem))
.map((path) => `${parent}.${path}`);
expect(keys.length, `${selector} matches no English messages`).toBeGreaterThan(0);
return keys;
}
/** Named interpolations such as `{count}`; literal interpolations like `{'{'}` are text. */
function placeholders(message: unknown): string[] {
if (typeof message !== "string") return [];
return [...new Set([...message.matchAll(/\{\s*([A-Za-z_][\w]*)\s*\}/g)].map((match) => match[1]))].sort();
}
describe.each(FEATURE_MESSAGES)("$feature messages", ({ keys: selectors, locales = ALL_LOCALES, translated }) => {
const keys = selectors.flatMap(resolveKeys);
it.each(ALL_LOCALES)("%s declares its messages with the English placeholders", (locale) => {
for (const key of keys) {
const text = lookup(declared[locale], key);
const english = lookup(en, key);
if (text === undefined && !locales.includes(locale)) continue;
expect(text, `${locale}: ${key}`).toBeTypeOf("string");
expect((text as string).trim(), `${locale}: ${key}`).not.toBe("");
expect(placeholders(text), `${locale}: ${key} placeholders`).toEqual(placeholders(english));
if (translated && locale !== "en") expect(text, `${locale}: ${key} must not reuse the English text`).not.toBe(english);
}
for (const selector of selectors.filter((entry) => entry.endsWith(".*"))) {
const namespace = selector.slice(0, -2);
const extra = leafPaths(lookup(declared[locale], namespace)).filter((path) => !keys.includes(`${namespace}.${path}`));
expect(extra, `${locale}: keys under ${namespace} that English does not declare`).toEqual([]);
}
});
});
describe("feature message rendering", () => {
const keys = FEATURE_MESSAGES.flatMap((entry) => entry.keys.flatMap(resolveKeys));
it.each(ALL_LOCALES)("%s renders every feature message through vue-i18n with its parameters", async (locale) => {
const { withEnglishFallback } = await vi.importActual<typeof import("../locales/fallback")>("../locales/fallback");
const messages = locale === "en" ? en : withEnglishFallback(declared[locale]);
const i18n = createI18n({ legacy: false, locale, messages: { [locale]: messages }, missingWarn: false, fallbackWarn: false });
for (const key of keys) {
const params = Object.fromEntries(placeholders(lookup(messages, key)).map((name) => [name, `<${name}>`]));
const text = i18n.global.t(key, params);
expect(text, `${locale}: ${key}`).not.toBe(key);
for (const value of Object.values(params)) expect(text, `${locale}: ${key}`).toContain(value);
}
i18n.dispose();
});
});
describe("feature message content rules", () => {
it.each(EXCEPT_AZ_TR)("%s keeps the Dameng validity labels as the database literals", (locale) => {
const objects = (locale === "en" ? en : declared[locale]).objects as Messages | undefined;
expect(objects?.validStatus ?? en.objects.validStatus).toBe("VALID");
expect(objects?.invalidStatus ?? en.objects.invalidStatus).toBe("INVALID");
});
it.each(ALL_LOCALES)("%s warns that a SQLite rebuild forces CAST conversion with lossy 0.0 values", (locale) => {
const notice = String(lookup(declared[locale], "structureEditor.sqliteRebuildNotice"));
expect(notice).toContain("CAST");
expect(notice).toContain("0.0");
});
});
@@ -1,104 +0,0 @@
import { readFileSync } from "node:fs";
import { createI18n } from "vue-i18n";
import { describe, expect, it } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
// These assertions read the locale SOURCES as text instead of importing the modules.
// Every non-English locale is `export default withEnglishFallback({ ... })`, and
// withEnglishFallback deep-merges `en` UNDER the locale at import time, so the imported
// default export already carries every english key — including the key this spec exists
// to guard. Asserting on those objects would pass even if a locale silently dropped the
// label (same trap documented in docsNamespaceParity.spec.ts), so the check has to happen
// before the merge does.
function localeSource(name: string): string {
return readFileSync(new URL(`../locales/${name}.ts`, import.meta.url), "utf8");
}
function declaredString(source: string, key: string): string | undefined {
return source.match(new RegExp(String.raw`^\s*${key}:\s*"((?:[^"\\]|\\.)*)",\s*$`, "m"))?.[1];
}
// The locales that carry the connection.mqtt* form cluster (led by mqttKeepAlive).
const localesCarryingMqttCluster = ["en", "zh-CN", "zh-TW", "ja", "it", "es", "pt-BR", "tr", "az"];
// Every locale FILE must declare the key in source. This is the assertion that actually
// guards drift: the imported modules cannot show a removed source key, because
// withEnglishFallback deep-merges english underneath at import time (see header).
const allLocaleFiles = [...localesCarryingMqttCluster, "ko"];
describe("mqtt max packet size label i18n parity", () => {
it("english declares the label with its byte unit", () => {
expect(declaredString(localeSource("en"), "mqttMaxPacketSize")).toContain("bytes");
});
it.each(allLocaleFiles)("%s declares the label in its source file", (name) => {
const label = declaredString(localeSource(name), "mqttMaxPacketSize");
expect(label, `${name}.ts must declare connection.mqttMaxPacketSize`).toBeTruthy();
expect(label?.trim()).not.toBe("");
});
it.each(localesCarryingMqttCluster)("%s declares the label alongside its mqtt cluster", (name) => {
const source = localeSource(name);
// Anchor: only locales that already declare the cluster get the new key.
expect(declaredString(source, "mqttKeepAlive"), `${name}.ts must declare connection.mqttKeepAlive`).toBeTruthy();
// Semantic-cluster anchoring (i18n-locales.md): the label belongs next to mqttConnectTimeout.
expect(source.indexOf("mqttMaxPacketSize:"), `${name}.ts must anchor the key after mqttConnectTimeout`).toBeGreaterThan(source.indexOf("mqttConnectTimeout:"));
});
it("ko declares the label without taking on the rest of the mqtt form cluster", () => {
const source = localeSource("ko");
// ko translates a few mqtt console strings but none of the form fields, so the form
// renders in english there via withEnglishFallback. This one label is the deliberate
// exception: it is declared in source so the Korean text exists in the file, and it is
// the only form key ko owns — do not grow the cluster here.
expect(declaredString(source, "mqttMaxPacketSize")).toBeTruthy();
expect(declaredString(source, "mqttKeepAlive")).toBeUndefined();
expect(declaredString(source, "mqttConnectTimeout")).toBeUndefined();
});
});
// Layer (a) from the PRD: the label must also resolve through vue-i18n at runtime. This is
// weaker than the source-level check above — the deep-merge hands a locale that drops the
// key the english text, so it cannot see drift — but it is what catches a locale module
// that fails to declare or parse the key at all, and the "key path leaks into the UI"
// failure mode that a missing translation produces.
const localeModules: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", itLocale],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
describe("mqtt max packet size label resolution", () => {
it.each(localeModules)("%s resolves the label to a translated string", (name, messages) => {
const connection = (messages.connection ?? {}) as typeof en.connection;
const i18n = createI18n({ legacy: false, locale: name, messages: { [name]: { connection } } });
const label = i18n.global.t("connection.mqttMaxPacketSize");
expect(label).not.toBe("connection.mqttMaxPacketSize");
expect(label.trim()).not.toBe("");
i18n.dispose();
});
});
describe("connection dialog mqtt label call site", () => {
const componentSource = readFileSync(new URL("../../components/connection/ConnectionDialog.vue", import.meta.url), "utf8");
it("renders the label through vue-i18n instead of a hardcoded chinese string", () => {
expect(componentSource).toContain('{{ t("connection.mqttMaxPacketSize") }}');
expect(componentSource).not.toContain("最大报文");
});
});
@@ -1,38 +0,0 @@
import { describe, expect, it } from "vitest";
import en from "../locales/en";
import es from "../locales/es";
import itLocale from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
function entries(value: unknown, prefix = ""): Array<[string, string]> {
if (typeof value === "string") return [[prefix, value]];
if (value === null || typeof value !== "object" || Array.isArray(value)) return [];
return Object.entries(value as Record<string, unknown>).flatMap(([key, child]) => entries(child, prefix ? `${prefix}.${key}` : key));
}
function placeholders(message: string): string[] {
return [...message.matchAll(/\{[^{}]+\}/g)].map(([match]) => match).sort();
}
const source = new Map(entries(zhCN.nacos).filter(([key]) => key.startsWith("contentReplace") || key.startsWith("replaceHistory.")));
const english = new Map(entries(en.nacos));
const locales = { en, es, it: itLocale, ja, ko, "pt-BR": ptBR, "zh-TW": zhTW };
describe("Nacos global replacement translations", () => {
it("declares the new source messages", () => {
expect(source.size).toBe(51);
});
it.each(Object.entries(locales))("%s has localized messages with matching placeholders", (name, locale) => {
const translated = new Map(entries(locale.nacos));
for (const [key, text] of source) {
expect(translated.get(key), key).toBeTruthy();
expect(placeholders(translated.get(key) ?? ""), key).toEqual(placeholders(text));
if (name !== "en") expect(translated.get(key), `${name}:${key} must not fall back to English`).not.toBe(english.get(key));
}
});
});
@@ -1,24 +0,0 @@
import { describe, expect, it } from "vitest";
import { createI18n } from "vue-i18n";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
describe("plugin batch messages", () => {
it.each(Object.entries({ az, en, es, it: itLocale, ja, ko, "pt-BR": ptBR, tr, "zh-CN": zhCN, "zh-TW": zhTW }))("interpolates source conflicts and refresh errors in %s", (locale, messages) => {
const pluginPlatform = messages.pluginPlatform as Pick<typeof en.pluginPlatform, "batchDuplicateSources" | "batchRefreshFailed">;
const i18n = createI18n({ legacy: false, locale, messages: { [locale]: { pluginPlatform } } });
expect(pluginPlatform.batchDuplicateSources.match(/\{[^}]+\}/g)).toEqual(["{names}"]);
expect(pluginPlatform.batchRefreshFailed.match(/\{[^}]+\}/g)).toEqual(["{error}"]);
expect(i18n.global.t("pluginPlatform.batchDuplicateSources", { names: "example.plugin" })).toContain("example.plugin");
expect(i18n.global.t("pluginPlatform.batchRefreshFailed", { error: "refresh offline" })).toContain("refresh offline");
i18n.dispose();
});
});
@@ -1,46 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
const BATCH_TERMINATE_KEYS = ["batchTerminate", "batchTerminateTitle", "batchTerminateConfirm", "batchTerminateRunning", "batchTerminateSummary"];
describe("process list batch terminate locale parity", () => {
it.each(locales)("%s ships every batch terminate key", (_name, locale) => {
const processList = (locale as { processList: Record<string, unknown> }).processList;
for (const key of BATCH_TERMINATE_KEYS) {
expect(typeof processList[key]).toBe("string");
expect(String(processList[key]).trim().length).toBeGreaterThan(0);
}
});
it("keeps the count and summary placeholders in every locale", () => {
for (const [_name, locale] of locales) {
const processList = (locale as { processList: Record<string, string> }).processList;
expect(processList.batchTerminate).toContain("{count}");
expect(processList.batchTerminateConfirm).toContain("{count}");
expect(processList.batchTerminateSummary).toContain("{succeeded}");
expect(processList.batchTerminateSummary).toContain("{failed}");
}
});
});
@@ -1,59 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
type Messages = Record<string, unknown>;
const locales: Array<[string, Messages]> = [
["az", az],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
const namespaces = ["quickOpen"] as const;
function leafEntries(value: unknown, prefix = ""): Array<[string, string]> {
if (typeof value === "string") return [[prefix, value]];
if (value === null || typeof value !== "object" || Array.isArray(value)) return [];
return Object.entries(value as Messages).flatMap(([key, child]) => leafEntries(child, prefix ? `${prefix}.${key}` : key));
}
describe.each(namespaces)("%s i18n namespace parity", (namespace) => {
const englishEntries = new Map(leafEntries((en as Messages)[namespace]));
it("english declares the namespace", () => {
expect(englishEntries.size).toBeGreaterThan(0);
});
it("english declares the global-search keys", () => {
for (const key of ["searchingContent", "globalSearchHint", "modeObjects", "modeContent", "contentPlaceholder", "searchSettings", "searchRoots", "addDirectory", "noRootsConfigured", "removePath", "searchExtensions", "extensionsPlaceholder", "apply"]) {
expect(englishEntries.has(key), `missing quickOpen.${key}`).toBe(true);
}
});
it.each(locales)("%s declares the same keys", (_name, locale) => {
const localeEntries = new Map(leafEntries(locale[namespace]));
expect([...localeEntries.keys()].sort()).toEqual([...englishEntries.keys()].sort());
});
it("every locale declares the globalSearch shortcut label", () => {
for (const [name, locale] of locales) {
const settings = locale.settings as Messages | undefined;
expect(settings?.shortcutGlobalSearch, `${name}.settings.shortcutGlobalSearch`).toBeTruthy();
}
});
});
@@ -1,71 +0,0 @@
import { readFileSync } from "node:fs";
import { createI18n } from "vue-i18n";
import { describe, expect, it } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
// The sidebar-search skip hint is a single-line projection of a driver error
// (see connectionStore.recordSidebarSearchConnectionFailure). Every locale has
// to own the `{message}` placeholder, so this reads the locale SOURCES as text:
// non-English locales are `export default withEnglishFallback({ ... })`, and the
// import-time deep merge would hide a locale that silently dropped the key.
function localeSource(name: string): string {
return readFileSync(new URL(`../locales/${name}.ts`, import.meta.url), "utf8");
}
function declaredString(source: string, key: string): string | undefined {
return source.match(new RegExp(String.raw`^\s*${key}:\s*"((?:[^"\\]|\\.)*)",\s*$`, "m"))?.[1];
}
const localeNames = ["az", "en", "es", "it", "ja", "ko", "pt-BR", "tr", "zh-CN", "zh-TW"];
describe("sidebar search skip hint i18n parity", () => {
it("english declares the key with its message placeholder", () => {
const label = declaredString(localeSource("en"), "searchConnectionSkipped");
expect(label).toContain("{message}");
});
it.each(localeNames)("%s declares the key with the message placeholder in its source file", (name) => {
const label = declaredString(localeSource(name), "searchConnectionSkipped");
expect(label, `${name}.ts must declare sidebar.searchConnectionSkipped`).toBeTruthy();
expect(label).toContain("{message}");
});
it.each(localeNames)("%s anchors the key inside the sidebar namespace", (name) => {
const source = localeSource(name);
expect(source.indexOf("searchConnectionSkipped:")).toBeGreaterThan(source.indexOf("sortConnectionsDescending:"));
expect(source.indexOf("searchConnectionSkipped:")).toBeLessThan(source.indexOf("searchScopeConnection:"));
});
});
const localeModules: Array<[string, Record<string, unknown>]> = [
["az", az],
["en", en],
["es", es],
["it", itLocale],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
describe("sidebar search skip hint resolution", () => {
it.each(localeModules)("%s renders the driver detail inside the hint", (name, messages) => {
const sidebar = (messages.sidebar ?? {}) as typeof en.sidebar;
const i18n = createI18n({ legacy: false, locale: name, messages: { [name]: { sidebar } } });
const hint = i18n.global.t("sidebar.searchConnectionSkipped", { message: "tls handshake eof" });
expect(hint).not.toBe("sidebar.searchConnectionSkipped");
expect(hint).toContain("tls handshake eof");
i18n.dispose();
});
});
@@ -1,37 +0,0 @@
import { describe, expect, it as test } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import it from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
function sqliteRebuildNotice(messages: Record<string, unknown>): string {
const structureEditor = messages.structureEditor as Record<string, unknown>;
return String(structureEditor.sqliteRebuildNotice);
}
describe("SQLite rebuild notice", () => {
test.each([
["Azerbaijani", az],
["English", en],
["Spanish", es],
["Italian", it],
["Japanese", ja],
["Korean", ko],
["Brazilian Portuguese", ptBR],
["Turkish", tr],
["Simplified Chinese", zhCN],
["Traditional Chinese", zhTW],
])("warns about retained backup, forced CAST conversion, lossy values, and rollback in %s", (_locale, messages) => {
const notice = sqliteRebuildNotice(messages);
expect(notice.length).toBeGreaterThan(30);
expect(notice).toContain("CAST");
expect(notice).toContain("0.0");
});
});
@@ -1,57 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
// EditorGroupTabBar renders its context menu via `t("contextMenu.<key>")`.
// When a key is missing everywhere, vue-i18n echoes the key path itself and
// the menu shows raw text like "contextMenu.pinTab" (regression in 5a3a6e2bb:
// the component landed without locale entries; spec mocks supplied their own
// translations, so tests stayed green). en is the fallbackLocale, so a missing
// en key leaks the raw path in every language — guard the full tab-menu key
// set against the real en module, not a mock.
const tabMenuKeys = ["changeOrientation", "closeAllTabs", "closeLeftTabs", "closeOtherTabs", "closeRightTabs", "closeTab", "closeTabGroup", "compactTabTitle", "copyName", "editTabGroup", "fullTabTitle", "pinTab", "resetTabGroup", "splitDown", "splitRight", "unpinTab", "unsplit"] as const;
// Non-English locales are `export default withEnglishFallback({...})`, so
// these imports are en-merged; the assertions below prove the key resolves to
// real text for every UI language, while the en test above is the one that
// actually catches a missing-from-everywhere key.
const locales: Array<[string, Record<string, unknown>]> = [
["az", az as Record<string, unknown>],
["en", en as Record<string, unknown>],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function contextMenuEntry(locale: Record<string, unknown>, key: string): unknown {
const contextMenu = locale["contextMenu"];
if (!contextMenu || typeof contextMenu !== "object") return undefined;
return (contextMenu as Record<string, unknown>)[key];
}
describe("tab context menu i18n keys", () => {
it.each(tabMenuKeys)("en resolves contextMenu.%s to text", (key) => {
const value = contextMenuEntry(en as Record<string, unknown>, key);
expect(value, `contextMenu.${key} missing from locales/en.ts`).toBeTypeOf("string");
expect(value).not.toBe("");
});
it.each(locales)("%s resolves pin/unpin tab menu labels", (_name, locale) => {
for (const key of ["pinTab", "unpinTab"] as const) {
expect(contextMenuEntry(locale, key), `${_name} contextMenu.${key}`).toBeTypeOf("string");
}
});
});
@@ -1,44 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
const locales: Array<[string, Record<string, unknown>]> = [
["en", en as Record<string, unknown>],
["az", az as Record<string, unknown>],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function gridEntry(locale: Record<string, unknown>, key: string): unknown {
const grid = locale["grid"];
if (!grid || typeof grid !== "object") return undefined;
return (grid as Record<string, unknown>)[key];
}
describe("table-info pin i18n messages", () => {
it.each(["pinTableInfo", "unpinTableInfo"] as const)("en resolves grid.%s to text", (key) => {
expect(gridEntry(en as Record<string, unknown>, key), `grid.${key} missing from locales/en.ts`).toBeTypeOf("string");
});
it.each(locales.slice(1))("%s translates table-info pin labels instead of using the English fallback", (_name, locale) => {
for (const key of ["pinTableInfo", "unpinTableInfo"] as const) {
const value = gridEntry(locale, key);
expect(value, `${_name} grid.${key}`).toBeTypeOf("string");
expect(value).not.toBe(gridEntry(en as Record<string, unknown>, key));
}
});
});
@@ -1,47 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "../locales/az";
import en from "../locales/en";
import es from "../locales/es";
import it_ from "../locales/it";
import ja from "../locales/ja";
import ko from "../locales/ko";
import ptBR from "../locales/pt-BR";
import tr from "../locales/tr";
import zhCN from "../locales/zh-CN";
import zhTW from "../locales/zh-TW";
// 数据传输「批量录入对象」相关文案,需要所有语言齐全,避免回落到英文
const TRANSFER_BULK_SELECT_KEYS = ["bulkSelectObjects", "bulkSelectTitle", "bulkSelectHint", "bulkSelectPlaceholder", "bulkSelectConfirm", "bulkSelectMatched", "bulkSelectUnmatched", "noMatchingObjects"] as const;
const locales: Array<[string, Record<string, unknown>]> = [
["en", en as Record<string, unknown>],
["az", az as Record<string, unknown>],
["es", es],
["it", it_],
["ja", ja],
["ko", ko],
["pt-BR", ptBR],
["tr", tr],
["zh-CN", zhCN],
["zh-TW", zhTW],
];
function transferEntry(locale: Record<string, unknown>, key: string): unknown {
const transfer = locale["transfer"];
if (!transfer || typeof transfer !== "object") return undefined;
return (transfer as Record<string, unknown>)[key];
}
describe("transfer bulk-select i18n messages", () => {
it.each(TRANSFER_BULK_SELECT_KEYS)("en resolves transfer.%s to text", (key) => {
expect(transferEntry(en as Record<string, unknown>, key), `transfer.${key} missing from locales/en.ts`).toBeTypeOf("string");
});
it.each(locales.slice(1))("%s translates the bulk-select labels instead of using the English fallback", (_name, locale) => {
for (const key of TRANSFER_BULK_SELECT_KEYS) {
const value = transferEntry(locale, key);
expect(value, `${_name} transfer.${key}`).toBeTypeOf("string");
expect(value, `${_name} transfer.${key} should not reuse the English text`).not.toBe(transferEntry(en as Record<string, unknown>, key));
}
});
});
@@ -1,26 +0,0 @@
import { describe, expect, it } from "vitest";
import az from "@/i18n/locales/az";
import en from "@/i18n/locales/en";
import es from "@/i18n/locales/es";
import itLocale from "@/i18n/locales/it";
import ja from "@/i18n/locales/ja";
import ko from "@/i18n/locales/ko";
import ptBR from "@/i18n/locales/pt-BR";
import tr from "@/i18n/locales/tr";
import zhCN from "@/i18n/locales/zh-CN";
import zhTW from "@/i18n/locales/zh-TW";
describe("user administration Host translations", () => {
it("provides the Host-change labels in English", () => {
expect(en.userAdmin.changeHost).toEqual(expect.any(String));
expect(en.userAdmin.newHost).toEqual(expect.any(String));
});
it("provides localized Host-change labels in every non-English locale", () => {
const locales = { az, es, it: itLocale, ja, ko, "pt-BR": ptBR, tr, "zh-CN": zhCN, "zh-TW": zhTW };
for (const [locale, messages] of Object.entries(locales)) {
expect(messages.userAdmin.changeHost, locale).not.toBe(en.userAdmin.changeHost);
expect(messages.userAdmin.newHost, locale).not.toBe(en.userAdmin.newHost);
}
});
});