i18n.init() is async by default. With initImmediate: false, it initializes synchronously so translations are ready before React hydrates. Without this, useTranslation() runs before i18n is ready, showing raw translation keys. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
781 B
TypeScript
31 lines
781 B
TypeScript
import i18n from "i18next";
|
|
import { initReactI18next } from "react-i18next";
|
|
import LanguageDetector from "i18next-browser-languagedetector";
|
|
import en from "./locales/en.ts";
|
|
import de from "./locales/de.ts";
|
|
|
|
export const defaultNS = "common";
|
|
|
|
export const resources = {
|
|
en: { common: en.common, planner: en.planner, journal: en.journal },
|
|
de: { common: de.common, planner: de.planner, journal: de.journal },
|
|
} as const;
|
|
|
|
export function initI18n() {
|
|
return i18n
|
|
.use(LanguageDetector)
|
|
.use(initReactI18next)
|
|
.init({
|
|
resources,
|
|
defaultNS,
|
|
fallbackLng: "en",
|
|
supportedLngs: ["en", "de"],
|
|
interpolation: {
|
|
escapeValue: false,
|
|
},
|
|
showSupportNotice: false,
|
|
initImmediate: false,
|
|
});
|
|
}
|
|
|
|
export { i18n };
|