mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 10:21:16 +08:00
fix(i18n): prevent zh-TW tool management fallbacks (#5943)
Complete the Traditional Chinese strings for the About-page tool manager and align the install/update hint with the current supported tools. Add locale coverage that requires every tool-management label and preserves interpolation variables across all four translations. Constraint: The About tool manager was extended across three commits without matching zh-TW entries. Rejected: Rely on i18next fallback text | leaves the Traditional Chinese UI partially English and hides future locale drift. Confidence: high Scope-risk: narrow Directive: Update toolManagementLocales.test.ts whenever the About tool manager adds a translatable label. Tested: pnpm typecheck; pnpm format:check; 7 locale tests; 575 Vitest tests; zero missing zh-TW settings keys Not-tested: Manual visual inspection of the About page Related:e3df86587,ea604a182,014c82d28
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import en from "@/i18n/locales/en.json";
|
||||
import ja from "@/i18n/locales/ja.json";
|
||||
import zhTW from "@/i18n/locales/zh-TW.json";
|
||||
import zh from "@/i18n/locales/zh.json";
|
||||
|
||||
const requiredKeys = [
|
||||
"manualInstallCommands",
|
||||
"updateAllTools",
|
||||
"currentVersion",
|
||||
"latestVersion",
|
||||
"updateAvailableShort",
|
||||
"toolInstall",
|
||||
"toolUpdate",
|
||||
"toolReady",
|
||||
"toolActionDone",
|
||||
"toolActionPartial",
|
||||
"toolActionFailed",
|
||||
"toolNotRunnable",
|
||||
"toolActionVersionUnchangedTitle",
|
||||
"toolActionVersionUnchanged",
|
||||
"toolActionInstalledNotRunnable",
|
||||
"installedNotRunnable",
|
||||
"toolCheckEnv",
|
||||
"toolDiagnose",
|
||||
"toolDiagnosing",
|
||||
"toolConflictTitle",
|
||||
"toolConflictHint",
|
||||
"toolConflictDefault",
|
||||
"toolConflictNotRunnable",
|
||||
"toolDiagnoseNoConflict",
|
||||
"toolDiagnoseFailed",
|
||||
"toolUpgradeConfirmTitle",
|
||||
"toolUpgradeConfirmHint",
|
||||
"toolUpgradeWillRun",
|
||||
"toolUpgradeConfirmBtn",
|
||||
"toolUpgradeUnanchoredHint",
|
||||
] as const;
|
||||
|
||||
type SettingsTranslations = Record<string, unknown>;
|
||||
|
||||
const locales = [
|
||||
["en", en.settings],
|
||||
["ja", ja.settings],
|
||||
["zh", zh.settings],
|
||||
["zh-TW", zhTW.settings],
|
||||
] as const;
|
||||
|
||||
function interpolationVariables(value: string): string[] {
|
||||
return Array.from(
|
||||
value.matchAll(/\{\{([^}]+)\}\}/g),
|
||||
([, name]) => name,
|
||||
).sort();
|
||||
}
|
||||
|
||||
describe("About tool management locale coverage", () => {
|
||||
it.each(locales)(
|
||||
"defines every tool management key in %s",
|
||||
(_locale, settings) => {
|
||||
const missing = requiredKeys.filter((key) => {
|
||||
const value = (settings as SettingsTranslations)[key];
|
||||
return typeof value !== "string" || value.trim().length === 0;
|
||||
});
|
||||
|
||||
expect(missing).toEqual([]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(locales.slice(1))(
|
||||
"preserves interpolation variables in %s",
|
||||
(_locale, settings) => {
|
||||
for (const key of requiredKeys) {
|
||||
const expected = en.settings[key];
|
||||
const actual = (settings as SettingsTranslations)[key];
|
||||
|
||||
expect(typeof actual).toBe("string");
|
||||
expect(interpolationVariables(actual as string)).toEqual(
|
||||
interpolationVariables(expected),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user