Files
DeepTutor/web/i18n/init.ts
Philipp Eisbacher 9b139a772f feat(i18n): add German as a full interface language
Adds `de` alongside en/zh/fr/uk, following the seams the Ukrainian locale
established: the interface-language normalizers (settings + launcher), the
Settings language list, APP_LANGUAGES / normalizeLanguage, the lazy bundle
loader, the date locale, the CLI banner labels, the quiz-judge prompt and
the i18n audit's required locales. German already existed as a reply
language; this makes it selectable for the UI as well.

`web/locales/de/app.json` covers all 5200 English keys (audit: 3850/3850
used keys, strict). `language.german` is added to every catalog.

Tests: `tests/i18n/test_german_locale.py` pins each seam, and
`web/tests/german-locale-quality.test.ts` guards terminology (informal
"du", one term per concept, no context-free machine translations such as
"Lappen" for RAG). Three existing tests used `de` as their example of an
unsupported language; they now use `xx`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 22:00:58 +02:00

58 lines
1.7 KiB
TypeScript

import i18n, { type Resource } from "i18next";
import { initReactI18next } from "react-i18next";
import enApp from "@/locales/en/app.json";
import { normalizeLanguage, type AppLanguage } from "./languages";
export { APP_LANGUAGES, isAppLanguage, normalizeLanguage } from "./languages";
export type { AppLanguage } from "./languages";
let _initialized = false;
export function initI18n(language?: unknown) {
if (_initialized) return i18n;
const resources: Resource = {
en: { app: enApp },
};
i18n.use(initReactI18next).init({
resources,
lng: normalizeLanguage(language),
fallbackLng: "en",
// Use a single default namespace to keep lookups simple.
// We intentionally keep keySeparator disabled so keys like "Generating..." remain valid.
defaultNS: "app",
ns: ["app"],
keySeparator: false,
interpolation: {
escapeValue: false,
},
returnEmptyString: false,
returnNull: false,
});
_initialized = true;
return i18n;
}
export async function ensureLanguage(language: AppLanguage) {
if (i18n.hasResourceBundle(language, "app")) return;
if (language === "zh") {
const zhApp = (await import("@/locales/zh/app.json")).default;
i18n.addResourceBundle("zh", "app", zhApp, true, true);
}
if (language === "fr") {
const frApp = (await import("@/locales/fr/app.json")).default;
i18n.addResourceBundle("fr", "app", frApp, true, true);
}
if (language === "de") {
const deApp = (await import("@/locales/de/app.json")).default;
i18n.addResourceBundle("de", "app", deApp, true, true);
}
if (language === "uk") {
const ukApp = (await import("@/locales/uk/app.json")).default;
i18n.addResourceBundle("uk", "app", ukApp, true, true);
}
}