UNPKG

react-intlayer

Version:

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

20 lines (18 loc) 915 B
import { getServerContext } from "./serverContext.mjs"; import { IntlayerServerContext } from "./IntlayerServerProvider.mjs"; import { useDictionary } from "./useDictionary.mjs"; import { useLoadDynamic } from "./useLoadDynamic.mjs"; import configuration from "@intlayer/config/built"; //#region src/server/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 server context */ const useDictionaryDynamic = (dictionaryPromise, key, locale) => { const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? configuration?.internationalization.defaultLocale; return useDictionary(useLoadDynamic(`${String(key)}.${localeTarget}`, dictionaryPromise[localeTarget]?.()), localeTarget); }; //#endregion export { useDictionaryDynamic }; //# sourceMappingURL=useDictionaryDynamic.mjs.map