From 9e6aa61e090941a85a80208a62fa88e10f28413a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 23:05:20 -0400 Subject: [PATCH] feat(i18n): dev-mode warn on missing translation keys, default-locale fallback (P3-54) Missing keys now log a console.warn in dev; at runtime the default-locale dict is consulted before falling back to the raw key so zh users are not shown literal keys when a zh translation is absent. --- src/renderer/i18n/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/i18n/index.ts b/src/renderer/i18n/index.ts index 8ad921f5..87354115 100644 --- a/src/renderer/i18n/index.ts +++ b/src/renderer/i18n/index.ts @@ -10,7 +10,16 @@ export type TranslationFn = (key: string, fallback?: string) => string; export function createTranslator(locale: AppLocale): TranslationFn { const dict = translations[locale] ?? translations[DEFAULT_LOCALE]; - return (key: string, fallback?: string) => dict[key] ?? fallback ?? key; + const defaultDict = translations[DEFAULT_LOCALE]; + return (key: string, fallback?: string) => { + const value = dict[key]; + if (value !== undefined) return value; + if (import.meta.env.DEV && !defaultDict[key] && fallback === undefined) { + + console.warn(`[i18n] missing translation key: ${key}`); + } + return defaultDict[key] ?? fallback ?? key; + }; } export const LocaleContext = createContext(DEFAULT_LOCALE);