import i18n from "i18next"; import LanguageDetector from "i18next-browser-languagedetector"; import { initReactI18next } from "react-i18next"; i18n .use(LanguageDetector) .use(initReactI18next) .init({ detection: { order: ["navigator"] }, debug: false, fallbackLng: "es", interpolation: { escapeValue: false }, }); export { i18n }; /*export const initI18Next = () => { if (hasInit) return i18next; i18next .use(LanguageDetector) .use(initReactI18next) .init({ detection: { order: ["navigator"] }, debug: true, fallbackLng: "es", interpolation: { escapeValue: false }, }); hasInit = true; return i18next; };*/ /** * Registra dinámicamente traducciones de un módulo. * * Cada módulo tendrá su propio namespace. * * idempotente: si el bundle ya existe, no se vuelve a añadir. */ export const registerTranslations = ( moduleName: string, locale: string, resources: Record ): void => { /*if (!hasInit) { throw new Error("i18n not initialized. Call initI18Next() first."); }*/ const ns = moduleName; const alreadyExists = i18n.hasResourceBundle(locale, ns); if (!alreadyExists) { i18n.addResourceBundle(locale, ns, resources, true, true); } };