diff --git a/packages/i18n/package.json b/packages/i18n/package.json index 27b34363..0ea760e2 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -3,13 +3,12 @@ "version": "0.0.0", "private": true, "type": "module", - "sideEffects": false, "scripts": { "typecheck": "tsc -p tsconfig.json --noEmit", "clean": "rimraf .turbo node_modules dist" }, "exports": { - ".": "./src/index.ts" + ".": "./src/i18n.ts" }, "dependencies": { "i18next": "25.6.0", diff --git a/packages/i18n/src/i18n.ts b/packages/i18n/src/i18n.ts index 2e057414..5e5964a3 100644 --- a/packages/i18n/src/i18n.ts +++ b/packages/i18n/src/i18n.ts @@ -1,10 +1,20 @@ -import i18next, { type i18n } from "i18next"; +import i18n from "i18next"; import LanguageDetector from "i18next-browser-languagedetector"; import { initReactI18next } from "react-i18next"; -let hasInit = false; +i18n + .use(LanguageDetector) + .use(initReactI18next) + .init({ + detection: { order: ["navigator"] }, + debug: true, + fallbackLng: "es", + interpolation: { escapeValue: false }, + }); -export const initI18Next = () => { +export { i18n }; + +/*export const initI18Next = () => { if (hasInit) return i18next; i18next @@ -12,14 +22,14 @@ export const initI18Next = () => { .use(initReactI18next) .init({ detection: { order: ["navigator"] }, - debug: false, + debug: true, fallbackLng: "es", interpolation: { escapeValue: false }, }); hasInit = true; return i18next; -}; +};*/ /** * Registra dinámicamente traducciones de un módulo. @@ -33,25 +43,16 @@ export const registerTranslations = ( locale: string, resources: Record ): void => { - if (!hasInit) { + /*if (!hasInit) { throw new Error("i18n not initialized. Call initI18Next() first."); - } + }*/ const ns = moduleName; - const alreadyExists = i18next.hasResourceBundle(locale, ns); + const alreadyExists = i18n.hasResourceBundle(locale, ns); if (!alreadyExists) { - i18next.addResourceBundle(locale, ns, resources, true, true); + console.log("cargando => ", moduleName, locale); + i18n.addResourceBundle(locale, ns, resources, true, true); } }; - -/** - * Acceso al `t()` global por si se necesita en librerías de backend. - */ -export const t = (...args: Parameters) => { - if (!hasInit) { - throw new Error("i18n not initialized. Call initI18Next() first."); - } - return i18next.t(...args); -}; diff --git a/packages/i18n/src/index.ts b/packages/i18n/src/index.ts deleted file mode 100644 index 0c4205e0..00000000 --- a/packages/i18n/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./i18n"; diff --git a/packages/rdx-ui/package.json b/packages/rdx-ui/package.json index 908b601b..53ad8c14 100644 --- a/packages/rdx-ui/package.json +++ b/packages/rdx-ui/package.json @@ -23,6 +23,7 @@ }, "devDependencies": { "@biomejs/biome": "^2.3.1", + "@repo/i18next": "workspace:*", "@repo/typescript-config": "workspace:*", "@tailwindcss/postcss": "^4.1.5", "@turbo/gen": "^2.5.2",