UNPKG

react-intlayer

Version:

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

23 lines (20 loc) 997 B
'use client'; import { IntlayerClientContext } from "./IntlayerProvider.mjs"; import { useDictionary } from "./useDictionary.mjs"; import { useLoadDynamic } from "./useLoadDynamic.mjs"; import { useContext, useMemo } from "react"; import configuration from "@intlayer/config/built"; //#region src/client/useDictionaryDynamic.ts /** * On the server side, Hook that transform a dictionary and return the content * * If the locale is not provided, it will use the locale from the client context */ const useDictionaryDynamic = (dictionaryPromise, key, locale) => { const { locale: currentLocale } = useContext(IntlayerClientContext); const localeTarget = useMemo(() => locale ?? currentLocale ?? configuration?.internationalization.defaultLocale, [currentLocale, locale]); return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget); }; //#endregion export { useDictionaryDynamic }; //# sourceMappingURL=useDictionaryDynamic.mjs.map