Arreglo de idiomas en producción
This commit is contained in:
parent
8b5678da5a
commit
07e873bb36
@ -3,13 +3,12 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"sideEffects": false,
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typecheck": "tsc -p tsconfig.json --noEmit",
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
||||||
"clean": "rimraf .turbo node_modules dist"
|
"clean": "rimraf .turbo node_modules dist"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/i18n.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"i18next": "25.6.0",
|
"i18next": "25.6.0",
|
||||||
|
|||||||
@ -1,10 +1,20 @@
|
|||||||
import i18next, { type i18n } from "i18next";
|
import i18n from "i18next";
|
||||||
import LanguageDetector from "i18next-browser-languagedetector";
|
import LanguageDetector from "i18next-browser-languagedetector";
|
||||||
import { initReactI18next } from "react-i18next";
|
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;
|
if (hasInit) return i18next;
|
||||||
|
|
||||||
i18next
|
i18next
|
||||||
@ -12,14 +22,14 @@ export const initI18Next = () => {
|
|||||||
.use(initReactI18next)
|
.use(initReactI18next)
|
||||||
.init({
|
.init({
|
||||||
detection: { order: ["navigator"] },
|
detection: { order: ["navigator"] },
|
||||||
debug: false,
|
debug: true,
|
||||||
fallbackLng: "es",
|
fallbackLng: "es",
|
||||||
interpolation: { escapeValue: false },
|
interpolation: { escapeValue: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
hasInit = true;
|
hasInit = true;
|
||||||
return i18next;
|
return i18next;
|
||||||
};
|
};*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registra dinámicamente traducciones de un módulo.
|
* Registra dinámicamente traducciones de un módulo.
|
||||||
@ -33,25 +43,16 @@ export const registerTranslations = (
|
|||||||
locale: string,
|
locale: string,
|
||||||
resources: Record<string, unknown>
|
resources: Record<string, unknown>
|
||||||
): void => {
|
): void => {
|
||||||
if (!hasInit) {
|
/*if (!hasInit) {
|
||||||
throw new Error("i18n not initialized. Call initI18Next() first.");
|
throw new Error("i18n not initialized. Call initI18Next() first.");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
const ns = moduleName;
|
const ns = moduleName;
|
||||||
|
|
||||||
const alreadyExists = i18next.hasResourceBundle(locale, ns);
|
const alreadyExists = i18n.hasResourceBundle(locale, ns);
|
||||||
|
|
||||||
if (!alreadyExists) {
|
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<i18n["t"]>) => {
|
|
||||||
if (!hasInit) {
|
|
||||||
throw new Error("i18n not initialized. Call initI18Next() first.");
|
|
||||||
}
|
|
||||||
return i18next.t(...args);
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
export * from "./i18n";
|
|
||||||
@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^2.3.1",
|
"@biomejs/biome": "^2.3.1",
|
||||||
|
"@repo/i18next": "workspace:*",
|
||||||
"@repo/typescript-config": "workspace:*",
|
"@repo/typescript-config": "workspace:*",
|
||||||
"@tailwindcss/postcss": "^4.1.5",
|
"@tailwindcss/postcss": "^4.1.5",
|
||||||
"@turbo/gen": "^2.5.2",
|
"@turbo/gen": "^2.5.2",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user