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

29 lines
830 B
TypeScript
Raw Normal View History

2025-07-09 17:56:15 +00:00
import { useEffect } from "react";
import { useTranslation as useI18NextTranslation } from "react-i18next";
2025-07-08 18:50:08 +00:00
import { PACKAGE_NAME } from "../index.ts";
import enResources from "./en.json" with { type: "json" };
import esResources from "./es.json" with { type: "json" };
2025-07-09 17:56:15 +00:00
const addMissingBundles = (i18n: any) => {
const needsEn = !i18n.hasResourceBundle("en", PACKAGE_NAME);
const needsEs = !i18n.hasResourceBundle("es", PACKAGE_NAME);
if (needsEn) {
i18n.addResourceBundle("en", PACKAGE_NAME, enResources, true, true);
}
if (needsEs) {
i18n.addResourceBundle("es", PACKAGE_NAME, esResources, true, true);
2025-07-08 18:50:08 +00:00
}
2025-07-09 17:56:15 +00:00
};
export const useTranslation = () => {
const { i18n } = useI18NextTranslation();
useEffect(() => {
addMissingBundles(i18n);
}, [i18n]);
2025-07-08 18:50:08 +00:00
2025-07-09 17:56:15 +00:00
return useI18NextTranslation(PACKAGE_NAME);
2025-07-08 18:50:08 +00:00
};