FactuGES_ERP/modules/customer-invoices/src/web/i18n.ts

30 lines
967 B
TypeScript
Raw Normal View History

2025-10-16 11:18:55 +00:00
import { KeyPrefix, Namespace, i18n } from "i18next";
import { UseTranslationResponse, useTranslation as useI18NextTranslation } from "react-i18next";
2025-07-09 17:56:15 +00:00
import enResources from "../common/locales/en.json";
import esResources from "../common/locales/es.json";
import { MODULE_NAME } from "./manifest";
2025-08-23 11:57:48 +00:00
const addMissingBundles = (i18n: i18n) => {
2025-07-09 17:56:15 +00:00
const needsEn = !i18n.hasResourceBundle("en", MODULE_NAME);
const needsEs = !i18n.hasResourceBundle("es", MODULE_NAME);
if (needsEn) {
i18n.addResourceBundle("en", MODULE_NAME, enResources, true, true);
}
if (needsEs) {
i18n.addResourceBundle("es", MODULE_NAME, esResources, true, true);
}
};
2025-10-16 11:18:55 +00:00
export const useTranslation = <
Ns extends Namespace = typeof MODULE_NAME,
K extends KeyPrefix<Ns> = undefined,
>(
keyPrefix?: K
): UseTranslationResponse<Ns, K> => {
2025-07-09 17:56:15 +00:00
const { i18n } = useI18NextTranslation();
2025-08-23 11:57:48 +00:00
addMissingBundles(i18n);
2025-10-16 11:18:55 +00:00
return useI18NextTranslation(MODULE_NAME, { keyPrefix });
2025-07-09 17:56:15 +00:00
};