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

36 lines
1.0 KiB
TypeScript
Raw Normal View History

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