react-intlayer 3.5.11 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/client/IntlayerProvider.mjs +0 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/getBrowserLocale.mjs +0 -1
- package/dist/esm/client/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/client/index.mjs +0 -1
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/client/t.mjs +0 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useContent.mjs +0 -1
- package/dist/esm/client/useContent.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +0 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +0 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useIntlayerAsync.mjs +0 -1
- package/dist/esm/client/useIntlayerAsync.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +0 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +0 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleCookie.mjs +0 -1
- package/dist/esm/client/useLocaleCookie.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +0 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs +0 -1
- package/dist/esm/distantDictionary/fetchDistantDictionary.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs +0 -1
- package/dist/esm/editor/ContentSelectorConnector.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +0 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +0 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/renderContentEditor.mjs +0 -1
- package/dist/esm/editor/renderContentEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +0 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getEnumeration.mjs +0 -1
- package/dist/esm/getEnumeration.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +0 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/getIntlayerAsync.mjs +0 -1
- package/dist/esm/getIntlayerAsync.mjs.map +1 -1
- package/dist/esm/getTranslation.mjs +0 -1
- package/dist/esm/getTranslation.mjs.map +1 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/processDictionary/index.mjs +0 -1
- package/dist/esm/processDictionary/index.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +0 -1
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/getLocaleTranslation.mjs +0 -1
- package/dist/esm/server/getLocaleTranslation.mjs.map +1 -1
- package/dist/esm/server/index.mjs +0 -1
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/esm/server/serverContext.mjs +0 -1
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +0 -1
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +0 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +0 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useTraduction.mjs +0 -1
- package/dist/esm/server/useTraduction.mjs.map +1 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs +0 -1
- package/dist/esm/utils/PoweredByMeta/index.mjs.map +1 -1
- package/package.json +16 -34
- package/dist/cjs/cli/react-intlayer.cjs +0 -73
- package/dist/cjs/cli/react-intlayer.cjs.map +0 -1
- package/dist/cjs/craco/craco.config.cjs +0 -32
- package/dist/cjs/craco/craco.config.cjs.map +0 -1
- package/dist/cjs/craco/intlayerCracoPlugin.cjs +0 -93
- package/dist/cjs/craco/intlayerCracoPlugin.cjs.map +0 -1
- package/dist/cjs/utils/removeUndefinedValueObject.cjs +0 -38
- package/dist/cjs/utils/removeUndefinedValueObject.cjs.map +0 -1
- package/dist/cjs/vite/index.cjs +0 -25
- package/dist/cjs/vite/index.cjs.map +0 -1
- package/dist/cjs/vite/intlayerMiddlewarePlugin.cjs +0 -224
- package/dist/cjs/vite/intlayerMiddlewarePlugin.cjs.map +0 -1
- package/dist/cjs/vite/intlayerPlugin.cjs +0 -88
- package/dist/cjs/vite/intlayerPlugin.cjs.map +0 -1
- package/dist/esm/chunk-ZD7AOCMD.mjs +0 -9
- package/dist/esm/chunk-ZD7AOCMD.mjs.map +0 -1
- package/dist/esm/cli/react-intlayer.mjs +0 -50
- package/dist/esm/cli/react-intlayer.mjs.map +0 -1
- package/dist/esm/craco/craco.config.mjs +0 -17
- package/dist/esm/craco/craco.config.mjs.map +0 -1
- package/dist/esm/craco/intlayerCracoPlugin.mjs +0 -74
- package/dist/esm/craco/intlayerCracoPlugin.mjs.map +0 -1
- package/dist/esm/utils/removeUndefinedValueObject.mjs +0 -15
- package/dist/esm/utils/removeUndefinedValueObject.mjs.map +0 -1
- package/dist/esm/vite/index.mjs +0 -3
- package/dist/esm/vite/index.mjs.map +0 -1
- package/dist/esm/vite/intlayerMiddlewarePlugin.mjs +0 -201
- package/dist/esm/vite/intlayerMiddlewarePlugin.mjs.map +0 -1
- package/dist/esm/vite/intlayerPlugin.mjs +0 -55
- package/dist/esm/vite/intlayerPlugin.mjs.map +0 -1
- package/dist/types/cli/react-intlayer.d.ts +0 -9
- package/dist/types/cli/react-intlayer.d.ts.map +0 -1
- package/dist/types/craco/craco.config.d.ts +0 -2
- package/dist/types/craco/craco.config.d.ts.map +0 -1
- package/dist/types/craco/intlayerCracoPlugin.d.ts +0 -24
- package/dist/types/craco/intlayerCracoPlugin.d.ts.map +0 -1
- package/dist/types/utils/removeUndefinedValueObject.d.ts +0 -2
- package/dist/types/utils/removeUndefinedValueObject.d.ts.map +0 -1
- package/dist/types/vite/index.d.ts +0 -3
- package/dist/types/vite/index.d.ts.map +0 -1
- package/dist/types/vite/intlayerMiddlewarePlugin.d.ts +0 -6
- package/dist/types/vite/intlayerMiddlewarePlugin.d.ts.map +0 -1
- package/dist/types/vite/intlayerPlugin.d.ts +0 -16
- package/dist/types/vite/intlayerPlugin.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { getConfiguration, type Locales } from '@intlayer/config/client';\nimport {\n type PropsWithChildren,\n createContext,\n useContext,\n useMemo,\n type FC,\n useState,\n useCallback,\n} from 'react';\nimport { localeCookie, setLocaleCookie } from './useLocaleCookie';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\n\ntype IntlayerValue = {\n locale: Locales;\n setLocale: (newLocale: Locales) => void;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeCookie ?? getConfiguration().internationalization.defaultLocale,\n setLocale: () => null,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = PropsWithChildren & {\n locale?: Locales;\n setLocale?: (locale: Locales) => void;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n locale,\n children,\n setLocale: setLocaleProp,\n}) => {\n const { internationalization } = getConfiguration();\n const { defaultLocale, locales: availableLocales } = internationalization;\n\n const [currentLocale, setCurrentLocale] = useState(\n locale ?? localeCookie ?? defaultLocale\n );\n\n const setLocaleBase = useCallback(\n (newLocale: Locales) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales.includes(newLocale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleCookie(newLocale); // Optionally set cookie for persistence\n },\n [availableLocales, currentLocale, locale]\n );\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const value: IntlayerValue = useMemo<IntlayerValue>(\n () => ({ locale: currentLocale, setLocale: setLocale }),\n [currentLocale, setLocale]\n );\n\n return (\n <IntlayerClientContext.Provider value={value}>\n <IntlayerEditorProvider>{children}</IntlayerEditorProvider>\n </IntlayerClientContext.Provider>\n );\n};\n"],"mappings":";AA6EM;AA3EN,SAAS,wBAAsC;AAC/C;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,uBAAuB;AAC9C,SAAS,8BAA8B;AAUhC,MAAM,wBAAwB,cAA6B;AAAA,EAChE,QAAQ,gBAAgB,iBAAiB,EAAE,qBAAqB;AAAA,EAChE,WAAW,MAAM;AACnB,CAAC;AAKM,MAAM,qBAAqB,MAAM,WAAW,qBAAqB;AAUjE,MAAM,mBAA8C,CAAC;AAAA,EAC1D;AAAA,EACA;AAAA,EACA,WAAW;AACb,MAAM;AACJ,QAAM,EAAE,qBAAqB,IAAI,iBAAiB;AAClD,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAAI;AAErD,QAAM,CAAC,eAAe,gBAAgB,IAAI;AAAA,IACxC,UAAU,gBAAgB;AAAA,EAC5B;AAEA,QAAM,gBAAgB;AAAA,IACpB,CAAC,cAAuB;AACtB,UAAI,cAAc,SAAS,MAAM,UAAU,SAAS,EAAG;AAEvD,UAAI,CAAC,iBAAiB,SAAS,SAAS,GAAG;AACzC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,uBAAiB,SAAS;AAC1B,sBAAgB,SAAS;AAAA,IAC3B;AAAA,IACA,CAAC,kBAAkB,eAAe,MAAM;AAAA,EAC1C;AAEA,QAAM,YAAY,iBAAiB;AAEnC,QAAM,QAAuB;AAAA,IAC3B,OAAO,EAAE,QAAQ,eAAe,UAAqB;AAAA,IACrD,CAAC,eAAe,SAAS;AAAA,EAC3B;AAEA,SACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAC9B,8BAAC,0BAAwB,UAAS,GACpC;AAEJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat();\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/getBrowserLocale.tsx"],"sourcesContent":["import { getConfiguration, type Locales } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\n\nexport enum LanguageDetector {\n Querystring = 'querystring',\n Cookie = 'cookie',\n LocalStorage = 'localStorage',\n SessionStorage = 'sessionStorage',\n Navigator = 'navigator',\n HtmlTag = 'htmlTag',\n}\n\n// Default settings for the language detector\ntype LanguageDetectorOptions = {\n order?: LanguageDetector[];\n lookupQuerystring?: string;\n lookupCookie?: string;\n lookupLocalStorage?: string;\n lookupSessionStorage?: string;\n excludeCacheFor?: string[];\n htmlTag?: HTMLElement | null;\n};\n\nconst getDefaultsOptions = (): LanguageDetectorOptions => {\n const { middleware } = getConfiguration();\n\n return {\n order: [\n LanguageDetector.Querystring,\n LanguageDetector.Cookie,\n LanguageDetector.Navigator,\n LanguageDetector.HtmlTag,\n ],\n lookupQuerystring: 'locale',\n lookupCookie: middleware.cookieName,\n htmlTag: document.documentElement,\n };\n};\n\n// Helper functions for various checks and operations\nconst isLocalStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.localStorage.setItem(testKey, 'foo');\n window.localStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\nconst isSessionStorageAvailable = (): boolean => {\n try {\n if (typeof window === 'undefined') return false;\n const testKey = 'intlayer.translate.boo';\n window.sessionStorage.setItem(testKey, 'foo');\n window.sessionStorage.removeItem(testKey);\n return true;\n } catch {\n return false;\n }\n};\n\n// Function to detect language using different detectors\nconst detectLanguage = (\n order: string[],\n options: LanguageDetectorOptions\n): Record<LanguageDetector, Locales | Locales[]> => {\n const detected: Record<LanguageDetector, Locales | Locales[]> = {} as Record<\n LanguageDetector,\n Locales | Locales[]\n >;\n\n const queryStringDetector = () => {\n if (typeof window === 'undefined') return;\n const search = window.location.search || '';\n const params = new URLSearchParams(search);\n const value = params.get(options.lookupQuerystring ?? '');\n if (value) {\n detected[LanguageDetector.Querystring] = value as Locales;\n }\n };\n\n const cookieDetector = () => {\n if (typeof document === 'undefined') return;\n const cookies = document.cookie.split(';');\n const cookieName = `${options.lookupCookie ?? ''}=`;\n const cookie = cookies.find((c) => c.trim().startsWith(cookieName));\n if (cookie) {\n const value = cookie.split('=')[1].trim();\n\n detected[LanguageDetector.Cookie] = value as Locales;\n }\n };\n\n const localStorageDetector = () => {\n if (!isLocalStorageAvailable()) return;\n const value = window.localStorage.getItem(options.lookupLocalStorage ?? '');\n if (value) {\n detected[LanguageDetector.LocalStorage] = value as Locales;\n }\n };\n\n const sessionStorageDetector = () => {\n if (!isSessionStorageAvailable()) return;\n const value = window.sessionStorage.getItem(\n options.lookupSessionStorage ?? ''\n );\n if (value) {\n detected[LanguageDetector.SessionStorage] = value as Locales;\n }\n };\n\n const navigatorDetector = () => {\n if (typeof navigator === 'undefined') return;\n\n if (navigator.language) {\n detected[LanguageDetector.Navigator] = navigator.language as Locales;\n }\n };\n\n const htmlTagDetector = () => {\n const htmlTag = options.htmlTag;\n if (htmlTag && typeof htmlTag.getAttribute === 'function') {\n const lang = htmlTag.getAttribute('lang');\n if (lang) {\n detected[LanguageDetector.HtmlTag] = lang as Locales;\n }\n }\n };\n\n // Map detector names to their corresponding functions\n const detectors: Record<string, () => void> = {\n [LanguageDetector.Querystring]: queryStringDetector,\n [LanguageDetector.Cookie]: cookieDetector,\n [LanguageDetector.LocalStorage]: localStorageDetector,\n [LanguageDetector.SessionStorage]: sessionStorageDetector,\n [LanguageDetector.Navigator]: navigatorDetector,\n [LanguageDetector.HtmlTag]: htmlTagDetector,\n };\n\n // Use the provided order to run each detector\n order.forEach((detectorName) => {\n detectors[detectorName]?.();\n });\n\n return detected;\n};\n\nconst getFirstAvailableLocale = (\n locales: Record<LanguageDetector, Locales | Locales[]>,\n order: LanguageDetector[]\n): Locales => {\n const { internationalization } = getConfiguration();\n\n for (const detector of order) {\n const localesArray = [locales[detector]].flat();\n\n for (const locale of localesArray) {\n if (\n locale &&\n (internationalization.locales ?? localeList).includes(locale)\n ) {\n return locale;\n } else if (\n locale?.includes('-') &&\n (internationalization.locales ?? localeList).includes(\n locale.split('-')[0] as Locales\n )\n ) {\n return locale.split('-')[0] as Locales;\n }\n }\n }\n\n return internationalization.defaultLocale;\n};\n\n/**\n * Core language detector function\n * const detectedLanguages = detectLanguage(['LanguageDetector.Cookie', 'LanguageDetector.LocalStorage'], { lookupCookie: 'myCookie' });\n */\nexport const getBrowserLocale = (\n userOptions: LanguageDetectorOptions | undefined = {}\n): Locales => {\n const options = { ...getDefaultsOptions(), ...userOptions };\n\n const locales = detectLanguage(options.order ?? [], options);\n\n return getFirstAvailableLocale(locales, options.order ?? []);\n};\n"],"mappings":"AAAA,SAAS,wBAAsC;AAC/C,SAAS,kBAAkB;AAEpB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAA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QAAM,QAAQ,CAAC,iBAAiB;AAC9B,cAAU,YAAY,IAAI;AAAA,EAC5B,CAAC;AAED,SAAO;AACT;AAEA,MAAM,0BAA0B,CAC9B,SACA,UACY;AACZ,QAAM,EAAE,qBAAqB,IAAI,iBAAiB;AAElD,aAAW,YAAY,OAAO;AAC5B,UAAM,eAAe,CAAC,QAAQ,QAAQ,CAAC,EAAE,KAAK;AAE9C,eAAW,UAAU,cAAc;AACjC,UACE,WACC,qBAAqB,WAAW,YAAY,SAAS,MAAM,GAC5D;AACA,eAAO;AAAA,MACT,WACE,QAAQ,SAAS,GAAG,MACnB,qBAAqB,WAAW,YAAY;AAAA,QAC3C,OAAO,MAAM,GAAG,EAAE,CAAC;AAAA,MACrB,GACA;AACA,eAAO,OAAO,MAAM,GAAG,EAAE,CAAC;AAAA,MAC5B;AAAA,IACF;AAAA,EACF;AAEA,SAAO,qBAAqB;AAC9B;AAMO,MAAM,mBAAmB,CAC9B,cAAmD,CAAC,MACxC;AACZ,QAAM,UAAU,EAAE,GAAG,mBAAmB,GAAG,GAAG,YAAY;AAE1D,QAAM,UAAU,eAAe,QAAQ,SAAS,CAAC,GAAG,OAAO;AAE3D,SAAO,wBAAwB,SAAS,QAAQ,SAAS,CAAC,CAAC;AAC7D;","names":["LanguageDetector"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayerContext,\n IntlayerProvider,\n} from './IntlayerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useIntlayerAsync } from './useIntlayerAsync';\nexport { useDictionary } from './useDictionary';\nexport { useLocaleBase } from './useLocaleBase';\nexport { useLocale } from './useLocale';\nexport { useTraduction } from './useTraduction';\nexport {\n useLocaleCookie,\n localeCookie,\n setLocaleCookie,\n} from './useLocaleCookie';\nexport { getBrowserLocale } from './getBrowserLocale';\nexport { t } from './t';\n"],"mappings":"AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,SAAS;","names":[]}
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: LanguageContent<Content>,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: LanguageContent<Content>,\n locale?: Locales\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAO/B,MAAM,IAAI,CACf,kBACA,WACG;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,eAAwB,kBAAkB,YAAY;AAC/D;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTraduction } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useContent.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useLocaleBase } from './useLocaleBase';\nimport { useTraduction } from './useTraduction';\n\n/**\n * On the client side, hook to get the translation content based on the locale\n */\nexport const useContent = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const { locale } = useLocaleBase();\n\n const content = useTraduction(languageContent);\n\n return {\n locale,\n content,\n t: useTraduction,\n };\n};\n"],"mappings":"AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAKvB,MAAM,aAAa,CACxB,oBACG;AACH,QAAM,EAAE,OAAO,IAAI,cAAc;AAEjC,QAAM,UAAU,cAAc,eAAe;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\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 client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport type { DeclarationContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getDictionary, type UseDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\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 client context\n */\nexport const useDictionary: UseDictionary = <T extends DeclarationContent>(\n dictionary: T,\n locale?: Locales,\n isRenderEditor = false\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary(dictionary, localeTarget, isRenderEditor);\n};\n"],"mappings":";AAIA,SAAS,kBAAkB;AAC3B,SAAS,qBAAyC;AAClD,SAAS,6BAA6B;AAO/B,MAAM,gBAA+B,CAC1C,YACA,QACA,iBAAiB,UACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,cAAc,YAAY,cAAc,cAAc;AAC/D;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext } from 'react';\nimport {\n type DictionaryKeys,\n getIntlayer,\n type UseIntlayerEditable,\n} from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayer: UseIntlayerEditable = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getIntlayer(key, localeTarget, isRenderEditor);\n};\n"],"mappings":";AAGA,SAAS,kBAAkB;AAC3B;AAAA,EAEE;AAAA,OAEK;AACP,SAAS,6BAA6B;AAO/B,MAAM,cAAmC,CAC9C,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAE/B,SAAO,YAAY,KAAK,cAAc,cAAc;AACtD;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport {\n DataFromDictionaryKey,\n type DictionaryKeys,\n getIntlayer,\n} from '../getIntlayer';\nimport { getIntlayerAsync } from '../getIntlayerAsync';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nexport type UseIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R> & { isLoading: boolean };\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync: UseIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget, isRenderEditor);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...dictionary, isLoading };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { useContext, useEffect, useMemo, useState } from 'react';\nimport {\n DataFromDictionaryKey,\n type DictionaryKeys,\n getIntlayer,\n} from '../getIntlayer';\nimport { getIntlayerAsync } from '../getIntlayerAsync';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nexport type UseIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R> & { isLoading: boolean };\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useIntlayerAsync: UseIntlayerAsync = <T extends DictionaryKeys>(\n key: T,\n locale?: Locales,\n isRenderEditor = true\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n const localeDictionary = getIntlayer(key, localeTarget, isRenderEditor);\n const [distantDictionary, setDistantDictionary] = useState<\n typeof localeDictionary | null | undefined\n >(undefined);\n const [isLoading, setIsLoading] = useState(false);\n\n useEffect(() => {\n setIsLoading(true);\n\n getIntlayerAsync(key)\n .then((distantDictionary) => {\n if (distantDictionary) {\n setDistantDictionary(distantDictionary);\n }\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, []);\n\n const dictionary = useMemo(\n () => distantDictionary ?? localeDictionary,\n [distantDictionary, localeDictionary]\n );\n\n return { ...dictionary, isLoading };\n};\n"],"mappings":";AAGA,SAAS,YAAY,WAAW,SAAS,gBAAgB;AACzD;AAAA,EAGE;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AAoB/B,MAAM,mBAAqC,CAChD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,EAAE,QAAQ,cAAc,IAAI,WAAW,qBAAqB;AAClE,QAAM,eAAe,UAAU;AAC/B,QAAM,mBAAmB,YAAY,KAAK,cAAc,cAAc;AACtE,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAEhD,MAAS;AACX,QAAM,CAAC,WAAW,YAAY,IAAI,SAAS,KAAK;AAEhD,YAAU,MAAM;AACd,iBAAa,IAAI;AAEjB,qBAAiB,GAAG,EACjB,KAAK,CAACA,uBAAsB;AAC3B,UAAIA,oBAAmB;AACrB,6BAAqBA,kBAAiB;AAAA,MACxC;AAAA,IACF,CAAC,EACA,QAAQ,MAAM;AACb,mBAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACL,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa;AAAA,IACjB,MAAM,qBAAqB;AAAA,IAC3B,CAAC,mBAAmB,gBAAgB;AAAA,EACtC;AAEA,SAAO,EAAE,GAAG,YAAY,UAAU;AACpC;","names":["distantDictionary"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useLocaleCookie } from './useLocaleCookie';\n\ntype useLocaleProps = {\n onLocaleChange?: (locale: Locales) => void;\n};\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocale = ({ onLocaleChange }: useLocaleProps = {}) => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n const { locale, setLocale: setLocaleState } = useContext(\n IntlayerClientContext\n );\n const { setLocaleCookie } = useLocaleCookie();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleCookie(locale);\n onLocaleChange?.(locale);\n },\n [\n onLocaleChange,\n availableLocales,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n ]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";AAGA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,aAAa,kBAAkB;AACxC,SAAS,6BAA6B;AACtC,SAAS,uBAAuB;AASzB,MAAM,YAAY,CAAC,EAAE,eAAe,IAAoB,CAAC,MAAM;AACpE,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,IAAI,iBAAiB,EAAE;AACvB,QAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AACrB,QAAM,EAAE,QAAQ,WAAW,eAAe,IAAI;AAAA,IAC5C;AAAA,EACF;AACA,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAE5C,QAAM,YAAY;AAAA,IAChB,CAACA,YAAoB;AACnB,UAAI,CAAC,iBAAiB,SAASA,OAAM,GAAG;AACtC,gBAAQ,MAAM,UAAUA,OAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,qBAAeA,OAAM;AACrB,sBAAgBA,OAAM;AACtB,uBAAiBA,OAAM;AAAA,IACzB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":["locale"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport { getConfiguration } from '@intlayer/config/client';\nimport { localeList } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n getConfiguration().internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n localeList, // List of all available locales\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,EAAE,eAAe,SAAS,iBAAiB,IAC/C,iBAAiB,EAAE;AAKd,MAAM,gBAAgB,MAAM;AACjC,QAAM,EAAE,QAAQ,UAAU,IAAI,WAAW,qBAAqB;AAE9D,SAAO;AAAA,IACL;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,IACA;AAAA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | Locales\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocaleCookie.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport Cookies from 'js-cookie';\n\nconst { cookieName } = getConfiguration().middleware;\n\nconst cookieAttributes: Cookies.CookieAttributes = {\n path: '/',\n expires: undefined,\n domain: undefined,\n secure: false,\n sameSite: 'strict',\n};\n\n/**\n * Get the locale cookie\n */\nexport const localeCookie = Cookies.get(cookieName) as unknown as\n | Locales\n | undefined;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleCookie = (locale: Locales) => {\n Cookies.set(cookieName, locale, cookieAttributes);\n};\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = () => ({\n localeCookie,\n setLocaleCookie,\n});\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C,OAAO,aAAa;AAEpB,MAAM,EAAE,WAAW,IAAI,iBAAiB,EAAE;AAE1C,MAAM,mBAA6C;AAAA,EACjD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AACZ;AAKO,MAAM,eAAe,QAAQ,IAAI,UAAU;AAO3C,MAAM,kBAAkB,CAAC,WAAoB;AAClD,UAAQ,IAAI,YAAY,QAAQ,gBAAgB;AAClD;AAKO,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import type { LanguageContent } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { getTranslation } from '../getTranslation';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTraduction<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTraduction = <Content = string>(\n languageContent: LanguageContent<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return getTranslation(languageContent, locale);\n};\n"],"mappings":"AACA,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAuB/B,MAAM,gBAAgB,CAC3B,oBACY;AACZ,QAAM,EAAE,OAAO,IAAI,WAAW,qBAAqB;AAEnD,SAAO,eAAe,iBAAiB,MAAM;AAC/C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/distantDictionary/fetchDistantDictionary.ts"],"sourcesContent":["import { getIntlayerAPI } from '@intlayer/api';\n// @ts-ignore @intlayer/backend is not build yet\nimport { type DictionaryAPI } from '@intlayer/backend';\nimport { getConfiguration } from '@intlayer/config/client';\n// @ts-ignore @intlayer/design-system not build yet\n\n/**\n * Fetch distant dictionary\n */\nexport const fetchDistantDictionary = async (\n dictionaryKey: string\n): Promise<DictionaryAPI> => {\n try {\n const config = getConfiguration();\n const { clientId, clientSecret } = config.editor;\n const intlayerAPI = getIntlayerAPI(undefined, config);\n\n if (!clientId || !clientSecret) {\n throw new Error(\n 'Missing OAuth2 client ID or client secret. To get access token go to https://intlayer.org/dashboard/project.'\n );\n }\n\n const oAuth2TokenResult = await intlayerAPI.auth.getOAuth2AccessToken();\n\n const oAuth2AccessToken = oAuth2TokenResult.data?.accessToken;\n\n // Fetch the dictionary\n const getDictionaryResult = await intlayerAPI.dictionary.getDictionary(\n dictionaryKey,\n undefined,\n {\n headers: { Authorization: `Bearer ${oAuth2AccessToken}` },\n }\n );\n\n const distantDictionary = getDictionaryResult.data;\n\n if (!distantDictionary) {\n throw new Error(`Dictionary ${dictionaryKey} not found on remote`);\n }\n\n return distantDictionary;\n } catch (error) {\n console.error(error);\n return undefined;\n }\n};\n"],"mappings":"AAAA,SAAS,sBAAsB;AAG/B,SAAS,wBAAwB;AAM1B,MAAM,yBAAyB,OACpC,kBAC2B;AAC3B,MAAI;AACF,UAAM,SAAS,iBAAiB;AAChC,UAAM,EAAE,UAAU,aAAa,IAAI,OAAO;AAC1C,UAAM,cAAc,eAAe,QAAW,MAAM;AAEpD,QAAI,CAAC,YAAY,CAAC,cAAc;AAC9B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,UAAM,oBAAoB,MAAM,YAAY,KAAK,qBAAqB;AAEtE,UAAM,oBAAoB,kBAAkB,MAAM;AAGlD,UAAM,sBAAsB,MAAM,YAAY,WAAW;AAAA,MACvD;AAAA,MACA;AAAA,MACA;AAAA,QACE,SAAS,EAAE,eAAe,UAAU,iBAAiB,GAAG;AAAA,MAC1D;AAAA,IACF;AAEA,UAAM,oBAAoB,oBAAoB;AAE9C,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI,MAAM,cAAc,aAAa,sBAAsB;AAAA,IACnE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorConnector.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n useState,\n} from 'react';\nimport {\n ContentSelectorWrapper,\n ContentSelectorWrapperProps,\n} from './ContentSelectorWrapper';\n\ntype ContentSelectorContextValue = {\n state: {\n ContentSelectorWrapper: typeof ContentSelectorWrapper;\n };\n setState: (value: ContentSelectorContextValue['state']) => void;\n};\n\nexport const ContentSelectorContext =\n createContext<ContentSelectorContextValue>({\n state: { ContentSelectorWrapper },\n setState: () => {},\n });\n\nexport const useContentSelectorContext = () =>\n useContext(ContentSelectorContext);\n\nexport const ContentSelectorProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [state, setState] = useState({\n // Add your default state here\n ContentSelectorWrapper,\n });\n\n const valueMemo = useMemo(() => ({ state, setState }), [state, setState]);\n\n return (\n <ContentSelectorContext.Provider value={valueMemo}>\n {children}\n </ContentSelectorContext.Provider>\n );\n};\n\nexport const ContentSelectorConnector: FC<ContentSelectorWrapperProps> = (\n props\n) => {\n const { ContentSelectorWrapper } = useContentSelectorContext().state;\n\n return <ContentSelectorWrapper {...props} />;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorConnector.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n FC,\n PropsWithChildren,\n useContext,\n useMemo,\n useState,\n} from 'react';\nimport {\n ContentSelectorWrapper,\n ContentSelectorWrapperProps,\n} from './ContentSelectorWrapper';\n\ntype ContentSelectorContextValue = {\n state: {\n ContentSelectorWrapper: typeof ContentSelectorWrapper;\n };\n setState: (value: ContentSelectorContextValue['state']) => void;\n};\n\nexport const ContentSelectorContext =\n createContext<ContentSelectorContextValue>({\n state: { ContentSelectorWrapper },\n setState: () => {},\n });\n\nexport const useContentSelectorContext = () =>\n useContext(ContentSelectorContext);\n\nexport const ContentSelectorProvider: FC<PropsWithChildren> = ({\n children,\n}) => {\n const [state, setState] = useState({\n // Add your default state here\n ContentSelectorWrapper,\n });\n\n const valueMemo = useMemo(() => ({ state, setState }), [state, setState]);\n\n return (\n <ContentSelectorContext.Provider value={valueMemo}>\n {children}\n </ContentSelectorContext.Provider>\n );\n};\n\nexport const ContentSelectorConnector: FC<ContentSelectorWrapperProps> = (\n props\n) => {\n const { ContentSelectorWrapper } = useContentSelectorContext().state;\n\n return <ContentSelectorWrapper {...props} />;\n};\n"],"mappings":";AA0CI;AAxCJ;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AASA,MAAM,yBACX,cAA2C;AAAA,EACzC,OAAO,EAAE,uBAAuB;AAAA,EAChC,UAAU,MAAM;AAAA,EAAC;AACnB,CAAC;AAEI,MAAM,4BAA4B,MACvC,WAAW,sBAAsB;AAE5B,MAAM,0BAAiD,CAAC;AAAA,EAC7D;AACF,MAAM;AACJ,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS;AAAA;AAAA,IAEjC;AAAA,EACF,CAAC;AAED,QAAM,YAAY,QAAQ,OAAO,EAAE,OAAO,SAAS,IAAI,CAAC,OAAO,QAAQ,CAAC;AAExE,SACE,oBAAC,uBAAuB,UAAvB,EAAgC,OAAO,WACrC,UACH;AAEJ;AAEO,MAAM,2BAA4D,CACvE,UACG;AACH,QAAM,EAAE,wBAAAA,wBAAuB,IAAI,0BAA0B,EAAE;AAE/D,SAAO,oBAACA,yBAAA,EAAwB,GAAG,OAAO;AAC5C;","names":["ContentSelectorWrapper"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["import { type KeyPath } from '@intlayer/core';\nimport { type PropsWithChildren, type FC } from 'react';\n\nexport type ContentSelectorWrapperProps = PropsWithChildren<{\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n}>;\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n}) => <>{children}</>;\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/ContentSelectorWrapper.tsx"],"sourcesContent":["import { type KeyPath } from '@intlayer/core';\nimport { type PropsWithChildren, type FC } from 'react';\n\nexport type ContentSelectorWrapperProps = PropsWithChildren<{\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n}>;\n\nexport const ContentSelectorWrapper: FC<ContentSelectorWrapperProps> = ({\n children,\n}) => <>{children}</>;\n"],"mappings":"AAWM;AAFC,MAAM,yBAA0D,CAAC;AAAA,EACtE;AACF,MAAM,gCAAG,UAAS;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { PoweredByMeta } from '../utils/PoweredByMeta/index';\nimport { ContentSelectorProvider } from './ContentSelectorConnector';\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <ContentSelectorProvider>\n <PoweredByMeta />\n {children}\n </ContentSelectorProvider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import { FC, PropsWithChildren } from 'react';\nimport { PoweredByMeta } from '../utils/PoweredByMeta/index';\nimport { ContentSelectorProvider } from './ContentSelectorConnector';\n\nexport const IntlayerEditorProvider: FC<PropsWithChildren> = ({ children }) => (\n <ContentSelectorProvider>\n <PoweredByMeta />\n {children}\n </ContentSelectorProvider>\n);\n"],"mappings":"AAKE,SACE,KADF;AAJF,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AAEjC,MAAM,yBAAgD,CAAC,EAAE,SAAS,MACvE,qBAAC,2BACC;AAAA,sBAAC,iBAAc;AAAA,EACd;AAAA,GACH;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/editor/renderContentEditor.tsx"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport type { KeyPath } from '@intlayer/core';\nimport type { FC, ReactNode } from 'react';\nimport { ContentSelectorConnector } from './ContentSelectorConnector';\n\nconst {\n editor: { enabled },\n} = getConfiguration();\n\nexport type IntlayerEditorElementProps = {\n content: string;\n dictionaryKey: string;\n dictionaryPath: string;\n keyPath: KeyPath[];\n isContentSelectable: boolean;\n};\n\nconst IntlayerEditorElement: FC<IntlayerEditorElementProps> = ({\n content,\n isContentSelectable,\n ...props\n}) => {\n if (enabled && isContentSelectable) {\n return (\n <ContentSelectorConnector {...props}>{content}</ContentSelectorConnector>\n );\n }\n return content;\n};\n\nexport type IntlayerNode<T = string> = ReactNode & {\n value: T;\n};\n\nexport const renderIntlayerEditor = (\n data: IntlayerEditorElementProps,\n isContentSelectable = true\n): IntlayerNode => {\n const Result = (\n <IntlayerEditorElement\n {...data}\n isContentSelectable={isContentSelectable}\n />\n );\n\n return { ...Result, value: data.content };\n};\n"],"mappings":"AAwBM;AAxBN,SAAS,wBAAwB;AAGjC,SAAS,gCAAgC;AAEzC,MAAM;AAAA,EACJ,QAAQ,EAAE,QAAQ;AACpB,IAAI,iBAAiB;AAUrB,MAAM,wBAAwD,CAAC;AAAA,EAC7D;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,WAAW,qBAAqB;AAClC,WACE,oBAAC,4BAA0B,GAAG,OAAQ,mBAAQ;AAAA,EAElD;AACA,SAAO;AACT;AAMO,MAAM,uBAAuB,CAClC,MACA,sBAAsB,SACL;AACjB,QAAM,SACJ;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA;AAAA,EACF;AAGF,SAAO,EAAE,GAAG,QAAQ,OAAO,KAAK,QAAQ;AAC1C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryKey !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/getDictionary.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { Locales } from '@intlayer/config';\nimport type {\n DeclarationContent,\n DictionaryValue,\n NodeType,\n} from '@intlayer/core';\nimport { isValidElement, type ReactNode } from 'react';\nimport {\n type IntlayerNode,\n renderIntlayerEditor,\n} from './editor/renderContentEditor';\nimport { processDictionary } from './processDictionary/index';\n\ntype TransformNodeType<T, L extends Locales, R extends boolean> = T extends {\n [NodeType.Enumeration]: { '1': any };\n}\n ? (\n quantity: number\n ) => DeepTransformContent<T[NodeType.Enumeration]['1'], L, R>\n : T extends {\n [NodeType.Translation]: object;\n }\n ? L extends keyof T[NodeType.Translation]\n ? DeepTransformContent<T[NodeType.Translation][L], L, R>\n : never\n : T;\n\nexport type DeepTransformContent<\n T,\n L extends Locales,\n R extends boolean,\n> = T extends object // Check if the property is an object\n ? T extends (infer U)[] // If it's an array, infer the type of array elements\n ? DeepTransformContent<U, L, R>[] // Apply DeepTransformContent recursively to each element of the array\n : T extends {\n nodeType: NodeType | string;\n }\n ? TransformNodeType<T, L, R>\n : T extends { _owner: any; key: any; props: any; ref: any }\n ? ReactNode\n : {\n [K in keyof T]: DeepTransformContent<T[K], L, R>;\n }\n : T extends undefined\n ? never\n : R extends true\n ? IntlayerNode<T>\n : T;\n\n/**\n * Go through the object. If a object has a keyPath, render the intlayer editor if editor enabled.\n */\nexport const recursiveTransformContent = (\n value: any,\n isRenderEditor = false\n): object => {\n if (typeof value === 'function') {\n return (props: any) =>\n recursiveTransformContent(value(props), isRenderEditor);\n } else if (typeof value === 'object') {\n if (typeof value.dictionaryKey !== 'undefined') {\n if (isRenderEditor) {\n return renderIntlayerEditor(value);\n }\n return value.content;\n } else if (Array.isArray(value)) {\n return value.map((el) => recursiveTransformContent(el, isRenderEditor));\n } else if (isValidElement(value)) {\n return value;\n }\n\n return Object.entries(value).reduce(\n (acc, [key, value]) => ({\n ...acc,\n [key]: recursiveTransformContent(value, isRenderEditor),\n }),\n {} as object\n );\n }\n\n return value;\n};\n\ntype DataFromDictionary<\n T extends DeclarationContent,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<T['content'], K, R>;\n\nexport type UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionary<T, L, R>;\n\n/**\n * Hook that picks one dictionary by its id and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getDictionary: UseDictionary = <\n T extends DeclarationContent,\n L extends Locales,\n R extends boolean = false,\n>(\n dictionary: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const result = processDictionary(\n dictionary.content as DictionaryValue,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionary<T, L, R>;\n};\n"],"mappings":"AAOA,SAAS,sBAAsC;AAC/C;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AAyC3B,MAAM,4BAA4B,CACvC,OACA,iBAAiB,UACN;AACX,MAAI,OAAO,UAAU,YAAY;AAC/B,WAAO,CAAC,UACN,0BAA0B,MAAM,KAAK,GAAG,cAAc;AAAA,EAC1D,WAAW,OAAO,UAAU,UAAU;AACpC,QAAI,OAAO,MAAM,kBAAkB,aAAa;AAC9C,UAAI,gBAAgB;AAClB,eAAO,qBAAqB,KAAK;AAAA,MACnC;AACA,aAAO,MAAM;AAAA,IACf,WAAW,MAAM,QAAQ,KAAK,GAAG;AAC/B,aAAO,MAAM,IAAI,CAAC,OAAO,0BAA0B,IAAI,cAAc,CAAC;AAAA,IACxE,WAAW,eAAe,KAAK,GAAG;AAChC,aAAO;AAAA,IACT;AAEA,WAAO,OAAO,QAAQ,KAAK,EAAE;AAAA,MAC3B,CAAC,KAAK,CAAC,KAAKA,MAAK,OAAO;AAAA,QACtB,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,0BAA0BA,QAAO,cAAc;AAAA,MACxD;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;AAuBO,MAAM,gBAA+B,CAK1C,YACA,QACA,iBAAoB,UACjB;AACH,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["value"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getEnumeration({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * }, 2);\n * // 'You have two'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // 'You have less than four'\n * ```\n *\n */\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n return result;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/getEnumeration.ts"],"sourcesContent":["import { type QuantityContent, getEnumerationContent } from '@intlayer/core';\n\n/**\n * Allow to pick a content based on a quantity.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getEnumeration({\n * '<=-2.3': 'You have less than -2.3',\n * '<1': 'You have less than one',\n * '2': 'You have two',\n * '>=3': 'You have three or more',\n * }, 2);\n * // 'You have two'\n * ```\n *\n * The order of the keys will define the priority of the content.\n *\n * ```ts\n * const content = getEnumeration({\n * '<4': 'You have less than four',\n * '2': 'You have two',\n * }, 2);\n * // 'You have less than four'\n * ```\n *\n */\nexport const getEnumeration = <Content>(\n enumerationContent: QuantityContent<Content>,\n quantity: number\n): Content => {\n const result: Content = getEnumerationContent<Content>(\n enumerationContent,\n quantity\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAA+B,6BAA6B;AA8BrD,MAAM,iBAAiB,CAC5B,oBACA,aACY;AACZ,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './getDictionary';\nimport { processDictionary } from './processDictionary/index';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\nexport type DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport type { Dictionary } from '@intlayer/core';\n/**\n * @intlayer/dictionaries-entry is a package that only returns the dictionary entry path.\n * Using an external package allow to alias it in the bundle configuration (such as webpack).\n * The alias allow hot reload the app (such as nextjs) on any dictionary change.\n */\nimport dictionaries from '@intlayer/dictionaries-entry';\nimport type { IntlayerDictionaryTypesConnector } from 'intlayer';\nimport {\n type DeepTransformContent,\n recursiveTransformContent,\n} from './getDictionary';\nimport { processDictionary } from './processDictionary/index';\n\n/**\n * Provides a fallback to string type if the generic type T is never,\n * otherwise returns T. This is useful for handling cases where no keys are found.\n * Example: StringFallback<never> -> string; StringFallback<'key'> -> 'key'\n */\nexport type StringFallback<T> = T extends never ? string : T; // If no keys are found, return string to disable error, and accept any string as dictionary key\n\n/**\n * Represents the keys of the IntlayerDictionaryTypesConnector,\n * ensuring they are valid dictionary keys or fallback to string if none exist.\n *\n * Example:\n * ```ts\n * DictionaryKeys -> 'key1' | 'key2'\n * // or if IntlayerDictionaryTypesConnector is not defined,\n * DictionaryKeys -> string\n * ```\n */\nexport type DictionaryKeys = StringFallback<\n keyof IntlayerDictionaryTypesConnector\n>;\n\n/**\n * Represents the data type returned by the useIntlayer hook,\n * excluding the 'id' and 'filePath' keys from the dictionary content.\n */\nexport type DataFromDictionaryKey<\n T extends DictionaryKeys,\n K extends Locales,\n R extends boolean = false,\n> = DeepTransformContent<IntlayerDictionaryTypesConnector[T]['content'], K, R>;\n\n/**\n * Type definition for the useIntlayer hook, which takes a dictionary ID and an optional locale,\n * and returns the deeply transformed dictionary content.\n *\n */\nexport type UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport type UseIntlayerEditable = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => DataFromDictionaryKey<T, L, R>;\n\nexport const getIntlayer: UseIntlayer = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = false,\n>(\n key: T,\n locale?: L,\n isRenderEditor: R = false as R\n) => {\n const dictionary: Dictionary = dictionaries[key as keyof typeof dictionaries];\n\n if (!dictionary) {\n throw new Error(`Dictionary ${key} not found`, dictionaries);\n }\n\n const result = processDictionary(\n dictionary.content,\n dictionary.key,\n dictionary.filePath,\n [],\n locale\n );\n\n return recursiveTransformContent(\n result,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n};\n"],"mappings":"AAOA,OAAO,kBAAkB;AAEzB;AAAA,EAEE;AAAA,OACK;AACP,SAAS,yBAAyB;AA2D3B,MAAM,cAA2B,CAKtC,KACA,QACA,iBAAoB,UACjB;AACH,QAAM,aAAyB,aAAa,GAAgC;AAE5E,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,cAAc,GAAG,cAAc,YAAY;AAAA,EAC7D;AAEA,QAAM,SAAS;AAAA,IACb,WAAW;AAAA,IACX,WAAW;AAAA,IACX,WAAW;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { fetchDistantDictionary } from './distantDictionary/fetchDistantDictionary';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/getIntlayerAsync.ts"],"sourcesContent":["'use client';\n\nimport type { Locales } from '@intlayer/config/client';\nimport { DeclarationContent } from 'intlayer';\nimport { fetchDistantDictionary } from './distantDictionary/fetchDistantDictionary';\nimport { getDictionary } from './getDictionary';\nimport { DictionaryKeys, DataFromDictionaryKey } from './getIntlayer';\n\nexport type GetIntlayerAsync = <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor?: R\n) => Promise<DataFromDictionaryKey<T, L, R> | null>;\n\n/**\n * On the client side, Hook that picking one dictionary by its key and return the content\n *\n * This hook will prerender the locale dictionary and fetch simultaneously the distant dictionaries to hydrate it.\n *\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const getIntlayerAsync: GetIntlayerAsync = async <\n T extends DictionaryKeys,\n L extends Locales,\n R extends boolean = true,\n>(\n key: T,\n locale?: L,\n isRenderEditor = true as R\n) => {\n const jsonDistantDictionary = await fetchDistantDictionary(key);\n\n if (jsonDistantDictionary) {\n return getDictionary(\n jsonDistantDictionary as unknown as DeclarationContent,\n locale,\n isRenderEditor\n ) as DataFromDictionaryKey<T, L, R>;\n }\n\n return null;\n};\n"],"mappings":";AAIA,SAAS,8BAA8B;AACvC,SAAS,qBAAqB;AAqBvB,MAAM,mBAAqC,OAKhD,KACA,QACA,iBAAiB,SACd;AACH,QAAM,wBAAwB,MAAM,uBAAuB,GAAG;AAE9D,MAAI,uBAAuB;AACzB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = getConfiguration().internationalization;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n return result;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/getTranslation.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\n\n/**\n *\n * Allow to pick a content based on a locale.\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```ts\n * const content = getTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const getTranslation = <Content = string>(\n languageContent: LanguageContent<Content>,\n locale?: Locales\n): Content => {\n const { defaultLocale } = getConfiguration().internationalization;\n\n const result: Content = getTranslationContent<Content>(\n languageContent,\n locale ?? defaultLocale\n );\n\n return result;\n};\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C,SAA+B,6BAA6B;AAuBrD,MAAM,iBAAiB,CAC5B,iBACA,WACY;AACZ,QAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAE7C,QAAM,SAAkB;AAAA,IACtB;AAAA,IACA,UAAU;AAAA,EACZ;AAEA,SAAO;AACT;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useIntlayerAsync,\n useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport { type IntlayerNode } from './editor/renderContentEditor';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export { getTranslation } from './getTranslation';\nexport {\n IntlayerProvider,\n type IntlayerProviderProps,\n IntlayerClientContext,\n useIntlayer,\n useIntlayerAsync,\n useDictionary,\n useLocale,\n useTraduction,\n useLocaleCookie,\n useIntlayerContext,\n localeCookie,\n setLocaleCookie,\n getBrowserLocale,\n useLocaleBase,\n t,\n} from './client/index';\nexport { getDictionary } from './getDictionary';\nexport { getIntlayer } from './getIntlayer';\nexport { type IntlayerNode } from './editor/renderContentEditor';\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode, JSX } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n childrenResult.push(\n createReactElement((children ?? {})[key as keyof typeof children])\n );\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'div',\n props,\n ...(props.children as ReactNode[])\n );\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: DictionaryValue,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryKey,\n dictionaryPath,\n };\n};\n"],"mappings":";AAAA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAMK;AACP,SAA4B,qBAA0C;AACtE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,IAAI,iBAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,eACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,OAAO;AAAA,EAC5C;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,qBACJ,CACE,oBACA,QACA,eACA,gBACA,UAAqB,CAAC,MAExB,CAAC,aAA8C;AAC7C,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAoB;AAAA,IACxB;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA,IACH,EAAE,MAAM,SAAS,aAAa,KAAK,kBAAkB,SAAS,EAAE;AAAA,EAClE;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEF,MAAM,cAAc,CAAC,SACnB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","names":["element"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/processDictionary/index.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n NodeType,\n type QuantityContent,\n type LanguageContent,\n findMatchingCondition,\n type KeyPath,\n type DictionaryValue,\n type TranslationContent,\n type EnumerationContent,\n type TypedNode,\n} from '@intlayer/core';\nimport { type ReactElement, createElement, type ReactNode, JSX } from 'react';\nimport { getEnumeration } from '../getEnumeration';\nimport { getTranslation } from '../getTranslation';\nimport type {\n TransformedContent,\n TransformedContentValue,\n} from './contentDictionary';\n\nconst {\n internationalization: { defaultLocale },\n} = getConfiguration();\n\nconst processTranslation = (\n languageContent: LanguageContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContent => {\n const translationResult: DictionaryValue = getTranslation<DictionaryValue>(\n languageContent,\n locale\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Translation, key: locale },\n ];\n\n return processDictionary(\n translationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n );\n};\n\nconst processEnumeration =\n (\n enumerationContent: QuantityContent<DictionaryValue>,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n ): TransformedContentValue =>\n (quantity: number): TransformedContentValue => {\n const enumerationResult: DictionaryValue = getEnumeration<DictionaryValue>(\n enumerationContent,\n quantity\n );\n\n const matchingCondition = findMatchingCondition(\n enumerationContent,\n quantity\n );\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Enumeration, key: matchingCondition.toString() },\n ];\n\n return processDictionary(\n enumerationResult,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath,\n locale\n ) as TransformedContentValue;\n };\n\nconst isReactNode = (node: Record<string, unknown>): boolean =>\n typeof node?.key !== 'undefined' && typeof node?.props !== 'undefined';\n\nexport const processNode = (\n field: DictionaryValue | undefined,\n locale: Locales,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = []\n): TransformedContentValue => {\n if (typeof field === 'object') {\n if (\n (field as TranslationContent<DictionaryValue>).nodeType ===\n NodeType.Translation\n ) {\n return processTranslation(\n field[\n NodeType.Translation as keyof typeof field\n ] as LanguageContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContentValue;\n }\n\n if (\n (field as EnumerationContent<DictionaryValue>).nodeType ===\n NodeType.Enumeration\n ) {\n return processEnumeration(\n field[\n NodeType.Enumeration as keyof typeof field\n ] as QuantityContent<DictionaryValue>,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n );\n }\n }\n\n return processDictionary(\n field!,\n dictionaryKey,\n dictionaryPath,\n keyPath,\n locale\n ) as TransformedContentValue;\n};\n\n// This function recursively creates React elements from a given JSON-like structure\nconst createReactElement = (element: ReactElement) => {\n if (typeof element === 'string') {\n // If it's a string, simply return it (used for text content)\n return element;\n }\n\n const convertChildrenAsArray = (\n element: ReactElement<{ children?: ReactNode }>\n ): ReactElement<{ children?: ReactNode }> => {\n if (element?.props && typeof element.props.children === 'object') {\n const childrenResult: ReactNode[] = [];\n const { children } = element.props;\n\n // Create the children elements recursively, if any\n Object.keys(children ?? {}).forEach((key) => {\n childrenResult.push(\n createReactElement((children ?? {})[key as keyof typeof children])\n );\n });\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: element.props.children },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as ReactElement<{ children?: ReactNode }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the React element\n return createElement(\n type ?? 'div',\n props,\n ...(props.children as ReactNode[])\n );\n};\n\nconst traceKeys: string[] = ['filePath', 'nodeType'];\n\n/**\n * Function that process a dictionary and return the result to be used in the application.\n */\nexport const processDictionary = (\n content: DictionaryValue,\n dictionaryKey: string,\n dictionaryPath?: string,\n keyPath: KeyPath[] = [],\n locale: Locales = defaultLocale\n): TransformedContent => {\n // If it's a React element, render it\n if (isReactNode(content as Record<string, unknown>)) {\n return createReactElement(\n content as unknown as ReactElement\n ) as unknown as TransformedContent;\n }\n\n if (content && typeof content === 'object') {\n const isArray = Array.isArray(content);\n\n let result: TransformedContent = {};\n\n if (typeof (content as TypedNode).nodeType !== 'undefined') {\n return processNode(\n content as DictionaryValue,\n locale,\n dictionaryKey,\n dictionaryPath,\n keyPath\n ) as TransformedContent;\n } else if (isArray) {\n // Eslint fix because promises are awaited during build stage\n\n result = (content as DictionaryValue[]).map((field, key) => {\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Array, key },\n ];\n\n return processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n }) as TransformedContent;\n } else {\n // List each key in the content and process it\n for (const key of Object.keys(content)) {\n const field = content[key as keyof typeof content];\n\n if (traceKeys.includes(key)) {\n result[key] = field as TransformedContentValue;\n continue;\n }\n\n const resultKeyPath: KeyPath[] = [\n ...keyPath,\n { type: NodeType.Object, key },\n ];\n\n const nodeResult = processNode(\n field,\n locale,\n dictionaryKey,\n dictionaryPath,\n resultKeyPath\n );\n\n result[key] = nodeResult;\n }\n }\n\n return result;\n }\n\n return {\n content: content as TransformedContentValue,\n keyPath,\n dictionaryKey,\n dictionaryPath,\n };\n};\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C;AAAA,EACE;AAAA,EAGA;AAAA,OAMK;AACP,SAA4B,qBAA0C;AACtE,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAM/B,MAAM;AAAA,EACJ,sBAAsB,EAAE,cAAc;AACxC,IAAI,iBAAiB;AAErB,MAAM,qBAAqB,CACzB,iBACA,QACA,eACA,gBACA,UAAqB,CAAC,MACC;AACvB,QAAM,oBAAqC;AAAA,IACzC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAA2B;AAAA,IAC/B,GAAG;AAAA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,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH,OAAO;AAEL,iBAAW,OAAO,OAAO,KAAK,OAAO,GAAG;AACtC,cAAM,QAAQ,QAAQ,GAA2B;AAEjD,YAAI,UAAU,SAAS,GAAG,GAAG;AAC3B,iBAAO,GAAG,IAAI;AACd;AAAA,QACF;AAEA,cAAM,gBAA2B;AAAA,UAC/B,GAAG;AAAA,UACH,EAAE,MAAM,SAAS,QAAQ,IAAI;AAAA,QAC/B;AAEA,cAAM,aAAa;AAAA,UACjB;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAEA,eAAO,GAAG,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["element"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<Locales>(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?: Locales;\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":"
|
|
1
|
+
{"version":3,"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<Locales>(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?: Locales;\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":"AAiCE;AAjCF,SAAuB,wBAAwB;AAE/C,SAAS,qBAAqB,wBAAwB;AAEtD,MAAM,EAAE,cAAc,IAAI,iBAAiB,EAAE;AAKtC,MAAM,wBACX,oBAA6B,aAAa;AAKrC,MAAM,cAAc,MAAM,iBAAiB,qBAAqB;AAKhE,MAAM,SAAS,iBAAiB,qBAAqB;AASrD,MAAM,yBAA0D,CAAC;AAAA,EACtE;AAAA,EACA,QAAAA,UAAS;AACX,MACE,oBAAC,sBAAsB,UAAtB,EAA+B,OAAOA,SACpC,UACH;","names":["locale"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, get the translation content based on the locale\n */\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(IntlayerServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? getConfiguration().internationalization.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/server/getLocaleTranslation.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\nimport { type LanguageContent, getTranslationContent } from '@intlayer/core';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, get the translation content based on the locale\n */\nexport const getLocaleTranslation = <Content>(\n languageContent: LanguageContent<Content>\n) => {\n const locale = getServerContext(IntlayerServerContext);\n const content = getTranslationContent<Content>(\n languageContent,\n locale ?? getConfiguration().internationalization.defaultLocale\n );\n\n return {\n locale,\n content,\n };\n};\n"],"mappings":"AAAA,SAAS,wBAAwB;AACjC,SAA+B,6BAA6B;AAC5D,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAK1B,MAAM,uBAAuB,CAClC,oBACG;AACH,QAAM,SAAS,iBAAiB,qBAAqB;AACrD,QAAM,UAAU;AAAA,IACd;AAAA,IACA,UAAU,iBAAiB,EAAE,qBAAqB;AAAA,EACpD;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n IntlayerServerContext as IntlayerServer,\n locale,\n IntlayerServerProvider,\n} from './IntlayerServerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useDictionary } from './useDictionary';\nexport { t } from './t';\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export { getLocaleTranslation as getLocaleContent } from './getLocaleTranslation';\nexport { useTraduction } from './useTraduction';\nexport {\n IntlayerServerContext as IntlayerServer,\n locale,\n IntlayerServerProvider,\n} from './IntlayerServerProvider';\nexport { useIntlayer } from './useIntlayer';\nexport { useDictionary } from './useDictionary';\nexport { t } from './t';\n"],"mappings":"AAAA,SAAiC,4BAAwB;AACzD,SAAS,qBAAqB;AAC9B;AAAA,EAC2B;AAAA,EACzB;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAC9B,SAAS,SAAS;","names":[]}
|