next-intlayer 9.3.2 → 9.4.0-canary.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/README.md +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/proxy/intlayerProxy.cjs +25 -7
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/rsc/index.cjs +96 -0
- package/dist/cjs/server/IntlayerProvider.cjs +54 -0
- package/dist/cjs/server/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs +17 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -0
- package/dist/cjs/server/ambientLocale.cjs +64 -0
- package/dist/cjs/server/ambientLocale.cjs.map +1 -0
- package/dist/cjs/server/format/index.cjs +17 -7
- package/dist/cjs/server/format/useCompact.cjs +26 -0
- package/dist/cjs/server/format/useCompact.cjs.map +1 -0
- package/dist/cjs/server/format/useCurrency.cjs +26 -0
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -0
- package/dist/cjs/server/format/useDate.cjs +33 -0
- package/dist/cjs/server/format/useDate.cjs.map +1 -0
- package/dist/cjs/server/format/useList.cjs +26 -0
- package/dist/cjs/server/format/useList.cjs.map +1 -0
- package/dist/cjs/server/format/useNumber.cjs +26 -0
- package/dist/cjs/server/format/useNumber.cjs.map +1 -0
- package/dist/cjs/server/format/usePercentage.cjs +26 -0
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -0
- package/dist/cjs/server/format/useRelativeTime.cjs +26 -0
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -0
- package/dist/cjs/server/format/useUnit.cjs +26 -0
- package/dist/cjs/server/format/useUnit.cjs.map +1 -0
- package/dist/cjs/server/index.cjs +27 -43
- package/dist/cjs/server/prepareSwcOptimization.cjs +1 -1
- package/dist/cjs/server/prepareSwcOptimization.cjs.map +1 -1
- package/dist/cjs/server/suspendingReader.cjs +45 -0
- package/dist/cjs/server/suspendingReader.cjs.map +1 -0
- package/dist/cjs/server/t.cjs +16 -0
- package/dist/cjs/server/t.cjs.map +1 -0
- package/dist/cjs/server/useDictionary.cjs +5 -4
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +5 -7
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +5 -4
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +17 -0
- package/dist/cjs/server/useI18n.cjs.map +1 -0
- package/dist/cjs/server/useIntl.cjs +16 -0
- package/dist/cjs/server/useIntl.cjs.map +1 -0
- package/dist/cjs/server/useIntlayer.cjs +5 -20
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +26 -0
- package/dist/cjs/server/useLocale.cjs.map +1 -0
- package/dist/cjs/server/withIntlayer.cjs +2 -3
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/proxy/intlayerProxy.mjs +26 -8
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/rsc/index.mjs +18 -0
- package/dist/esm/server/IntlayerProvider.mjs +53 -0
- package/dist/esm/server/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/server/IntlayerServerProvider.mjs +16 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -0
- package/dist/esm/server/ambientLocale.mjs +61 -0
- package/dist/esm/server/ambientLocale.mjs.map +1 -0
- package/dist/esm/server/format/index.mjs +10 -1
- package/dist/esm/server/format/useCompact.mjs +25 -0
- package/dist/esm/server/format/useCompact.mjs.map +1 -0
- package/dist/esm/server/format/useCurrency.mjs +25 -0
- package/dist/esm/server/format/useCurrency.mjs.map +1 -0
- package/dist/esm/server/format/useDate.mjs +32 -0
- package/dist/esm/server/format/useDate.mjs.map +1 -0
- package/dist/esm/server/format/useList.mjs +25 -0
- package/dist/esm/server/format/useList.mjs.map +1 -0
- package/dist/esm/server/format/useNumber.mjs +25 -0
- package/dist/esm/server/format/useNumber.mjs.map +1 -0
- package/dist/esm/server/format/usePercentage.mjs +25 -0
- package/dist/esm/server/format/usePercentage.mjs.map +1 -0
- package/dist/esm/server/format/useRelativeTime.mjs +25 -0
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -0
- package/dist/esm/server/format/useUnit.mjs +25 -0
- package/dist/esm/server/format/useUnit.mjs.map +1 -0
- package/dist/esm/server/index.mjs +12 -2
- package/dist/esm/server/prepareSwcOptimization.mjs +1 -1
- package/dist/esm/server/prepareSwcOptimization.mjs.map +1 -1
- package/dist/esm/server/suspendingReader.mjs +42 -0
- package/dist/esm/server/suspendingReader.mjs.map +1 -0
- package/dist/esm/server/t.mjs +15 -0
- package/dist/esm/server/t.mjs.map +1 -0
- package/dist/esm/server/useDictionary.mjs +5 -4
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +5 -7
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +5 -4
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +16 -0
- package/dist/esm/server/useI18n.mjs.map +1 -0
- package/dist/esm/server/useIntl.mjs +15 -0
- package/dist/esm/server/useIntl.mjs.map +1 -0
- package/dist/esm/server/useIntlayer.mjs +6 -18
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +25 -0
- package/dist/esm/server/useLocale.mjs.map +1 -0
- package/dist/esm/server/withIntlayer.mjs +2 -3
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-purge.d.ts +2 -2
- package/dist/types/@intlayer/babel/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts +2 -2
- package/dist/types/@intlayer/babel/dist/types/extractContent/contentWriter.d.ts +2 -2
- package/dist/types/@intlayer/babel/dist/types/getOptimizePluginOptions.d.ts +2 -2
- package/dist/types/@intlayer/babel/dist/types/getPurgePluginOptions.d.ts +2 -2
- package/dist/types/client/useLocalePageRouter.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/dist/types/rsc/index.d.ts +19 -0
- package/dist/types/server/IntlayerProvider.d.ts +43 -0
- package/dist/types/server/IntlayerProvider.d.ts.map +1 -0
- package/dist/types/server/IntlayerServerProvider.d.ts +13 -0
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -0
- package/dist/types/server/ambientLocale.d.ts +34 -0
- package/dist/types/server/ambientLocale.d.ts.map +1 -0
- package/dist/types/server/format/index.d.ts +9 -1
- package/dist/types/server/format/useCompact.d.ts +16 -0
- package/dist/types/server/format/useCompact.d.ts.map +1 -0
- package/dist/types/server/format/useCurrency.d.ts +16 -0
- package/dist/types/server/format/useCurrency.d.ts.map +1 -0
- package/dist/types/server/format/useDate.d.ts +20 -0
- package/dist/types/server/format/useDate.d.ts.map +1 -0
- package/dist/types/server/format/useList.d.ts +16 -0
- package/dist/types/server/format/useList.d.ts.map +1 -0
- package/dist/types/server/format/useNumber.d.ts +16 -0
- package/dist/types/server/format/useNumber.d.ts.map +1 -0
- package/dist/types/server/format/usePercentage.d.ts +16 -0
- package/dist/types/server/format/usePercentage.d.ts.map +1 -0
- package/dist/types/server/format/useRelativeTime.d.ts +16 -0
- package/dist/types/server/format/useRelativeTime.d.ts.map +1 -0
- package/dist/types/server/format/useUnit.d.ts +16 -0
- package/dist/types/server/format/useUnit.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +12 -2
- package/dist/types/server/prepareSwcOptimization.d.ts +1 -1
- package/dist/types/server/prepareSwcOptimization.d.ts.map +1 -1
- package/dist/types/server/suspendingReader.d.ts +22 -0
- package/dist/types/server/suspendingReader.d.ts.map +1 -0
- package/dist/types/server/t.d.ts +13 -0
- package/dist/types/server/t.d.ts.map +1 -0
- package/dist/types/server/useDictionary.d.ts +2 -1
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +5 -4
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +3 -2
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/server/useI18n.d.ts +14 -0
- package/dist/types/server/useI18n.d.ts.map +1 -0
- package/dist/types/server/useIntl.d.ts +13 -0
- package/dist/types/server/useIntl.d.ts.map +1 -0
- package/dist/types/server/useIntlayer.d.ts +4 -5
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/dist/types/server/useLocale.d.ts +20 -0
- package/dist/types/server/useLocale.d.ts.map +1 -0
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -327,4 +327,4 @@ Contribute on [GitHub](https://github.com/aymericzip/intlayer), [GitLab](https:/
|
|
|
327
327
|
|
|
328
328
|
If you like Intlayer, give us a ⭐ on GitHub. It helps others discover the project! [See why GitHub Stars matter](https://github.com/aymericzip/intlayer/blob/main/CONTRIBUTING.md#why-github-stars-matter-).
|
|
329
329
|
|
|
330
|
-
[](https://star-history.dera.page/#aymericzip/intlayer&Date)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["useRouter","usePathname","useCallback","getLocalizedUrl","checkIsURLAbsolute","useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl } from '@intlayer/core/localization';\nimport { checkIsURLAbsolute } from '@intlayer/core/utils';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport {\n type UseLocaleResult as UseLocaleResultReact,\n useLocale as useLocaleReact,\n} from 'react-intlayer';\nimport { usePathname } from './usePathname';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n onChange?:\n | 'replace'\n | 'push'\n | 'none'\n | ((params: { locale: LocalesValues; path: string }) => void);\n};\n\nexport type UseLocaleResult = UseLocaleResultReact & {\n pathWithoutLocale: string;\n};\n\n/**\n * Hook to manage the current locale in Next.js App Router.\n *\n * This hook extends the base `useLocale` from `react-intlayer` by adding\n * Next.js-specific navigation logic for locale changes.\n *\n * @param props - Optional properties to configure locale change behavior.\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useLocale } from 'next-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { setLocale } = useLocale({ onChange: 'push' });\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n onChange = 'replace',\n onLocaleChange,\n isCookieEnabled,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathname();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n const currentDomain =\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n typeof window !== 'undefined'\n ? window.location.hostname\n : undefined;\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale, {\n currentDomain,\n });\n\n if (typeof onChange === 'function') {\n onChange({ locale, path: pathWithLocale });\n return;\n }\n\n // Cross-domain navigation: the Next.js router cannot navigate to a\n // different origin, so fall back to a full page load.\n if (\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n checkIsURLAbsolute(pathWithLocale)\n ) {\n try {\n const parsed = new URL(pathWithLocale);\n if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {\n window.location.href = pathWithLocale;\n }\n } catch {\n // Malformed URL — skip redirect\n }\n return;\n }\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [replace, push, pathWithoutLocale, onChange, onLocaleChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n isCookieEnabled,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,aAAa,EACxB,WAAW,WACX,gBACA,oBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,SAAS,aAASA,8BAAU;CACpC,MAAM,oBAAoBC,uCAAY;CAEtC,MAAM,0BAAsBC,oBACzB,WAA0B;EACzB,IAAI,CAAC,UAAU;EAEf,MAAM,gBACJ,QAAQ,IAAI,6BAA6B,WACzC,OAAO,WAAW,cACd,OAAO,SAAS,WAChB;
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["useRouter","usePathname","useCallback","getLocalizedUrl","checkIsURLAbsolute","useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl } from '@intlayer/core/localization';\nimport { checkIsURLAbsolute } from '@intlayer/core/utils';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport {\n type UseLocaleResult as UseLocaleResultReact,\n useLocale as useLocaleReact,\n} from 'react-intlayer';\nimport { usePathname } from './usePathname';\n\nexport type UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: DeclaredLocales) => void;\n onChange?:\n | 'replace'\n | 'push'\n | 'none'\n | ((params: { locale: LocalesValues; path: string }) => void);\n};\n\nexport type UseLocaleResult = UseLocaleResultReact & {\n pathWithoutLocale: string;\n};\n\n/**\n * Hook to manage the current locale in Next.js App Router.\n *\n * This hook extends the base `useLocale` from `react-intlayer` by adding\n * Next.js-specific navigation logic for locale changes.\n *\n * @param props - Optional properties to configure locale change behavior.\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useLocale } from 'next-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { setLocale } = useLocale({ onChange: 'push' });\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n onChange = 'replace',\n onLocaleChange,\n isCookieEnabled,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathname();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n const currentDomain =\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n typeof window !== 'undefined'\n ? window.location.hostname\n : undefined;\n\n // `setLocale` accepts any string (a router param, a cookie, a header),\n // while `getLocalizedUrl` is constrained to the declared locales.\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale, {\n currentDomain,\n });\n\n if (typeof onChange === 'function') {\n onChange({ locale, path: pathWithLocale });\n return;\n }\n\n // Cross-domain navigation: the Next.js router cannot navigate to a\n // different origin, so fall back to a full page load.\n if (\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n checkIsURLAbsolute(pathWithLocale)\n ) {\n try {\n const parsed = new URL(pathWithLocale);\n if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {\n window.location.href = pathWithLocale;\n }\n } catch {\n // Malformed URL — skip redirect\n }\n return;\n }\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [replace, push, pathWithoutLocale, onChange, onLocaleChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n isCookieEnabled,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,MAAa,aAAa,EACxB,WAAW,WACX,gBACA,oBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,SAAS,aAASA,8BAAU;CACpC,MAAM,oBAAoBC,uCAAY;CAEtC,MAAM,0BAAsBC,oBACzB,WAA0B;EACzB,IAAI,CAAC,UAAU;EAEf,MAAM,gBACJ,QAAQ,IAAI,6BAA6B,WACzC,OAAO,WAAW,cACd,OAAO,SAAS,WAChB;EAIN,MAAM,qBAAiBC,6CAAgB,mBAAmB,QAAQ,EAChE,cACF,CAAC;EAED,IAAI,OAAO,aAAa,YAAY;GAClC,SAAS;IAAE;IAAQ,MAAM;GAAe,CAAC;GACzC;EACF;EAIA,IACE,QAAQ,IAAI,6BAA6B,eACzCC,yCAAmB,cAAc,GACjC;GACA,IAAI;IACF,MAAM,SAAS,IAAI,IAAI,cAAc;IACrC,IAAI,OAAO,aAAa,WAAW,OAAO,aAAa,UACrD,OAAO,SAAS,OAAO;GAE3B,QAAQ,CAER;GACA;EACF;EAEA,IAAI,aAAa,WACf,QAAQ,cAAc;EAExB,IAAI,aAAa,QACf,KAAK,cAAc;EAGrB,iBAAiB,MAAyB;CAC5C,GACA;EAAC;EAAS;EAAM;EAAmB;EAAU;CAAc,CAC7D;CAOA,OAAO;EACL,OANsBC,0BAAe;GACrC,gBAAgB;GAChB;EACF,CAGmB;EACjB;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.cjs","names":["useRouter","useMemo","getPathWithoutLocale","useCallback","getLocalizedUrl","useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type {
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.cjs","names":["useRouter","useMemo","getPathWithoutLocale","useCallback","getLocalizedUrl","useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\nimport type { UseLocaleProps, UseLocaleResult } from './useLocale';\n\n/**\n * Hook to manage the current locale in Next.js Page Router.\n *\n * This hook provides locale management functionality tailored for the Next.js Page Router,\n * handling redirections and page reloads upon locale changes.\n *\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocalePageRouter } from 'next-intlayer';\n *\n * const MyComponent = () => {\n * const { setLocale } = useLocalePageRouter();\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocalePageRouter = ({\n onLocaleChange,\n isCookieEnabled,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n // `redirectionFunction` accepts any string, while `getLocalizedUrl` is\n // constrained to the declared locales.\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n onLocaleChange?.(locale as Locale);\n\n return reload();\n },\n [pathWithoutLocale, onLocaleChange, reload]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n isCookieEnabled,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,uBAAuB,EAClC,gBACA,oBACkB,CAAC,MAAuB;CAC1C,MAAM,EAAE,MAAM,UAAU,eAAWA,0BAAU;CAC7C,MAAM,wBAAoBC,yBAClBC,kDAAqB,QAAQ,GACnC,CAAC,QAAQ,CACX;CAEA,MAAM,0BAAsBC,oBACzB,WAA0B;EAGzB,MAAM,qBAAiBC,6CAAgB,mBAAmB,MAAM;EAEhE,KAAK,cAAc;EAEnB,iBAAiB,MAAgB;EAEjC,OAAO,OAAO;CAChB,GACA;EAAC;EAAmB;EAAgB;CAAM,CAC5C;CAOA,OAAO;EACL,OANsBC,0BAAe;GACrC,gBAAgB;GAChB;EACF,CAGmB;EACjB;CACF;AACF"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -37,6 +37,12 @@ Object.defineProperty(exports, 'IntlayerClientContext', {
|
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
exports.IntlayerClientProvider = require_client_IntlayerClientProvider.IntlayerClientProvider;
|
|
40
|
+
Object.defineProperty(exports, 'IntlayerProvider', {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return react_intlayer.IntlayerProvider;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
40
46
|
exports.MarkdownProvider = MarkdownProvider;
|
|
41
47
|
exports.MarkdownRenderer = MarkdownRenderer;
|
|
42
48
|
exports.generateStaticParams = require_generateStaticParams.generateStaticParams;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n getDictionary,\n getIntlayer,\n IntlayerClientContext,\n type IntlayerNode,\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useI18n,\n useIntl,\n useIntlayer,\n useLoadDynamic,\n useLocaleCookie,\n useLocaleStorage,\n} from 'react-intlayer';\nexport * from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["_MarkdownProvider","_useMarkdownContext","_renderMarkdown","_useMarkdownRenderer","_MarkdownRenderer"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n getDictionary,\n getIntlayer,\n IntlayerClientContext,\n type IntlayerNode,\n IntlayerProvider,\n type IntlayerProviderProps,\n localeCookie,\n localeInStorage,\n setLocaleCookie,\n setLocaleInStorage,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useI18n,\n useIntl,\n useIntlayer,\n useLoadDynamic,\n useLocaleCookie,\n useLocaleStorage,\n} from 'react-intlayer';\nexport * from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n\nimport type {\n MarkdownProviderOptions as _MarkdownProviderOptions,\n MarkdownRendererProps as _MarkdownRendererProps,\n RenderMarkdownProps as _RenderMarkdownProps,\n} from './markdown';\nimport {\n MarkdownProvider as _MarkdownProvider,\n MarkdownRenderer as _MarkdownRenderer,\n renderMarkdown as _renderMarkdown,\n useMarkdownContext as _useMarkdownContext,\n useMarkdownRenderer as _useMarkdownRenderer,\n} from './markdown';\n\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownProvider = _MarkdownProvider;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownContext = _useMarkdownContext;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownProviderOptions = _MarkdownProviderOptions;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const renderMarkdown = _renderMarkdown;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const useMarkdownRenderer = _useMarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport const MarkdownRenderer = _MarkdownRenderer;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type RenderMarkdownProps = _RenderMarkdownProps;\n/**\n * @deprecated import from next-intlayer/markdown instead\n */\nexport type MarkdownRendererProps = _MarkdownRendererProps;\n"],"mappings":";;;;;;;;;;;;;AAmDA,MAAa,2DAAmBA;;;;AAIhC,MAAa,6DAAqBC;;;;AAQlC,MAAa,yDAAiBC;;;;AAI9B,MAAa,8DAAsBC;;;;AAInC,MAAa,2DAAmBC"}
|
|
@@ -20,6 +20,25 @@ const prefixDefault = !(process.env.INTLAYER_ROUTING_MODE && process.env.INTLAYE
|
|
|
20
20
|
const internalPrefix = !noPrefix;
|
|
21
21
|
const rewriteRules = process.env.INTLAYER_ROUTING_REWRITE_RULES !== "false" ? (0, _intlayer_core_localization.getRewriteRules)(rewrite, "url") : void 0;
|
|
22
22
|
/**
|
|
23
|
+
* Resolves the locale a localized ("pretty") path belongs to.
|
|
24
|
+
*
|
|
25
|
+
* A path such as `/a-propos` only exists because a rewrite rule maps it to the
|
|
26
|
+
* French locale, so it declares its locale just as explicitly as an `/fr`
|
|
27
|
+
* prefix would. Without this, a visitor whose `Accept-Language` (or stored
|
|
28
|
+
* locale) says `en` gets `/a-propos` canonicalized against the English rules
|
|
29
|
+
* only, which never matches — the proxy then treats it as an unlocalized path
|
|
30
|
+
* and redirects to `/en/a-propos`, a URL no locale owns.
|
|
31
|
+
*
|
|
32
|
+
* Only patterns that differ from their canonical form are considered: a rule
|
|
33
|
+
* whose localized path equals the canonical one (`en: '/about'`) carries no
|
|
34
|
+
* locale signal, and matching on it would hijack the default locale's
|
|
35
|
+
* unprefixed URLs.
|
|
36
|
+
*
|
|
37
|
+
* @param pathname - The request pathname, without any locale prefix.
|
|
38
|
+
* @returns The locale declared by the path, or `undefined` when it declares none.
|
|
39
|
+
*/
|
|
40
|
+
const getRewriteLocale = (pathname) => rewriteRules ? locales?.find((candidate) => (0, _intlayer_core_localization.getCanonicalPath)(pathname, candidate, rewriteRules) !== pathname) : void 0;
|
|
41
|
+
/**
|
|
23
42
|
* Detects if the request is a prefetch request from Next.js.
|
|
24
43
|
*
|
|
25
44
|
* Next.js prefetch requests are identified by:
|
|
@@ -144,6 +163,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
144
163
|
}
|
|
145
164
|
let locale = localLocale ?? require_proxy_localeDetector.localeDetector?.(request) ?? defaultLocale;
|
|
146
165
|
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
166
|
+
locale = getRewriteLocale(pathname) ?? locale;
|
|
147
167
|
const canonicalPath = (0, _intlayer_core_localization.getCanonicalPath)(pathname, locale, rewriteRules);
|
|
148
168
|
const internalPath = internalPrefix ? (0, _intlayer_core_localization.getInternalPath)(canonicalPath, locale) : canonicalPath;
|
|
149
169
|
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);
|
|
@@ -197,9 +217,9 @@ const handlePrefix = (request, localLocale, pathLocale, pathname) => {
|
|
|
197
217
|
const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
198
218
|
let locale = localLocale ?? require_proxy_localeDetector.localeDetector?.(request) ?? defaultLocale;
|
|
199
219
|
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
220
|
+
locale = getRewriteLocale(pathname) ?? locale;
|
|
200
221
|
const canonicalPath = (0, _intlayer_core_localization.getCanonicalPath)(pathname, locale, rewriteRules);
|
|
201
|
-
const
|
|
202
|
-
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
222
|
+
const { path: targetLocalizedPath } = (0, _intlayer_core_localization.resolveLocalizedPath)(canonicalPath, locale, rewriteRules);
|
|
203
223
|
const newPath = constructPath(locale, targetLocalizedPath, basePath, appendLocaleSearchIfNeeded(request.nextUrl.search, locale));
|
|
204
224
|
return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, internalPrefix ? (0, _intlayer_core_localization.getInternalPath)(canonicalPath, locale) : canonicalPath, locale);
|
|
205
225
|
};
|
|
@@ -215,9 +235,8 @@ const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
|
215
235
|
const handleExistingPathLocale = (request, pathLocale, pathname) => {
|
|
216
236
|
const rawPath = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
217
237
|
const canonicalPath = (0, _intlayer_core_localization.getCanonicalPath)(rawPath, pathLocale, rewriteRules);
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
if ((typeof targetLocalizedPathResult === "string" ? false : targetLocalizedPathResult.isRewritten) && targetLocalizedPath !== rawPath) {
|
|
238
|
+
const { path: targetLocalizedPath, isRewritten } = (0, _intlayer_core_localization.resolveLocalizedPath)(canonicalPath, pathLocale, rewriteRules);
|
|
239
|
+
if (isRewritten && targetLocalizedPath !== rawPath) {
|
|
221
240
|
const newPath = constructPath(pathLocale, targetLocalizedPath, basePath, appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale));
|
|
222
241
|
return redirectUrl(request, newPath);
|
|
223
242
|
}
|
|
@@ -240,8 +259,7 @@ const handleExistingPathLocale = (request, pathLocale, pathname) => {
|
|
|
240
259
|
* The key fix for 404s without [locale] folders
|
|
241
260
|
*/
|
|
242
261
|
const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
243
|
-
const
|
|
244
|
-
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
262
|
+
const { path: targetLocalizedPath } = (0, _intlayer_core_localization.resolveLocalizedPath)(canonicalPath, pathLocale, rewriteRules);
|
|
245
263
|
const basePathValue = basePath || "";
|
|
246
264
|
const basePathTrailingSlash = basePathValue.endsWith("/");
|
|
247
265
|
let finalPath = targetLocalizedPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.cjs","names":["internationalization","routing","resolveProxyMode","isProxyStorageLocaleEnabled","formatProxyEnabledMessage","ROUTING_MODE","getRewriteRules","NextResponse","getDomainHostname","getDomainOrigin","getLocaleFromDomain","getCanonicalPath","getInternalPath","getLocaleFromStorageServer","localeDetector","getLocalizedPath"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, log, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n formatProxyEnabledMessage,\n getCanonicalPath,\n getDomainHostname,\n getDomainOrigin,\n getInternalPath,\n getLocaleFromDomain,\n getLocalizedPath,\n getRewriteRules,\n isProxyStorageLocaleEnabled,\n type LocaleDomainMap,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport {\n getLocaleFromStorageServer,\n setLocaleInStorageServer,\n} from '@intlayer/core/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\n/**\n * Controls whether locale detection occurs during Next.js prefetch requests\n * - true: Detect and apply locale during prefetch\n * - false: Use default locale during prefetch (recommended)\n *\n * This setting affects how Next.js handles locale prefetching:\n *\n * Example scenario:\n * - User's browser language is 'fr'\n * - Current page is /fr/about\n * - Link prefetches /about\n *\n * With `detectLocaleOnPrefetchNoPrefix:true`\n * - Prefetch detects 'fr' locale from browser\n * - Redirects prefetch to /fr/about\n *\n * With `detectLocaleOnPrefetchNoPrefix:false` (default)\n * - Prefetch uses default locale\n * - Redirects prefetch to /en/about (assuming 'en' is default)\n *\n * When to use true:\n * - Your app uses non-localized internal links (e.g. <a href=\"/about\">)\n * - You want consistent locale detection behavior between regular and prefetch requests\n *\n * When to use false (default):\n * - Your app uses locale-prefixed links (e.g. <a href=\"/fr/about\">)\n * - You want to optimize prefetching performance\n * - You want to avoid potential redirect loops\n */\nconst DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX = false;\n\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { basePath, mode, rewrite, domains, enableProxy } = routing ?? {};\n\n// Resolved behaviour of the locale-routing proxy. `disabled` turns\n// `intlayerProxy` into a pass-through so apps can handle routing themselves.\n// The env var backing this is injected at build time so bundlers can tree-shake\n// the guarded branches.\nconst proxyMode = resolveProxyMode(enableProxy);\n\n// Next.js inlines NODE_ENV into every bundle, edge middleware included, so this\n// is both reliable and statically eliminable. `next build` is the only command\n// that injects `INTLAYER_ROUTING_ENABLE_PROXY`, meaning a dev server always\n// reaches `resolveProxyMode` through the configuration value.\n//\n// Matched against `development` rather than \"not production\" on purpose: only\n// `next dev` runs a dev server. Any other value (`test`, a custom staging env)\n// has no dev server in play and must keep the full production behaviour.\nconst isDevServer = process.env.NODE_ENV === 'development';\n\n// In auto mode, a dev server keeps locale routing URL-driven: the stored locale\n// is not used as a redirect source, so a stale cookie cannot keep pulling every\n// navigation to another locale while developing.\nconst canUseStorageLocale = isProxyStorageLocaleEnabled(proxyMode, isDevServer);\n\n// Announce the proxy the way the Vite plugin does on `configureServer`. Next\n// has no server-start hook for middleware, so this runs when the middleware\n// module is first evaluated — at the first request `next dev` routes through\n// it. Restricted to the dev server on purpose: in production this module is\n// re-evaluated on every edge cold start, and the line would be pure noise.\nif (isDevServer && proxyMode !== 'disabled') {\n getAppLogger({ log })(formatProxyEnabledMessage(!canUseStorageLocale), {\n level: 'info',\n });\n}\n\n// Note: cookie names are resolved inside LocaleStorage based on configuration\n\n// Derived flags from routing.mode\nconst effectiveMode = mode ?? ROUTING_MODE;\nconst noPrefix =\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix'\n ) &&\n effectiveMode === 'no-prefix') ||\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params');\nconst prefixDefault =\n !(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-all'\n ) && effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules =\n process.env.INTLAYER_ROUTING_REWRITE_RULES !== 'false'\n ? getRewriteRules(rewrite, 'url')\n : undefined;\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests are identified by:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js app-router prefetch)\n *\n * Note: `next-url` and `x-nextjs-data` are intentionally NOT used here.\n * Both are also sent on real client-side navigations (RSC navigation\n * requests and pages-router data requests respectively), so treating them\n * as prefetch would force such navigations to the default locale instead\n * of the user's stored locale.\n *\n * During prefetch, we should ignore cookie-based locale detection\n * to prevent unwanted redirects when users are switching locales.\n *\n * @param request - The incoming Next.js request object.\n * @returns - True if the request is a prefetch request, false otherwise.\n */\nconst isPrefetchRequest = (request: NextRequest): boolean => {\n const purpose = request.headers.get('purpose');\n const nextRouterPrefetch = request.headers.get('next-router-prefetch');\n\n return purpose === 'prefetch' || nextRouterPrefetch === '1';\n};\n\n// Ensure locale is reflected in search params when routing mode is 'search-params'\nconst appendLocaleSearchIfNeeded = (\n search: string | undefined,\n locale: Locale\n): string | undefined => {\n if (\n (process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params') ||\n effectiveMode !== 'search-params'\n )\n return search;\n const params = new URLSearchParams(search ?? '');\n params.set('locale', locale);\n return `?${params.toString()}`;\n};\n\n/**\n * Proxy that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/proxy.ts\n *\n * export { intlayerProxy as proxy } from '@intlayer/next/proxy';\n *\n * // applies this proxy only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main proxy function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n *\n */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n // When the proxy is disabled, pass the request through untouched.\n if (proxyMode === 'disabled') {\n return NextResponse.next();\n }\n\n const pathname = request.nextUrl.pathname;\n\n const localLocale = getLocalLocale(request);\n\n if (noPrefix) {\n return handleNoPrefix(request, localLocale, pathname);\n }\n\n const pathLocale = getPathLocale(pathname);\n\n // Domain routing: if the path locale is mapped to a different domain, redirect there.\n // e.g. intlayer.org/zh/about → https://intlayer.zh/about\n if (\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n pathLocale &&\n domains\n ) {\n const localeDomain = domains[pathLocale];\n\n if (localeDomain) {\n const domainHost = getDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = getDomainOrigin(localeDomain);\n\n return NextResponse.redirect(\n new URL(`${rawPath}${request.nextUrl.search}`, targetOrigin)\n );\n }\n }\n }\n\n // Domain routing: if the current hostname is exclusively mapped to one locale,\n // treat it as that locale's domain — no URL prefix needed.\n // e.g. intlayer.zh/about → internally rewrite to /zh/about\n if (process.env.INTLAYER_ROUTING_DOMAINS !== 'false' && !pathLocale) {\n const domainLocale = getLocaleFromDomain(\n request.nextUrl.hostname,\n domains as LocaleDomainMap\n );\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n\n // Never emit a trailing slash (`/zh/`): Next.js trailing-slash\n // normalisation would redirect it back and forth with this proxy.\n const internalPath = getInternalPath(canonicalPath, domainLocale);\n\n return rewriteUrl(\n request,\n internalPath + (request.nextUrl.search ?? ''),\n domainLocale\n );\n }\n }\n\n return handlePrefix(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\n *\n * Returns `undefined` when the stored locale is not allowed to drive locale\n * resolution (auto mode on a dev server), which makes every caller fall through\n * to `Accept-Language` detection and then the default locale.\n *\n * @param request - The incoming Next.js request object.\n * @returns - The locale found in the cookies, or undefined if not found or invalid.\n */\nconst getLocalLocale = (request: NextRequest): Locale | undefined => {\n if (!canUseStorageLocale) return undefined;\n\n return getLocaleFromStorageServer({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n getHeader: (name: string) => request.headers.get(name) ?? null,\n });\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n const pathLocale = getPathLocale(pathname);\n\n if (pathLocale) {\n const pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || '/';\n\n const canonicalPath = getCanonicalPath(\n pathWithoutLocale,\n pathLocale,\n rewriteRules\n );\n\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n const redirectPath = search\n ? `${canonicalPath}${search}`\n : `${canonicalPath}${request.nextUrl.search ?? ''}`;\n\n // Persist the explicitly-requested locale: stripping the prefix drops the\n // only locale signal from the URL, so without this the follow-up request\n // would fall back to cookie / Accept-Language detection and could resolve\n // a different locale.\n return redirectUrl(request, redirectPath, pathLocale);\n }\n\n if (\n !(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params'\n ) {\n const existingSearchParams = new URLSearchParams(request.nextUrl.search);\n const existingLocale = existingSearchParams.get('locale');\n\n const isExistingValid = locales?.includes(existingLocale as Locale);\n\n let locale = (localLocale ??\n (isExistingValid ? (existingLocale as Locale) : undefined) ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n const canonicalPath = getCanonicalPath(\n pathname,\n locale as Locale,\n rewriteRules\n );\n\n if (existingLocale === locale) {\n const internalPath = internalPrefix\n ? getInternalPath(canonicalPath, locale as Locale)\n : canonicalPath;\n const rewritePath = `${internalPath}${request.nextUrl.search ?? ''}`;\n return rewriteUrl(request, rewritePath, locale as Locale);\n }\n\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n locale as Locale\n );\n // Use original pathname for redirect to preserve user's URL input, just adding params\n const redirectPath = search\n ? `${pathname}${search}`\n : `${pathname}${request.nextUrl.search ?? ''}`;\n\n return redirectUrl(request, redirectPath);\n }\n\n // effectiveMode === 'no-prefix'\n let locale = (localLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n const canonicalPath = getCanonicalPath(\n pathname,\n locale as Locale,\n rewriteRules\n );\n\n const internalPath = internalPrefix\n ? getInternalPath(canonicalPath, locale as Locale)\n : canonicalPath;\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n locale as Locale\n );\n const rewritePath = search\n ? `${internalPath}${search}`\n : `${internalPath}${request.nextUrl.search ?? ''}`;\n\n return rewriteUrl(request, rewritePath, locale as Locale);\n};\n\n/**\n * Checks whether a pathname starts with the given locale as a full path\n * segment (`/fr` or `/fr/...`). A bare `startsWith('/fr')` would also match\n * unrelated paths like `/friends`, causing wrong prefix stripping and\n * self-redirect loops.\n *\n * @param pathname - The pathname to test.\n * @param locale - The locale to look for as the first path segment.\n * @returns - True if the first path segment is exactly the locale.\n */\nconst hasLocaleSegmentPrefix = (pathname: string, locale: Locale): boolean =>\n pathname === `/${locale}` || pathname.startsWith(`/${locale}/`);\n\n/**\n * Extracts the locale from the URL pathname if present.\n *\n * @param pathname - The pathname from the request URL.\n * @returns - The locale found in the pathname, or undefined if not found.\n */\nconst getPathLocale = (pathname: string): Locale | undefined =>\n (locales as Locale[] | undefined)?.find((locale) =>\n hasLocaleSegmentPrefix(pathname, locale)\n );\n\n/**\n * Handles the case where URLs have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handlePrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n if (!pathLocale) {\n const isPrefetch = isPrefetchRequest(request);\n if (isPrefetch && !DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX) {\n return handleMissingPathLocale(\n request,\n defaultLocale as Locale,\n pathname\n );\n }\n return handleMissingPathLocale(request, localLocale, pathname);\n }\n\n return handleExistingPathLocale(request, pathLocale, pathname);\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleMissingPathLocale = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n let locale = (localLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n // Resolve to canonical path.\n // If user visits /a-propos (implied 'fr'), we resolve to /about\n const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);\n\n // Determine target localized path for redirection\n // /about + 'fr' -> /a-propos\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n locale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const newPath = constructPath(\n locale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n // Never emit a trailing slash (`/en/` for canonicalPath `/`): Next.js\n // trailing-slash normalisation would redirect it back and forth with this\n // proxy. `getInternalPath` collapses the root path to `/${locale}`.\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(\n request,\n internalPrefix ? getInternalPath(canonicalPath, locale) : canonicalPath,\n locale\n ); // Rewrite must use Canonical\n};\n\n/**\n * Handles requests where the locale exists in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @returns - The response to be returned to the client.\n */\nconst handleExistingPathLocale = (\n request: NextRequest,\n pathLocale: Locale,\n pathname: string\n): NextResponse => {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n\n // 1. Identify the Canonical Path (Internal Next.js path)\n // Ex: /a-propos (from URL) -> /about (Canonical)\n const canonicalPath = getCanonicalPath(rawPath, pathLocale, rewriteRules);\n\n // By skipping the forced localLocale check, we allow the explicit pathLocale\n // to take precedence, which correctly updates the header/cookie when navigating.\n\n // Rewrite Logic\n // We must rewrite to the Next.js internal structure: /[locale]/[canonicalPath]\n // Ex: Rewrite /fr/a-propos -> /fr/about\n\n // 2. Redirect to localized path if needed (Canonical -> Localized)\n // Ex: /fr/about -> /fr/a-propos\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n const isRewritten =\n typeof targetLocalizedPathResult === 'string'\n ? false\n : targetLocalizedPathResult.isRewritten;\n\n if (isRewritten && targetLocalizedPath !== rawPath) {\n const newPath = constructPath(\n pathLocale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale)\n );\n return redirectUrl(request, newPath);\n }\n\n // Never emit a trailing slash (`/fr/` for the bare `/fr` URL): rewriting\n // `/fr` to `/fr/` makes Next.js issue a trailing-slash normalisation\n // redirect back to `/fr`, which this proxy rewrites again — an infinite\n // redirect loop. `getInternalPath` collapses the root path to `/${locale}`.\n const internalUrl = internalPrefix\n ? getInternalPath(canonicalPath, pathLocale)\n : canonicalPath;\n\n // Only handle redirect if we are strictly managing default locale prefixing\n // Fix: pass `canonicalPath` (the path *without* the locale prefix, e.g. /pricing)\n // instead of `pathname` (the full path including prefix, e.g. /en/pricing).\n // Previously this caused an infinite redirect loop in prefix-no-default mode\n // because handleDefaultLocaleRedirect built the redirect target from its third\n // argument, which reproduced the same URL on every response.\n if (!prefixDefault && pathLocale === defaultLocale) {\n return handleDefaultLocaleRedirect(request, pathLocale, canonicalPath);\n }\n\n const search = request.nextUrl.search;\n return rewriteUrl(request, internalUrl + (search ?? ''), pathLocale);\n};\n\n/**\n * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param pathname - The pathname from the request URL.\n * @param pathLocale - The locale extracted from the pathname.\n * @param localLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @returns - The new URL path with the correct locale.\n */\n// Function handleCookieLocaleMismatch was removed because the URL locale should take precedence over the stored locale.\n\n/**\n * The key fix for 404s without [locale] folders\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locale,\n canonicalPath: string // Internal path (e.g. /about)\n): NextResponse => {\n // Always called with !prefixDefault && pathLocale === defaultLocale (pre-validated by caller).\n // Redirect to strip the default-locale prefix from the URL.\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const basePathValue = (basePath as string) || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n // Persist the explicitly-requested default locale. Stripping the prefix\n // (e.g. /es → /) drops the only locale signal from the URL, so without this\n // the follow-up request to the canonical path would fall back to\n // Accept-Language detection and could resolve a different locale (e.g. /en).\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? ''),\n pathLocale\n );\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n search?: string\n): string => {\n // Remove existing locale prefix from path if it was passed by mistake,\n // though we usually pass localized paths here now.\n const pathWithoutPrefix = hasLocaleSegmentPrefix(path, locale)\n ? path.slice(`/${locale}`.length) || '/'\n : path;\n\n if (\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix'\n ) &&\n effectiveMode === 'no-prefix') ||\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params')\n ) {\n // `search` is either undefined or already has a leading '?' (from\n // appendLocaleSearchIfNeeded / request.nextUrl.search), so append as-is.\n return `${pathWithoutPrefix}${search ?? ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = hasLocaleSegmentPrefix(path, locale)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathValue = basePath || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n const newPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n // Never emit a trailing slash (`/fr/` for the root path): the framework's\n // trailing-slash normalisation would redirect it back and forth with this\n // proxy, creating an infinite redirect loop.\n return cleanPath !== '/' && cleanPath.endsWith('/')\n ? cleanPath.slice(0, -1)\n : cleanPath;\n};\n\n/**\n * This handles the internal path Next.js sees.\n * To support optional [locale] folders, we need to decide if we\n * keep the locale prefix or strip it.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locale\n): NextResponse => {\n const search = request.nextUrl.search;\n\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @param persistLocale - When provided, the locale is written to storage\n * (cookie/header, per config) on the redirect response so the follow-up\n * request resolves the same locale instead of re-running detection.\n * @returns - The redirect response.\n */\nconst redirectUrl = (\n request: NextRequest,\n newPath: string,\n persistLocale?: Locale\n): NextResponse => {\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.hash}`,\n request.url\n );\n\n const response = NextResponse.redirect(safeTarget);\n\n if (persistLocale) {\n persistLocaleOnResponse(response, persistLocale);\n }\n\n return response;\n};\n\n/**\n * Writes the resolved locale to the outgoing response's storage (cookie and/or\n * header, according to `routing.storage`). Only the cookie survives a client\n * redirect, so this is what carries an explicitly-selected locale across a\n * prefix-stripping redirect. Enabled cookie/header targets are resolved by\n * {@link setLocaleInStorageServer} from the config; disabled ones are no-ops.\n *\n * @param response - The outgoing Next.js response to attach storage to.\n * @param locale - The locale to persist.\n */\nconst persistLocaleOnResponse = (\n response: NextResponse,\n locale: Locale\n): void => {\n setLocaleInStorageServer(locale, {\n setCookieStore: (name, value, attributes) => {\n response.cookies.set(name, value, {\n path: attributes.path,\n domain: attributes.domain,\n expires:\n typeof attributes.expires === 'number'\n ? new Date(attributes.expires)\n : attributes.expires,\n secure: attributes.secure,\n sameSite: attributes.sameSite,\n httpOnly: attributes.httpOnly,\n });\n },\n setHeader: (name, value) => {\n response.headers.set(name, value);\n },\n });\n};\n"],"mappings":";;;;;;;;;;AA2DA,MAAM,EAAE,SAAS,kBAAkBA,+CAAwB,CAAC;AAC5D,MAAM,EAAE,UAAU,MAAM,SAAS,SAAS,gBAAgBC,kCAAW,CAAC;AAMtE,MAAM,gBAAYC,8CAAiB,WAAW;AAU9C,MAAM,cAAc,QAAQ,IAAI,aAAa;AAK7C,MAAM,0BAAsBC,yDAA4B,WAAW,WAAW;AAO9E,IAAI,eAAe,cAAc,YAC/B,0CAAa,EAAE,gCAAI,CAAC,CAAC,KAACC,uDAA0B,CAAC,mBAAmB,GAAG,EACrE,OAAO,OACT,CAAC;AAMH,MAAM,gBAAgB,QAAQC;AAC9B,MAAM,WACH,EACC,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,gBAEtC,kBAAkB,eACnB,EACC,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,oBAEtC,kBAAkB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,"file":"intlayerProxy.cjs","names":["internationalization","routing","resolveProxyMode","isProxyStorageLocaleEnabled","formatProxyEnabledMessage","ROUTING_MODE","getRewriteRules","getCanonicalPath","NextResponse","getDomainHostname","getDomainOrigin","getLocaleFromDomain","getInternalPath","getLocaleFromStorageServer","localeDetector","resolveLocalizedPath"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, log, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n formatProxyEnabledMessage,\n getCanonicalPath,\n getDomainHostname,\n getDomainOrigin,\n getInternalPath,\n getLocaleFromDomain,\n getRewriteRules,\n isProxyStorageLocaleEnabled,\n type LocaleDomainMap,\n resolveLocalizedPath,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport {\n getLocaleFromStorageServer,\n setLocaleInStorageServer,\n} from '@intlayer/core/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\n/**\n * Controls whether locale detection occurs during Next.js prefetch requests\n * - true: Detect and apply locale during prefetch\n * - false: Use default locale during prefetch (recommended)\n *\n * This setting affects how Next.js handles locale prefetching:\n *\n * Example scenario:\n * - User's browser language is 'fr'\n * - Current page is /fr/about\n * - Link prefetches /about\n *\n * With `detectLocaleOnPrefetchNoPrefix:true`\n * - Prefetch detects 'fr' locale from browser\n * - Redirects prefetch to /fr/about\n *\n * With `detectLocaleOnPrefetchNoPrefix:false` (default)\n * - Prefetch uses default locale\n * - Redirects prefetch to /en/about (assuming 'en' is default)\n *\n * When to use true:\n * - Your app uses non-localized internal links (e.g. <a href=\"/about\">)\n * - You want consistent locale detection behavior between regular and prefetch requests\n *\n * When to use false (default):\n * - Your app uses locale-prefixed links (e.g. <a href=\"/fr/about\">)\n * - You want to optimize prefetching performance\n * - You want to avoid potential redirect loops\n */\nconst DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX = false;\n\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { basePath, mode, rewrite, domains, enableProxy } = routing ?? {};\n\n// Resolved behaviour of the locale-routing proxy. `disabled` turns\n// `intlayerProxy` into a pass-through so apps can handle routing themselves.\n// The env var backing this is injected at build time so bundlers can tree-shake\n// the guarded branches.\nconst proxyMode = resolveProxyMode(enableProxy);\n\n// Next.js inlines NODE_ENV into every bundle, edge middleware included, so this\n// is both reliable and statically eliminable. `next build` is the only command\n// that injects `INTLAYER_ROUTING_ENABLE_PROXY`, meaning a dev server always\n// reaches `resolveProxyMode` through the configuration value.\n//\n// Matched against `development` rather than \"not production\" on purpose: only\n// `next dev` runs a dev server. Any other value (`test`, a custom staging env)\n// has no dev server in play and must keep the full production behaviour.\nconst isDevServer = process.env.NODE_ENV === 'development';\n\n// In auto mode, a dev server keeps locale routing URL-driven: the stored locale\n// is not used as a redirect source, so a stale cookie cannot keep pulling every\n// navigation to another locale while developing.\nconst canUseStorageLocale = isProxyStorageLocaleEnabled(proxyMode, isDevServer);\n\n// Announce the proxy the way the Vite plugin does on `configureServer`. Next\n// has no server-start hook for middleware, so this runs when the middleware\n// module is first evaluated — at the first request `next dev` routes through\n// it. Restricted to the dev server on purpose: in production this module is\n// re-evaluated on every edge cold start, and the line would be pure noise.\nif (isDevServer && proxyMode !== 'disabled') {\n getAppLogger({ log })(formatProxyEnabledMessage(!canUseStorageLocale), {\n level: 'info',\n });\n}\n\n// Note: cookie names are resolved inside LocaleStorage based on configuration\n\n// Derived flags from routing.mode\nconst effectiveMode = mode ?? ROUTING_MODE;\nconst noPrefix =\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix'\n ) &&\n effectiveMode === 'no-prefix') ||\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params');\nconst prefixDefault =\n !(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'prefix-all'\n ) && effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules =\n process.env.INTLAYER_ROUTING_REWRITE_RULES !== 'false'\n ? getRewriteRules(rewrite, 'url')\n : undefined;\n\n/**\n * Resolves the locale a localized (\"pretty\") path belongs to.\n *\n * A path such as `/a-propos` only exists because a rewrite rule maps it to the\n * French locale, so it declares its locale just as explicitly as an `/fr`\n * prefix would. Without this, a visitor whose `Accept-Language` (or stored\n * locale) says `en` gets `/a-propos` canonicalized against the English rules\n * only, which never matches — the proxy then treats it as an unlocalized path\n * and redirects to `/en/a-propos`, a URL no locale owns.\n *\n * Only patterns that differ from their canonical form are considered: a rule\n * whose localized path equals the canonical one (`en: '/about'`) carries no\n * locale signal, and matching on it would hijack the default locale's\n * unprefixed URLs.\n *\n * @param pathname - The request pathname, without any locale prefix.\n * @returns The locale declared by the path, or `undefined` when it declares none.\n */\nconst getRewriteLocale = (pathname: string): Locale | undefined =>\n rewriteRules\n ? (locales?.find(\n (candidate) =>\n getCanonicalPath(pathname, candidate as Locale, rewriteRules) !==\n pathname\n ) as Locale | undefined)\n : undefined;\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests are identified by:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js app-router prefetch)\n *\n * Note: `next-url` and `x-nextjs-data` are intentionally NOT used here.\n * Both are also sent on real client-side navigations (RSC navigation\n * requests and pages-router data requests respectively), so treating them\n * as prefetch would force such navigations to the default locale instead\n * of the user's stored locale.\n *\n * During prefetch, we should ignore cookie-based locale detection\n * to prevent unwanted redirects when users are switching locales.\n *\n * @param request - The incoming Next.js request object.\n * @returns - True if the request is a prefetch request, false otherwise.\n */\nconst isPrefetchRequest = (request: NextRequest): boolean => {\n const purpose = request.headers.get('purpose');\n const nextRouterPrefetch = request.headers.get('next-router-prefetch');\n\n return purpose === 'prefetch' || nextRouterPrefetch === '1';\n};\n\n// Ensure locale is reflected in search params when routing mode is 'search-params'\nconst appendLocaleSearchIfNeeded = (\n search: string | undefined,\n locale: Locale\n): string | undefined => {\n if (\n (process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params') ||\n effectiveMode !== 'search-params'\n )\n return search;\n const params = new URLSearchParams(search ?? '');\n params.set('locale', locale);\n return `?${params.toString()}`;\n};\n\n/**\n * Proxy that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/proxy.ts\n *\n * export { intlayerProxy as proxy } from '@intlayer/next/proxy';\n *\n * // applies this proxy only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main proxy function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n *\n */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n // When the proxy is disabled, pass the request through untouched.\n if (proxyMode === 'disabled') {\n return NextResponse.next();\n }\n\n const pathname = request.nextUrl.pathname;\n\n const localLocale = getLocalLocale(request);\n\n if (noPrefix) {\n return handleNoPrefix(request, localLocale, pathname);\n }\n\n const pathLocale = getPathLocale(pathname);\n\n // Domain routing: if the path locale is mapped to a different domain, redirect there.\n // e.g. intlayer.org/zh/about → https://intlayer.zh/about\n if (\n process.env.INTLAYER_ROUTING_DOMAINS !== 'false' &&\n pathLocale &&\n domains\n ) {\n const localeDomain = domains[pathLocale];\n\n if (localeDomain) {\n const domainHost = getDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = getDomainOrigin(localeDomain);\n\n return NextResponse.redirect(\n new URL(`${rawPath}${request.nextUrl.search}`, targetOrigin)\n );\n }\n }\n }\n\n // Domain routing: if the current hostname is exclusively mapped to one locale,\n // treat it as that locale's domain — no URL prefix needed.\n // e.g. intlayer.zh/about → internally rewrite to /zh/about\n if (process.env.INTLAYER_ROUTING_DOMAINS !== 'false' && !pathLocale) {\n const domainLocale = getLocaleFromDomain(\n request.nextUrl.hostname,\n domains as LocaleDomainMap\n );\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n\n // Never emit a trailing slash (`/zh/`): Next.js trailing-slash\n // normalisation would redirect it back and forth with this proxy.\n const internalPath = getInternalPath(canonicalPath, domainLocale);\n\n return rewriteUrl(\n request,\n internalPath + (request.nextUrl.search ?? ''),\n domainLocale\n );\n }\n }\n\n return handlePrefix(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\n *\n * Returns `undefined` when the stored locale is not allowed to drive locale\n * resolution (auto mode on a dev server), which makes every caller fall through\n * to `Accept-Language` detection and then the default locale.\n *\n * @param request - The incoming Next.js request object.\n * @returns - The locale found in the cookies, or undefined if not found or invalid.\n */\nconst getLocalLocale = (request: NextRequest): Locale | undefined => {\n if (!canUseStorageLocale) return undefined;\n\n return getLocaleFromStorageServer({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n getHeader: (name: string) => request.headers.get(name) ?? null,\n });\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n const pathLocale = getPathLocale(pathname);\n\n if (pathLocale) {\n const pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || '/';\n\n const canonicalPath = getCanonicalPath(\n pathWithoutLocale,\n pathLocale,\n rewriteRules\n );\n\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n const redirectPath = search\n ? `${canonicalPath}${search}`\n : `${canonicalPath}${request.nextUrl.search ?? ''}`;\n\n // Persist the explicitly-requested locale: stripping the prefix drops the\n // only locale signal from the URL, so without this the follow-up request\n // would fall back to cookie / Accept-Language detection and could resolve\n // a different locale.\n return redirectUrl(request, redirectPath, pathLocale);\n }\n\n if (\n !(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params'\n ) {\n const existingSearchParams = new URLSearchParams(request.nextUrl.search);\n const existingLocale = existingSearchParams.get('locale');\n\n const isExistingValid = locales?.includes(existingLocale as Locale);\n\n let locale = (localLocale ??\n (isExistingValid ? (existingLocale as Locale) : undefined) ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n const canonicalPath = getCanonicalPath(\n pathname,\n locale as Locale,\n rewriteRules\n );\n\n if (existingLocale === locale) {\n const internalPath = internalPrefix\n ? getInternalPath(canonicalPath, locale as Locale)\n : canonicalPath;\n const rewritePath = `${internalPath}${request.nextUrl.search ?? ''}`;\n return rewriteUrl(request, rewritePath, locale as Locale);\n }\n\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n locale as Locale\n );\n // Use original pathname for redirect to preserve user's URL input, just adding params\n const redirectPath = search\n ? `${pathname}${search}`\n : `${pathname}${request.nextUrl.search ?? ''}`;\n\n return redirectUrl(request, redirectPath);\n }\n\n // effectiveMode === 'no-prefix'\n let locale = (localLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n // Without a prefix, a localized path is the only locale signal the URL\n // carries, so it takes precedence over storage / `Accept-Language`.\n locale = getRewriteLocale(pathname) ?? locale;\n\n const canonicalPath = getCanonicalPath(\n pathname,\n locale as Locale,\n rewriteRules\n );\n\n const internalPath = internalPrefix\n ? getInternalPath(canonicalPath, locale as Locale)\n : canonicalPath;\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n locale as Locale\n );\n const rewritePath = search\n ? `${internalPath}${search}`\n : `${internalPath}${request.nextUrl.search ?? ''}`;\n\n return rewriteUrl(request, rewritePath, locale as Locale);\n};\n\n/**\n * Checks whether a pathname starts with the given locale as a full path\n * segment (`/fr` or `/fr/...`). A bare `startsWith('/fr')` would also match\n * unrelated paths like `/friends`, causing wrong prefix stripping and\n * self-redirect loops.\n *\n * @param pathname - The pathname to test.\n * @param locale - The locale to look for as the first path segment.\n * @returns - True if the first path segment is exactly the locale.\n */\nconst hasLocaleSegmentPrefix = (pathname: string, locale: Locale): boolean =>\n pathname === `/${locale}` || pathname.startsWith(`/${locale}/`);\n\n/**\n * Extracts the locale from the URL pathname if present.\n *\n * @param pathname - The pathname from the request URL.\n * @returns - The locale found in the pathname, or undefined if not found.\n */\nconst getPathLocale = (pathname: string): Locale | undefined =>\n (locales as Locale[] | undefined)?.find((locale) =>\n hasLocaleSegmentPrefix(pathname, locale)\n );\n\n/**\n * Handles the case where URLs have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handlePrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n if (!pathLocale) {\n const isPrefetch = isPrefetchRequest(request);\n if (isPrefetch && !DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX) {\n return handleMissingPathLocale(\n request,\n defaultLocale as Locale,\n pathname\n );\n }\n return handleMissingPathLocale(request, localLocale, pathname);\n }\n\n return handleExistingPathLocale(request, pathLocale, pathname);\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleMissingPathLocale = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n let locale = (localLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n\n if (!locales?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n // A localized path names its own locale, and the URL always outranks the\n // stored / negotiated one — otherwise /a-propos read as 'en' resolves to no\n // rule and gets redirected to the ownerless /en/a-propos.\n locale = getRewriteLocale(pathname) ?? locale;\n\n // Resolve to canonical path.\n // If user visits /a-propos (implied 'fr'), we resolve to /about\n const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);\n\n // Determine target localized path for redirection\n // /about + 'fr' -> /a-propos\n const { path: targetLocalizedPath } = resolveLocalizedPath(\n canonicalPath,\n locale,\n rewriteRules\n );\n\n const newPath = constructPath(\n locale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n // Never emit a trailing slash (`/en/` for canonicalPath `/`): Next.js\n // trailing-slash normalisation would redirect it back and forth with this\n // proxy. `getInternalPath` collapses the root path to `/${locale}`.\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(\n request,\n internalPrefix ? getInternalPath(canonicalPath, locale) : canonicalPath,\n locale\n ); // Rewrite must use Canonical\n};\n\n/**\n * Handles requests where the locale exists in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @returns - The response to be returned to the client.\n */\nconst handleExistingPathLocale = (\n request: NextRequest,\n pathLocale: Locale,\n pathname: string\n): NextResponse => {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n\n // 1. Identify the Canonical Path (Internal Next.js path)\n // Ex: /a-propos (from URL) -> /about (Canonical)\n const canonicalPath = getCanonicalPath(rawPath, pathLocale, rewriteRules);\n\n // By skipping the forced localLocale check, we allow the explicit pathLocale\n // to take precedence, which correctly updates the header/cookie when navigating.\n\n // Rewrite Logic\n // We must rewrite to the Next.js internal structure: /[locale]/[canonicalPath]\n // Ex: Rewrite /fr/a-propos -> /fr/about\n\n // 2. Redirect to localized path if needed (Canonical -> Localized)\n // Ex: /fr/about -> /fr/a-propos\n const { path: targetLocalizedPath, isRewritten } = resolveLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n\n if (isRewritten && targetLocalizedPath !== rawPath) {\n const newPath = constructPath(\n pathLocale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale)\n );\n return redirectUrl(request, newPath);\n }\n\n // Never emit a trailing slash (`/fr/` for the bare `/fr` URL): rewriting\n // `/fr` to `/fr/` makes Next.js issue a trailing-slash normalisation\n // redirect back to `/fr`, which this proxy rewrites again — an infinite\n // redirect loop. `getInternalPath` collapses the root path to `/${locale}`.\n const internalUrl = internalPrefix\n ? getInternalPath(canonicalPath, pathLocale)\n : canonicalPath;\n\n // Only handle redirect if we are strictly managing default locale prefixing\n // Fix: pass `canonicalPath` (the path *without* the locale prefix, e.g. /pricing)\n // instead of `pathname` (the full path including prefix, e.g. /en/pricing).\n // Previously this caused an infinite redirect loop in prefix-no-default mode\n // because handleDefaultLocaleRedirect built the redirect target from its third\n // argument, which reproduced the same URL on every response.\n if (!prefixDefault && pathLocale === defaultLocale) {\n return handleDefaultLocaleRedirect(request, pathLocale, canonicalPath);\n }\n\n const search = request.nextUrl.search;\n return rewriteUrl(request, internalUrl + (search ?? ''), pathLocale);\n};\n\n/**\n * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param pathname - The pathname from the request URL.\n * @param pathLocale - The locale extracted from the pathname.\n * @param localLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @returns - The new URL path with the correct locale.\n */\n// Function handleCookieLocaleMismatch was removed because the URL locale should take precedence over the stored locale.\n\n/**\n * The key fix for 404s without [locale] folders\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locale,\n canonicalPath: string // Internal path (e.g. /about)\n): NextResponse => {\n // Always called with !prefixDefault && pathLocale === defaultLocale (pre-validated by caller).\n // Redirect to strip the default-locale prefix from the URL.\n const { path: targetLocalizedPath } = resolveLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n\n const basePathValue = (basePath as string) || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n // Persist the explicitly-requested default locale. Stripping the prefix\n // (e.g. /es → /) drops the only locale signal from the URL, so without this\n // the follow-up request to the canonical path would fall back to\n // Accept-Language detection and could resolve a different locale (e.g. /en).\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? ''),\n pathLocale\n );\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n search?: string\n): string => {\n // Remove existing locale prefix from path if it was passed by mistake,\n // though we usually pass localized paths here now.\n const pathWithoutPrefix = hasLocaleSegmentPrefix(path, locale)\n ? path.slice(`/${locale}`.length) || '/'\n : path;\n\n if (\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'no-prefix'\n ) &&\n effectiveMode === 'no-prefix') ||\n (!(\n process.env.INTLAYER_ROUTING_MODE &&\n process.env.INTLAYER_ROUTING_MODE !== 'search-params'\n ) &&\n effectiveMode === 'search-params')\n ) {\n // `search` is either undefined or already has a leading '?' (from\n // appendLocaleSearchIfNeeded / request.nextUrl.search), so append as-is.\n return `${pathWithoutPrefix}${search ?? ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = hasLocaleSegmentPrefix(path, locale)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathValue = basePath || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n const newPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n // Never emit a trailing slash (`/fr/` for the root path): the framework's\n // trailing-slash normalisation would redirect it back and forth with this\n // proxy, creating an infinite redirect loop.\n return cleanPath !== '/' && cleanPath.endsWith('/')\n ? cleanPath.slice(0, -1)\n : cleanPath;\n};\n\n/**\n * This handles the internal path Next.js sees.\n * To support optional [locale] folders, we need to decide if we\n * keep the locale prefix or strip it.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locale\n): NextResponse => {\n const search = request.nextUrl.search;\n\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @param persistLocale - When provided, the locale is written to storage\n * (cookie/header, per config) on the redirect response so the follow-up\n * request resolves the same locale instead of re-running detection.\n * @returns - The redirect response.\n */\nconst redirectUrl = (\n request: NextRequest,\n newPath: string,\n persistLocale?: Locale\n): NextResponse => {\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.hash}`,\n request.url\n );\n\n const response = NextResponse.redirect(safeTarget);\n\n if (persistLocale) {\n persistLocaleOnResponse(response, persistLocale);\n }\n\n return response;\n};\n\n/**\n * Writes the resolved locale to the outgoing response's storage (cookie and/or\n * header, according to `routing.storage`). Only the cookie survives a client\n * redirect, so this is what carries an explicitly-selected locale across a\n * prefix-stripping redirect. Enabled cookie/header targets are resolved by\n * {@link setLocaleInStorageServer} from the config; disabled ones are no-ops.\n *\n * @param response - The outgoing Next.js response to attach storage to.\n * @param locale - The locale to persist.\n */\nconst persistLocaleOnResponse = (\n response: NextResponse,\n locale: Locale\n): void => {\n setLocaleInStorageServer(locale, {\n setCookieStore: (name, value, attributes) => {\n response.cookies.set(name, value, {\n path: attributes.path,\n domain: attributes.domain,\n expires:\n typeof attributes.expires === 'number'\n ? new Date(attributes.expires)\n : attributes.expires,\n secure: attributes.secure,\n sameSite: attributes.sameSite,\n httpOnly: attributes.httpOnly,\n });\n },\n setHeader: (name, value) => {\n response.headers.set(name, value);\n },\n });\n};\n"],"mappings":";;;;;;;;;;AA2DA,MAAM,EAAE,SAAS,kBAAkBA,+CAAwB,CAAC;AAC5D,MAAM,EAAE,UAAU,MAAM,SAAS,SAAS,gBAAgBC,kCAAW,CAAC;AAMtE,MAAM,gBAAYC,8CAAiB,WAAW;AAU9C,MAAM,cAAc,QAAQ,IAAI,aAAa;AAK7C,MAAM,0BAAsBC,yDAA4B,WAAW,WAAW;AAO9E,IAAI,eAAe,cAAc,YAC/B,0CAAa,EAAE,gCAAI,CAAC,CAAC,KAACC,uDAA0B,CAAC,mBAAmB,GAAG,EACrE,OAAO,OACT,CAAC;AAMH,MAAM,gBAAgB,QAAQC;AAC9B,MAAM,WACH,EACC,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,gBAEtC,kBAAkB,eACnB,EACC,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,oBAEtC,kBAAkB;AACtB,MAAM,gBACJ,EACE,QAAQ,IAAI,yBACZ,QAAQ,IAAI,0BAA0B,iBACnC,kBAAkB;AAEzB,MAAM,iBAAiB,CAAC;AAExB,MAAM,eACJ,QAAQ,IAAI,mCAAmC,cAC3CC,6CAAgB,SAAS,KAAK,IAC9B;;;;;;;;;;;;;;;;;;;AAoBN,MAAM,oBAAoB,aACxB,eACK,SAAS,MACP,kBACCC,8CAAiB,UAAU,WAAqB,YAAY,MAC5D,QACJ,IACA;;;;;;;;;;;;;;;;;;;;AAqBN,MAAM,qBAAqB,YAAkC;CAC3D,MAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;CAC7C,MAAM,qBAAqB,QAAQ,QAAQ,IAAI,sBAAsB;CAErE,OAAO,YAAY,cAAc,uBAAuB;AAC1D;AAGA,MAAM,8BACJ,QACA,WACuB;CACvB,IACG,QAAQ,IAAI,yBACX,QAAQ,IAAI,0BAA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U,WAAW;CAE7D,MAAM,SAAS,IAAI,IAAI,gBAAgB,QAAQ,GAAG;CAIlD,MAAM,aACJ,OAAO,WAAW,QAAQ,QAAQ,SAC9B,SACA,IAAI,IACF,GAAG,OAAO,WAAW,OAAO,SAAS,OAAO,QAC5C,QAAQ,GACV;CAEN,MAAM,WAAWA,yBAAa,SAAS,UAAU;CAEjD,IAAI,eACF,wBAAwB,UAAU,aAAa;CAGjD,OAAO;AACT;;;;;;;;;;;AAYA,MAAM,2BACJ,UACA,WACS;CACT,mDAAyB,QAAQ;EAC/B,iBAAiB,MAAM,OAAO,eAAe;GAC3C,SAAS,QAAQ,IAAI,MAAM,OAAO;IAChC,MAAM,WAAW;IACjB,QAAQ,WAAW;IACnB,SACE,OAAO,WAAW,YAAY,WAC1B,IAAI,KAAK,WAAW,OAAO,IAC3B,WAAW;IACjB,QAAQ,WAAW;IACnB,UAAU,WAAW;IACrB,UAAU,WAAW;GACvB,CAAC;EACH;EACA,YAAY,MAAM,UAAU;GAC1B,SAAS,QAAQ,IAAI,MAAM,KAAK;EAClC;CACF,CAAC;AACH"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_client_IntlayerClientProvider = require('../client/IntlayerClientProvider.cjs');
|
|
3
|
+
const require_client_usePathname = require('../client/usePathname.cjs');
|
|
4
|
+
const require_client_useLocalePageRouter = require('../client/useLocalePageRouter.cjs');
|
|
5
|
+
const require_generateStaticParams = require('../generateStaticParams.cjs');
|
|
6
|
+
const require_server_IntlayerProvider = require('../server/IntlayerProvider.cjs');
|
|
7
|
+
const require_server_t = require('../server/t.cjs');
|
|
8
|
+
const require_server_useDictionary = require('../server/useDictionary.cjs');
|
|
9
|
+
const require_server_useDictionaryAsync = require('../server/useDictionaryAsync.cjs');
|
|
10
|
+
const require_server_useDictionaryDynamic = require('../server/useDictionaryDynamic.cjs');
|
|
11
|
+
const require_server_useI18n = require('../server/useI18n.cjs');
|
|
12
|
+
const require_server_useIntl = require('../server/useIntl.cjs');
|
|
13
|
+
const require_server_useIntlayer = require('../server/useIntlayer.cjs');
|
|
14
|
+
const require_server_useLocale = require('../server/useLocale.cjs');
|
|
15
|
+
let react_intlayer = require("react-intlayer");
|
|
16
|
+
let react_intlayer_server = require("react-intlayer/server");
|
|
17
|
+
|
|
18
|
+
Object.defineProperty(exports, 'IntlayerClientContext', {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return react_intlayer.IntlayerClientContext;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
exports.IntlayerClientProvider = require_client_IntlayerClientProvider.IntlayerClientProvider;
|
|
25
|
+
exports.IntlayerProvider = require_server_IntlayerProvider.IntlayerProvider;
|
|
26
|
+
exports.generateStaticParams = require_generateStaticParams.generateStaticParams;
|
|
27
|
+
Object.defineProperty(exports, 'getDictionary', {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return react_intlayer.getDictionary;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, 'getIntlayer', {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () {
|
|
36
|
+
return react_intlayer.getIntlayer;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, 'localeCookie', {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return react_intlayer.localeCookie;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, 'localeInStorage', {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () {
|
|
48
|
+
return react_intlayer.localeInStorage;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, 'setLocaleCookie', {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return react_intlayer.setLocaleCookie;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(exports, 'setLocaleInStorage', {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () {
|
|
60
|
+
return react_intlayer.setLocaleInStorage;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
exports.t = require_server_t.t;
|
|
64
|
+
exports.useDictionary = require_server_useDictionary.useDictionary;
|
|
65
|
+
exports.useDictionaryAsync = require_server_useDictionaryAsync.useDictionaryAsync;
|
|
66
|
+
exports.useDictionaryDynamic = require_server_useDictionaryDynamic.useDictionaryDynamic;
|
|
67
|
+
exports.useI18n = require_server_useI18n.useI18n;
|
|
68
|
+
exports.useIntl = require_server_useIntl.useIntl;
|
|
69
|
+
exports.useIntlayer = require_server_useIntlayer.useIntlayer;
|
|
70
|
+
Object.defineProperty(exports, 'useLoadDynamic', {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return react_intlayer_server.useLoadDynamic;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
exports.useLocale = require_server_useLocale.useLocale;
|
|
77
|
+
Object.defineProperty(exports, 'useLocaleCookie', {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return react_intlayer.useLocaleCookie;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
exports.useLocalePageRouter = require_client_useLocalePageRouter.useLocalePageRouter;
|
|
84
|
+
Object.defineProperty(exports, 'useLocaleStorage', {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return react_intlayer.useLocaleStorage;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
exports.usePathname = require_client_usePathname.usePathname;
|
|
91
|
+
Object.defineProperty(exports, 'useRewriteURL', {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return react_intlayer.useRewriteURL;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_client_IntlayerClientProvider = require('../client/IntlayerClientProvider.cjs');
|
|
3
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
|
+
let react_intlayer_server = require("react-intlayer/server");
|
|
5
|
+
|
|
6
|
+
//#region src/server/IntlayerProvider.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Unified Intlayer provider for the Next.js App Router.
|
|
9
|
+
*
|
|
10
|
+
* Server component that seeds the request-scoped server context (locale and
|
|
11
|
+
* ambient variant) read by the server hooks, and mounts the client provider so
|
|
12
|
+
* client components receive the same values — one provider for both halves.
|
|
13
|
+
*
|
|
14
|
+
* Mount it once, in the locale layout:
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { IntlayerProvider } from 'next-intlayer/server';
|
|
18
|
+
*
|
|
19
|
+
* const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {
|
|
20
|
+
* const { locale } = await params;
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <IntlayerProvider locale={locale}>
|
|
24
|
+
* <html lang={locale}>
|
|
25
|
+
* <body>{children}</body>
|
|
26
|
+
* </html>
|
|
27
|
+
* </IntlayerProvider>
|
|
28
|
+
* );
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* The server context is request-scoped, not tree-scoped: on client-side
|
|
33
|
+
* navigations that only re-render the page segment, the layout — and with it
|
|
34
|
+
* this provider — does not re-run. The server hooks then fall back to the
|
|
35
|
+
* locale carried by the request (the `x-intlayer-locale` header set by the
|
|
36
|
+
* intlayer proxy, then the locale cookie), so content stays correct without a
|
|
37
|
+
* per-page provider. The ambient `variant` has no request-carried fallback:
|
|
38
|
+
* seed it per request with `setVariant` when server components read it outside
|
|
39
|
+
* a full render of this provider.
|
|
40
|
+
*/
|
|
41
|
+
const IntlayerProvider = ({ children, locale, variant, ...clientProps }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_intlayer_server.IntlayerServerProvider, {
|
|
42
|
+
locale,
|
|
43
|
+
variant,
|
|
44
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_client_IntlayerClientProvider.IntlayerClientProvider, {
|
|
45
|
+
locale,
|
|
46
|
+
variant,
|
|
47
|
+
...clientProps,
|
|
48
|
+
children
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
exports.IntlayerProvider = IntlayerProvider;
|
|
54
|
+
//# sourceMappingURL=IntlayerProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["IntlayerServerProvider","IntlayerClientProvider"],"sources":["../../../src/server/IntlayerProvider.tsx"],"sourcesContent":["import type { FC } from 'react';\nimport {\n IntlayerServerProvider,\n type IntlayerServerProviderProps,\n} from 'react-intlayer/server';\nimport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from '../client/IntlayerClientProvider';\n\nexport type IntlayerProviderProps = IntlayerClientProviderProps &\n IntlayerServerProviderProps;\n\n/**\n * Unified Intlayer provider for the Next.js App Router.\n *\n * Server component that seeds the request-scoped server context (locale and\n * ambient variant) read by the server hooks, and mounts the client provider so\n * client components receive the same values — one provider for both halves.\n *\n * Mount it once, in the locale layout:\n *\n * ```tsx\n * import { IntlayerProvider } from 'next-intlayer/server';\n *\n * const LocaleLayout: NextLayoutIntlayer = async ({ children, params }) => {\n * const { locale } = await params;\n *\n * return (\n * <IntlayerProvider locale={locale}>\n * <html lang={locale}>\n * <body>{children}</body>\n * </html>\n * </IntlayerProvider>\n * );\n * };\n * ```\n *\n * The server context is request-scoped, not tree-scoped: on client-side\n * navigations that only re-render the page segment, the layout — and with it\n * this provider — does not re-run. The server hooks then fall back to the\n * locale carried by the request (the `x-intlayer-locale` header set by the\n * intlayer proxy, then the locale cookie), so content stays correct without a\n * per-page provider. The ambient `variant` has no request-carried fallback:\n * seed it per request with `setVariant` when server components read it outside\n * a full render of this provider.\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n locale,\n variant,\n ...clientProps\n}) => (\n <IntlayerServerProvider locale={locale} variant={variant}>\n <IntlayerClientProvider locale={locale} variant={variant} {...clientProps}>\n {children}\n </IntlayerClientProvider>\n </IntlayerServerProvider>\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,oBAA+C,EAC1D,UACA,QACA,SACA,GAAG,kBAEH,2CAACA,8CAAD;CAAgC;CAAiB;WAC/C,2CAACC,8DAAD;EAAgC;EAAiB;EAAS,GAAI;EAC3D;CACqB;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let react_intlayer_server = require("react-intlayer/server");
|
|
3
|
+
|
|
4
|
+
//#region src/server/IntlayerServerProvider.ts
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Mount `IntlayerProvider` from `next-intlayer/server` once in the
|
|
7
|
+
* locale layout instead — it seeds both the server context and the client
|
|
8
|
+
* provider, and the server hooks fall back to the locale carried by the
|
|
9
|
+
* request when the layout is skipped on client-side navigations. For a page
|
|
10
|
+
* that must seed the locale itself (statically rendered routes on
|
|
11
|
+
* Next.js < 16), use the imperative `setLocale` instead of wrapping the tree.
|
|
12
|
+
*/
|
|
13
|
+
const IntlayerServerProvider = react_intlayer_server.IntlayerServerProvider;
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.IntlayerServerProvider = IntlayerServerProvider;
|
|
17
|
+
//# sourceMappingURL=IntlayerServerProvider.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.cjs","names":["IntlayerServerProviderBase"],"sources":["../../../src/server/IntlayerServerProvider.ts"],"sourcesContent":["import { IntlayerServerProvider as IntlayerServerProviderBase } from 'react-intlayer/server';\n\n/**\n * @deprecated Mount `IntlayerProvider` from `next-intlayer/server` once in the\n * locale layout instead — it seeds both the server context and the client\n * provider, and the server hooks fall back to the locale carried by the\n * request when the layout is skipped on client-side navigations. For a page\n * that must seed the locale itself (statically rendered routes on\n * Next.js < 16), use the imperative `setLocale` instead of wrapping the tree.\n */\nexport const IntlayerServerProvider = IntlayerServerProviderBase;\n"],"mappings":";;;;;;;;;;;;AAUA,MAAa,yBAAyBA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_server_getLocale = require('./getLocale.cjs');
|
|
3
|
+
const require_server_suspendingReader = require('./suspendingReader.cjs');
|
|
4
|
+
let react_intlayer_server = require("react-intlayer/server");
|
|
5
|
+
|
|
6
|
+
//#region src/server/ambientLocale.ts
|
|
7
|
+
/**
|
|
8
|
+
* Whether the call site already carries a locale — either a plain locale
|
|
9
|
+
* argument or a selector object with an explicit `locale` field.
|
|
10
|
+
*/
|
|
11
|
+
const hasExplicitLocale = (localeOrSelector) => typeof localeOrSelector === "string" || typeof localeOrSelector === "object" && localeOrSelector !== null && Boolean(localeOrSelector.locale);
|
|
12
|
+
/**
|
|
13
|
+
* Whether the request-derived locale is worth reading at all.
|
|
14
|
+
*
|
|
15
|
+
* The base hooks in `react-intlayer/server` already prefer, in order, the
|
|
16
|
+
* locale passed at the call site and the request-scoped server context seeded
|
|
17
|
+
* by `IntlayerProvider`; they only fall back to the third argument these
|
|
18
|
+
* helpers produce. Reading request storage means calling `headers()` /
|
|
19
|
+
* `cookies()`, which opts the route into dynamic rendering — so it must stay
|
|
20
|
+
* behind both of those, and never run when either already answers.
|
|
21
|
+
*/
|
|
22
|
+
const needsRequestLocale = (localeOrSelector) => !hasExplicitLocale(localeOrSelector) && !(0, react_intlayer_server.getServerContext)(react_intlayer_server.IntlayerServer);
|
|
23
|
+
/**
|
|
24
|
+
* Reads the locale carried by the request: the `x-intlayer-locale` header set
|
|
25
|
+
* by the intlayer proxy, then the locale cookie, then `accept-language`.
|
|
26
|
+
*
|
|
27
|
+
* Errors are not swallowed — during prerendering Next.js relies on the throw
|
|
28
|
+
* from `headers()` to mark the route dynamic.
|
|
29
|
+
*/
|
|
30
|
+
const readStoredLocale = require_server_suspendingReader.createSuspendingReader(require_server_getLocale.getLocale);
|
|
31
|
+
/**
|
|
32
|
+
* Fallback locale for the synchronous server hooks, so a page does not need a
|
|
33
|
+
* provider of its own. Not a React hook despite suspending — it holds no
|
|
34
|
+
* positional state, which is what lets it run conditionally (see
|
|
35
|
+
* {@link createSuspendingReader}): on a client-side navigation that re-renders only the
|
|
36
|
+
* page segment, the layout — and with it `IntlayerProvider` — does not re-run,
|
|
37
|
+
* and the locale carried by the request takes over.
|
|
38
|
+
*
|
|
39
|
+
* Suspends until the request storage resolves. Returns `undefined` when the
|
|
40
|
+
* call site or the server context already carries the locale.
|
|
41
|
+
*/
|
|
42
|
+
const resolveFallbackLocale = (localeOrSelector) => needsRequestLocale(localeOrSelector) ? readStoredLocale() : void 0;
|
|
43
|
+
/**
|
|
44
|
+
* Asynchronous twin of {@link resolveFallbackLocale}, for the hooks that are
|
|
45
|
+
* already async and can await the request storage instead of suspending on it.
|
|
46
|
+
*/
|
|
47
|
+
const getFallbackLocale = async (localeOrSelector) => needsRequestLocale(localeOrSelector) ? await require_server_getLocale.getLocale() : void 0;
|
|
48
|
+
/**
|
|
49
|
+
* Full ambient locale for the server APIs that take a plain locale argument
|
|
50
|
+
* (or none at all): call site → server context → locale carried by the
|
|
51
|
+
* request.
|
|
52
|
+
*
|
|
53
|
+
* {@link resolveFallbackLocale} only yields the last rung, because the base hooks
|
|
54
|
+
* in `react-intlayer/server` consult the first two themselves. The APIs
|
|
55
|
+
* reimplemented here have no such fallback slot, so they need the resolved
|
|
56
|
+
* value.
|
|
57
|
+
*/
|
|
58
|
+
const resolveAmbientLocale = (locale) => locale ?? (0, react_intlayer_server.getServerContext)(react_intlayer_server.IntlayerServer) ?? resolveFallbackLocale(locale);
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
exports.getFallbackLocale = getFallbackLocale;
|
|
62
|
+
exports.resolveAmbientLocale = resolveAmbientLocale;
|
|
63
|
+
exports.resolveFallbackLocale = resolveFallbackLocale;
|
|
64
|
+
//# sourceMappingURL=ambientLocale.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambientLocale.cjs","names":["getServerContext","IntlayerServer","createSuspendingReader","getLocale"],"sources":["../../../src/server/ambientLocale.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getServerContext, IntlayerServer } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\nimport { createSuspendingReader } from './suspendingReader';\n\n/**\n * Whether the call site already carries a locale — either a plain locale\n * argument or a selector object with an explicit `locale` field.\n */\nconst hasExplicitLocale = (localeOrSelector?: unknown): boolean =>\n typeof localeOrSelector === 'string' ||\n (typeof localeOrSelector === 'object' &&\n localeOrSelector !== null &&\n Boolean((localeOrSelector as { locale?: unknown }).locale));\n\n/**\n * Whether the request-derived locale is worth reading at all.\n *\n * The base hooks in `react-intlayer/server` already prefer, in order, the\n * locale passed at the call site and the request-scoped server context seeded\n * by `IntlayerProvider`; they only fall back to the third argument these\n * helpers produce. Reading request storage means calling `headers()` /\n * `cookies()`, which opts the route into dynamic rendering — so it must stay\n * behind both of those, and never run when either already answers.\n */\nconst needsRequestLocale = (localeOrSelector?: unknown): boolean =>\n !hasExplicitLocale(localeOrSelector) && !getServerContext(IntlayerServer);\n\n/**\n * Reads the locale carried by the request: the `x-intlayer-locale` header set\n * by the intlayer proxy, then the locale cookie, then `accept-language`.\n *\n * Errors are not swallowed — during prerendering Next.js relies on the throw\n * from `headers()` to mark the route dynamic.\n */\nconst readStoredLocale = createSuspendingReader<Locale>(getLocale);\n\n/**\n * Fallback locale for the synchronous server hooks, so a page does not need a\n * provider of its own. Not a React hook despite suspending — it holds no\n * positional state, which is what lets it run conditionally (see\n * {@link createSuspendingReader}): on a client-side navigation that re-renders only the\n * page segment, the layout — and with it `IntlayerProvider` — does not re-run,\n * and the locale carried by the request takes over.\n *\n * Suspends until the request storage resolves. Returns `undefined` when the\n * call site or the server context already carries the locale.\n */\nexport const resolveFallbackLocale = (\n localeOrSelector?: unknown\n): Locale | undefined =>\n needsRequestLocale(localeOrSelector) ? readStoredLocale() : undefined;\n\n/**\n * Asynchronous twin of {@link resolveFallbackLocale}, for the hooks that are\n * already async and can await the request storage instead of suspending on it.\n */\nexport const getFallbackLocale = async (\n localeOrSelector?: unknown\n): Promise<Locale | undefined> =>\n needsRequestLocale(localeOrSelector) ? await getLocale() : undefined;\n\n/**\n * Full ambient locale for the server APIs that take a plain locale argument\n * (or none at all): call site → server context → locale carried by the\n * request.\n *\n * {@link resolveFallbackLocale} only yields the last rung, because the base hooks\n * in `react-intlayer/server` consult the first two themselves. The APIs\n * reimplemented here have no such fallback slot, so they need the resolved\n * value.\n */\nexport const resolveAmbientLocale = (\n locale?: LocalesValues\n): LocalesValues | undefined =>\n locale ??\n getServerContext<LocalesValues>(IntlayerServer) ??\n resolveFallbackLocale(locale);\n"],"mappings":";;;;;;;;;;AAUA,MAAM,qBAAqB,qBACzB,OAAO,qBAAqB,YAC3B,OAAO,qBAAqB,YAC3B,qBAAqB,QACrB,QAAS,iBAA0C,MAAM;;;;;;;;;;;AAY7D,MAAM,sBAAsB,qBAC1B,CAAC,kBAAkB,gBAAgB,KAAK,KAACA,wCAAiBC,oCAAc;;;;;;;;AAS1E,MAAM,mBAAmBC,uDAA+BC,kCAAS;;;;;;;;;;;;AAajE,MAAa,yBACX,qBAEA,mBAAmB,gBAAgB,IAAI,iBAAiB,IAAI;;;;;AAM9D,MAAa,oBAAoB,OAC/B,qBAEA,mBAAmB,gBAAgB,IAAI,MAAMA,mCAAU,IAAI;;;;;;;;;;;AAY7D,MAAa,wBACX,WAEA,cACAH,wCAAgCC,oCAAc,KAC9C,sBAAsB,MAAM"}
|