react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
1 lines • 1.32 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/config/client';\nimport { LanguageContent, type Dictionary } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: LanguageContent<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n configuration?.internationalization.defaultLocale;\n\n const dictionary = await dictionaryPromise[localeTarget]!();\n\n return useDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAOvB,MAAM,qBAAqB,OAChC,mBACA,WACG;AACH,QAAM,eACJ,UACA,iBAAgC,qBAAqB,KACrD,eAAe,qBAAqB;AAEtC,QAAM,aAAa,MAAM,kBAAkB,YAAY,EAAG;AAE1D,SAAO,cAAc,YAAY,YAAY;AAC/C;","names":[]}