UNPKG

react-intlayer

Version:

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

1 lines 1.5 kB
{"version":3,"file":"IntlayerServerProvider.mjs","names":["locale"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = configuration?.internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n {children}\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;AAMA,MAAM,EAAE,kBAAkB,eAAe,wBAAwB,EAAE;;;;AAKnE,MAAa,wBACX,oBAAmC,cAAc;;;;AAKnD,MAAa,oBAAoB,iBAAiB,sBAAsB;;;;AAKxE,MAAa,SAAS,iBAAiB,sBAAsB;;;;AAS7D,MAAa,0BAA2D,EACtE,UACA,mBAAS,oBAET,oBAAC,sBAAsB;CAAS,OAAOA;CACpC;EAC8B"}