UNPKG

react-intlayer

Version:

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

19 lines (17 loc) 809 B
import { getServerContext } from "./serverContext.mjs"; import { IntlayerServerContext } from "./IntlayerServerProvider.mjs"; import { useDictionary } from "./useDictionary.mjs"; import configuration from "@intlayer/config/built"; //#region src/server/useDictionaryAsync.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 useDictionaryAsync = async (dictionaryPromise, locale) => { const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? configuration?.internationalization.defaultLocale; return useDictionary(await dictionaryPromise[localeTarget]?.(), localeTarget); }; //#endregion export { useDictionaryAsync }; //# sourceMappingURL=useDictionaryAsync.mjs.map