FactuGES_ERP/packages/rdx-ui/src/locales/i18n.ts

36 lines
1.0 KiB
TypeScript

import { i18n, registerTranslations } from "@repo/i18next";
import { useEffect } from "react";
import { useTranslation as useI18NextTranslation } from "react-i18next";
import { PACKAGE_NAME } from "../index.ts";
import enResources from "./en.json" with { type: "json" };
import esResources from "./es.json" with { type: "json" };
/**
* Registra dinámicamente las traducciones del módulo.
*/
const ensureModuleTranslations = () => {
registerTranslations(PACKAGE_NAME, "en", enResources);
registerTranslations(PACKAGE_NAME, "es", esResources);
};
/**
* Hook de traducción del módulo, version adaptada.
*
* - Asegura los bundles del módulo.
* - Devuelve el hook react-i18next con namespace.
*/
export const useTranslation = () => {
// Asegura los bundles del módulo al montar (idempotente)
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
useEffect(() => {
ensureModuleTranslations();
}, [i18n]);
// Hook con namespace
return useI18NextTranslation(PACKAGE_NAME, {
i18n,
});
};