UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

26 lines 757 B
import { getIntlayer } from "../getIntlayer.mjs"; import { IntlayerServerContext } from "./IntlayerServerProvider.mjs"; import { getServerContext } from "./serverContext.mjs"; const useI18n = (namespace, locale) => { const localeTarget = locale ?? getServerContext(IntlayerServerContext); const dictionaryContent = getIntlayer(namespace, localeTarget); const t = (path) => { if (!path) { return dictionaryContent; } const pathArray = path.split("."); let current = dictionaryContent; for (const key of pathArray) { current = current?.[key]; if (current === void 0) { return dictionaryContent; } } return current; }; return t; }; export { useI18n }; //# sourceMappingURL=useI18n.mjs.map