next-intlayer 8.4.4 → 8.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/cjs/client/IntlayerClientProvider.cjs +36 -1
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +9 -1
- package/dist/cjs/client/index.cjs +16 -1
- package/dist/cjs/client/useLocale.cjs +71 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs +45 -1
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +12 -1
- package/dist/cjs/generateStaticParams.cjs +29 -1
- package/dist/cjs/generateStaticParams.cjs.map +1 -1
- package/dist/cjs/index.cjs +132 -1
- package/dist/cjs/proxy/index.cjs +8 -1
- package/dist/cjs/proxy/intlayerProxy.cjs +249 -1
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/proxy/localeDetector.cjs +20 -1
- package/dist/cjs/proxy/localeDetector.cjs.map +1 -1
- package/dist/cjs/proxy/middleware.cjs +37 -1
- package/dist/cjs/proxy/middleware.cjs.map +1 -1
- package/dist/cjs/proxy/multipleProxies.cjs +57 -1
- package/dist/cjs/proxy/multipleProxies.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +9 -1
- package/dist/cjs/server/getLocale.cjs +48 -1
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +75 -1
- package/dist/cjs/server/useDictionary.cjs +17 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +17 -1
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +17 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +29 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +258 -1
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +34 -1
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -1
- package/dist/esm/client/index.mjs +6 -1
- package/dist/esm/client/useLocale.mjs +69 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocalePageRouter.mjs +43 -1
- package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +5 -1
- package/dist/esm/generateStaticParams.mjs +26 -1
- package/dist/esm/generateStaticParams.mjs.map +1 -1
- package/dist/esm/index.mjs +8 -1
- package/dist/esm/proxy/index.mjs +5 -1
- package/dist/esm/proxy/intlayerProxy.mjs +246 -1
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/proxy/localeDetector.mjs +18 -1
- package/dist/esm/proxy/localeDetector.mjs.map +1 -1
- package/dist/esm/proxy/middleware.mjs +35 -1
- package/dist/esm/proxy/middleware.mjs.map +1 -1
- package/dist/esm/proxy/multipleProxies.mjs +55 -1
- package/dist/esm/proxy/multipleProxies.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -1
- package/dist/esm/server/getLocale.mjs +45 -1
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/index.mjs +5 -1
- package/dist/esm/server/useDictionary.mjs +15 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +15 -1
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +15 -1
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +25 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/withIntlayer.mjs +253 -1
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"react-intlayer/format"
|
|
1
|
+
export * from "react-intlayer/format"
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientProvider } from "./IntlayerClientProvider.mjs";
|
|
2
|
+
import { useLocale } from "./useLocale.mjs";
|
|
3
|
+
import { useLocalePageRouter } from "./useLocalePageRouter.mjs";
|
|
4
|
+
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
5
|
+
|
|
6
|
+
export { IntlayerClientProvider, useLocale, useLocalePageRouter, useRewriteURL };
|
|
@@ -1,2 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useLocale as useLocale$1 } from "react-intlayer";
|
|
4
|
+
import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core/localization";
|
|
5
|
+
import { usePathname, useRouter } from "next/navigation.js";
|
|
6
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/client/useLocale.ts
|
|
9
|
+
const usePathWithoutLocale = () => {
|
|
10
|
+
const pathname = usePathname();
|
|
11
|
+
const [fullPath, setFullPath] = useState(pathname);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const search = typeof window !== "undefined" ? window.location.search : "";
|
|
14
|
+
setFullPath(search ? `${pathname}${search}` : pathname);
|
|
15
|
+
}, [pathname]);
|
|
16
|
+
return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Hook to manage the current locale in Next.js App Router.
|
|
20
|
+
*
|
|
21
|
+
* This hook extends the base `useLocale` from `react-intlayer` by adding
|
|
22
|
+
* Next.js-specific navigation logic for locale changes.
|
|
23
|
+
*
|
|
24
|
+
* @param props - Optional properties to configure locale change behavior.
|
|
25
|
+
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* 'use client';
|
|
30
|
+
*
|
|
31
|
+
* import { useLocale } from 'next-intlayer';
|
|
32
|
+
*
|
|
33
|
+
* const LocaleSwitcher = () => {
|
|
34
|
+
* const { setLocale } = useLocale({ onChange: 'push' });
|
|
35
|
+
*
|
|
36
|
+
* return (
|
|
37
|
+
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
38
|
+
* );
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
const useLocale = ({ onChange = "replace" } = {}) => {
|
|
43
|
+
const { replace, push } = useRouter();
|
|
44
|
+
const pathWithoutLocale = usePathWithoutLocale();
|
|
45
|
+
return {
|
|
46
|
+
...useLocale$1({ onLocaleChange: useCallback((locale) => {
|
|
47
|
+
if (!onChange) return;
|
|
48
|
+
const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
|
|
49
|
+
if (typeof onChange === "function") {
|
|
50
|
+
onChange({
|
|
51
|
+
locale,
|
|
52
|
+
path: pathWithLocale
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (onChange === "replace") replace(pathWithLocale);
|
|
57
|
+
if (onChange === "push") push(pathWithLocale);
|
|
58
|
+
}, [
|
|
59
|
+
replace,
|
|
60
|
+
push,
|
|
61
|
+
pathWithoutLocale,
|
|
62
|
+
onChange
|
|
63
|
+
]) }),
|
|
64
|
+
pathWithoutLocale
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { useLocale };
|
|
2
70
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?:\n | 'replace'\n | 'push'\n | 'none'\n | ((params: { locale: DeclaredLocales; path: string }) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\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 = ({ onChange = 'replace' }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: DeclaredLocales) => {\n if (!onChange) return;\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (typeof onChange === 'function') {\n onChange({ locale, path: pathWithLocale });\n return;\n }\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?:\n | 'replace'\n | 'push'\n | 'none'\n | ((params: { locale: DeclaredLocales; path: string }) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\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 = ({ onChange = 'replace' }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: DeclaredLocales) => {\n if (!onChange) return;\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (typeof onChange === 'function') {\n onChange({ locale, path: pathWithLocale });\n return;\n }\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;AAmBA,MAAM,6BAA6B;CACjC,MAAM,WAAW,aAAa;CAC9B,MAAM,CAAC,UAAU,eAAe,SAAS,SAAS;AAElD,iBAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,QAAO,cAAc,qBAAqB,SAAS,EAAE,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BlE,MAAa,aAAa,EAAE,WAAW,cAA8B,EAAE,KAAK;CAC1E,MAAM,EAAE,SAAS,SAAS,WAAW;CACrC,MAAM,oBAAoB,sBAAsB;AA2BhD,QAAO;EACL,GALsBA,YAAe,EACrC,gBAtB0B,aACzB,WAA4B;AAC3B,OAAI,CAAC,SAAU;GAEf,MAAM,iBAAiB,gBAAgB,mBAAmB,OAAO;AAEjE,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS;KAAE;KAAQ,MAAM;KAAgB,CAAC;AAC1C;;AAGF,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAC7C,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useLocale } from "react-intlayer";
|
|
4
|
+
import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core/localization";
|
|
5
|
+
import { useCallback, useMemo } from "react";
|
|
6
|
+
import { useRouter } from "next/router.js";
|
|
7
|
+
|
|
8
|
+
//#region src/client/useLocalePageRouter.ts
|
|
9
|
+
/**
|
|
10
|
+
* Hook to manage the current locale in Next.js Page Router.
|
|
11
|
+
*
|
|
12
|
+
* This hook provides locale management functionality tailored for the Next.js Page Router,
|
|
13
|
+
* handling redirections and page reloads upon locale changes.
|
|
14
|
+
*
|
|
15
|
+
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useLocalePageRouter } from 'next-intlayer';
|
|
20
|
+
*
|
|
21
|
+
* const MyComponent = () => {
|
|
22
|
+
* const { setLocale } = useLocalePageRouter();
|
|
23
|
+
*
|
|
24
|
+
* return (
|
|
25
|
+
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
26
|
+
* );
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const useLocalePageRouter = () => {
|
|
31
|
+
const { push, pathname, reload } = useRouter();
|
|
32
|
+
const pathWithoutLocale = useMemo(() => getPathWithoutLocale(pathname), [pathname]);
|
|
33
|
+
return {
|
|
34
|
+
...useLocale({ onLocaleChange: useCallback((locale) => {
|
|
35
|
+
push(getLocalizedUrl(pathWithoutLocale, locale));
|
|
36
|
+
return reload();
|
|
37
|
+
}, [pathWithoutLocale]) }),
|
|
38
|
+
pathWithoutLocale
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { useLocalePageRouter };
|
|
2
44
|
//# sourceMappingURL=useLocalePageRouter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\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 const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\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 const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,WAAW,WAAW;CAC9C,MAAM,oBAAoB,cAClB,qBAAqB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,GALsBA,UAAe,EACrC,gBAZ0B,aACzB,WAA0B;AAGzB,QAFuB,gBAAgB,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import configuration from "@intlayer/config/built";
|
|
2
|
+
|
|
3
|
+
//#region src/generateStaticParams.ts
|
|
4
|
+
const { locales } = configuration.internationalization;
|
|
5
|
+
/**
|
|
6
|
+
* Generates static parameters for Next.js's dynamic routes based on the configured locales.
|
|
7
|
+
*
|
|
8
|
+
* This function is typically used in Next.js App Router for `generateStaticParams`
|
|
9
|
+
* to ensure all supported locales are pre-rendered at build time.
|
|
10
|
+
*
|
|
11
|
+
* @returns An array of objects containing the `locale` parameter for each configured locale.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```tsx
|
|
15
|
+
* // app/[locale]/layout.tsx
|
|
16
|
+
* export { generateStaticParams } from 'next-intlayer';
|
|
17
|
+
*
|
|
18
|
+
* export default async function RootLayout({ children, params }) {
|
|
19
|
+
* // ...
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { generateStaticParams };
|
|
2
27
|
//# sourceMappingURL=generateStaticParams.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.mjs","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateStaticParams.mjs","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;AAEA,MAAM,EAAE,YAAY,cAAc;;;;;;;;;;;;;;;;;;;AAoBlC,MAAa,6BAA6B,QAAQ,KAAK,YAAY,EAAE,QAAQ,EAAE"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { IntlayerClientProvider } from "./client/IntlayerClientProvider.mjs";
|
|
2
|
+
import { useLocale } from "./client/useLocale.mjs";
|
|
3
|
+
import { useLocalePageRouter } from "./client/useLocalePageRouter.mjs";
|
|
4
|
+
import { useRewriteURL } from "./client/useRewriteURL.mjs";
|
|
5
|
+
import { generateStaticParams } from "./generateStaticParams.mjs";
|
|
6
|
+
import { IntlayerClientContext, MarkdownProvider, MarkdownRenderer, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocaleCookie, useLocaleStorage } from "react-intlayer";
|
|
7
|
+
|
|
8
|
+
export { IntlayerClientContext, IntlayerClientProvider, MarkdownProvider, MarkdownRenderer, generateStaticParams, getDictionary, getIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale, useLocaleCookie, useLocalePageRouter, useLocaleStorage, useRewriteURL };
|
package/dist/esm/proxy/index.mjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{localeDetector
|
|
1
|
+
import { localeDetector } from "./localeDetector.mjs";
|
|
2
|
+
import { intlayerProxy } from "./intlayerProxy.mjs";
|
|
3
|
+
import { multipleProxies } from "./multipleProxies.mjs";
|
|
4
|
+
|
|
5
|
+
export { intlayerProxy, localeDetector, multipleProxies };
|
|
@@ -1,2 +1,247 @@
|
|
|
1
|
-
import{localeDetector as
|
|
1
|
+
import { localeDetector as localeDetector$1 } from "./localeDetector.mjs";
|
|
2
|
+
import { getCanonicalPath, getLocalizedPath, getRewriteRules } from "@intlayer/core/localization";
|
|
3
|
+
import configuration from "@intlayer/config/built";
|
|
4
|
+
import { ROUTING_MODE } from "@intlayer/config/defaultValues";
|
|
5
|
+
import { getLocaleFromStorage, setLocaleInStorage } from "@intlayer/core/utils";
|
|
6
|
+
import { NextResponse } from "next/server";
|
|
7
|
+
|
|
8
|
+
//#region src/proxy/intlayerProxy.ts
|
|
9
|
+
const { internationalization, routing } = configuration ?? {};
|
|
10
|
+
const { locales, defaultLocale } = internationalization ?? {};
|
|
11
|
+
const { basePath, mode, rewrite } = routing ?? {};
|
|
12
|
+
const effectiveMode = mode ?? ROUTING_MODE;
|
|
13
|
+
const noPrefix = effectiveMode === "no-prefix" || effectiveMode === "search-params";
|
|
14
|
+
const prefixDefault = effectiveMode === "prefix-all";
|
|
15
|
+
const internalPrefix = !noPrefix;
|
|
16
|
+
const rewriteRules = getRewriteRules(rewrite, "url");
|
|
17
|
+
/**
|
|
18
|
+
* Detects if the request is a prefetch request from Next.js.
|
|
19
|
+
*
|
|
20
|
+
* Next.js prefetch requests can be identified by several headers:
|
|
21
|
+
* - purpose: 'prefetch' (standard prefetch header)
|
|
22
|
+
* - next-router-prefetch: '1' (Next.js router prefetch)
|
|
23
|
+
* - next-url: present (Next.js internal navigation)
|
|
24
|
+
*
|
|
25
|
+
* During prefetch, we should ignore cookie-based locale detection
|
|
26
|
+
* to prevent unwanted redirects when users are switching locales.
|
|
27
|
+
*
|
|
28
|
+
* @param request - The incoming Next.js request object.
|
|
29
|
+
* @returns - True if the request is a prefetch request, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
const isPrefetchRequest = (request) => {
|
|
32
|
+
const purpose = request.headers.get("purpose");
|
|
33
|
+
const nextRouterPrefetch = request.headers.get("next-router-prefetch");
|
|
34
|
+
const nextUrl = request.headers.get("next-url");
|
|
35
|
+
const xNextjsData = request.headers.get("x-nextjs-data");
|
|
36
|
+
return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
|
|
37
|
+
};
|
|
38
|
+
const appendLocaleSearchIfNeeded = (search, locale) => {
|
|
39
|
+
if (effectiveMode !== "search-params") return search;
|
|
40
|
+
const params = new URLSearchParams(search ?? "");
|
|
41
|
+
params.set("locale", locale);
|
|
42
|
+
return `?${params.toString()}`;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Proxy that handles the internationalization layer
|
|
46
|
+
*
|
|
47
|
+
* Usage:
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* // ./src/proxy.ts
|
|
51
|
+
*
|
|
52
|
+
* export { intlayerProxy as proxy } from '@intlayer/next/proxy';
|
|
53
|
+
*
|
|
54
|
+
* // applies this proxy only to files in the app directory
|
|
55
|
+
* export const config = {
|
|
56
|
+
* matcher: '/((?!api|static|.*\\..*|_next).*)',
|
|
57
|
+
* };
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* Main proxy function for handling internationalization.
|
|
61
|
+
*
|
|
62
|
+
* @param request - The incoming Next.js request object.
|
|
63
|
+
* @param event - The Next.js fetch event (optional).
|
|
64
|
+
* @param response - The Next.js response object (optional).
|
|
65
|
+
* @returns - The response to be returned to the client.
|
|
66
|
+
*/
|
|
67
|
+
const intlayerProxy = (request, _event, _response) => {
|
|
68
|
+
const pathname = request.nextUrl.pathname;
|
|
69
|
+
const localLocale = getLocalLocale(request);
|
|
70
|
+
if (noPrefix) return handleNoPrefix(request, localLocale, pathname);
|
|
71
|
+
return handlePrefix(request, localLocale, getPathLocale(pathname), pathname);
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Retrieves the locale from the request cookies if available and valid.
|
|
75
|
+
*
|
|
76
|
+
* @param request - The incoming Next.js request object.
|
|
77
|
+
* @returns - The locale found in the cookies, or undefined if not found or invalid.
|
|
78
|
+
*/
|
|
79
|
+
const getLocalLocale = (request) => getLocaleFromStorage({
|
|
80
|
+
getCookie: (name) => request.cookies.get(name)?.value ?? null,
|
|
81
|
+
getHeader: (name) => request.headers.get(name) ?? null
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Handles the case where URLs do not have locale prefixes.
|
|
85
|
+
*/
|
|
86
|
+
const handleNoPrefix = (request, localLocale, pathname) => {
|
|
87
|
+
const pathLocale = getPathLocale(pathname);
|
|
88
|
+
if (pathLocale) {
|
|
89
|
+
const canonicalPath = getCanonicalPath(pathname.slice(`/${pathLocale}`.length) || "/", pathLocale, rewriteRules);
|
|
90
|
+
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
91
|
+
return redirectUrl(request, search ? `${canonicalPath}${search}` : `${canonicalPath}${request.nextUrl.search ?? ""}`);
|
|
92
|
+
}
|
|
93
|
+
if (effectiveMode === "search-params") {
|
|
94
|
+
const existingLocale = new URLSearchParams(request.nextUrl.search).get("locale");
|
|
95
|
+
const isExistingValid = locales?.includes(existingLocale);
|
|
96
|
+
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ?? localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
97
|
+
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
98
|
+
const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);
|
|
99
|
+
if (existingLocale === locale) return rewriteUrl(request, `${internalPrefix ? `/${locale}${canonicalPath}` : canonicalPath}${request.nextUrl.search ?? ""}`, locale);
|
|
100
|
+
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);
|
|
101
|
+
return redirectUrl(request, search ? `${pathname}${search}` : `${pathname}${request.nextUrl.search ?? ""}`);
|
|
102
|
+
}
|
|
103
|
+
let locale = localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
104
|
+
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
105
|
+
const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);
|
|
106
|
+
const internalPath = internalPrefix ? `/${locale}${canonicalPath}` : canonicalPath;
|
|
107
|
+
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);
|
|
108
|
+
return rewriteUrl(request, search ? `${internalPath}${search}` : `${internalPath}${request.nextUrl.search ?? ""}`, locale);
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Extracts the locale from the URL pathname if present.
|
|
112
|
+
*
|
|
113
|
+
* @param pathname - The pathname from the request URL.
|
|
114
|
+
* @returns - The locale found in the pathname, or undefined if not found.
|
|
115
|
+
*/
|
|
116
|
+
const getPathLocale = (pathname) => locales.find((locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`);
|
|
117
|
+
/**
|
|
118
|
+
* Handles the case where URLs have locale prefixes.
|
|
119
|
+
*
|
|
120
|
+
* @param request - The incoming Next.js request object.
|
|
121
|
+
* @param localLocale - The locale from the cookie.
|
|
122
|
+
* @param pathLocale - The locale extracted from the pathname.
|
|
123
|
+
* @param pathname - The pathname from the request URL.
|
|
124
|
+
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
125
|
+
* @returns - The response to be returned to the client.
|
|
126
|
+
*/
|
|
127
|
+
const handlePrefix = (request, localLocale, pathLocale, pathname) => {
|
|
128
|
+
if (!pathLocale) {
|
|
129
|
+
if (isPrefetchRequest(request) && true) return handleMissingPathLocale(request, defaultLocale, pathname);
|
|
130
|
+
return handleMissingPathLocale(request, localLocale, pathname);
|
|
131
|
+
}
|
|
132
|
+
return handleExistingPathLocale(request, pathLocale, pathname);
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Handles requests where the locale is missing from the URL pathname.
|
|
136
|
+
*
|
|
137
|
+
* @param request - The incoming Next.js request object.
|
|
138
|
+
* @param localLocale - The locale from the cookie.
|
|
139
|
+
* @param pathname - The pathname from the request URL.
|
|
140
|
+
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
141
|
+
* @returns - The response to be returned to the client.
|
|
142
|
+
*/
|
|
143
|
+
const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
144
|
+
let locale = localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
145
|
+
if (!locales.includes(locale)) locale = defaultLocale;
|
|
146
|
+
const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);
|
|
147
|
+
const targetLocalizedPathResult = getLocalizedPath(canonicalPath, locale, rewriteRules);
|
|
148
|
+
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
149
|
+
const newPath = constructPath(locale, targetLocalizedPath, basePath, appendLocaleSearchIfNeeded(request.nextUrl.search, locale));
|
|
150
|
+
return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, internalPrefix ? `/${locale}${canonicalPath}` : canonicalPath, locale);
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Handles requests where the locale exists in the URL pathname.
|
|
154
|
+
*
|
|
155
|
+
* @param request - The incoming Next.js request object.
|
|
156
|
+
* @param localLocale - The locale from the cookie.
|
|
157
|
+
* @param pathLocale - The locale extracted from the pathname.
|
|
158
|
+
* @param pathname - The pathname from the request URL.
|
|
159
|
+
* @returns - The response to be returned to the client.
|
|
160
|
+
*/
|
|
161
|
+
const handleExistingPathLocale = (request, pathLocale, pathname) => {
|
|
162
|
+
const rawPath = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
163
|
+
const canonicalPath = getCanonicalPath(rawPath, pathLocale, rewriteRules);
|
|
164
|
+
const targetLocalizedPathResult = getLocalizedPath(canonicalPath, pathLocale, rewriteRules);
|
|
165
|
+
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
166
|
+
if ((typeof targetLocalizedPathResult === "string" ? false : targetLocalizedPathResult.isRewritten) && targetLocalizedPath !== rawPath) return redirectUrl(request, constructPath(pathLocale, targetLocalizedPath, basePath, appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale)));
|
|
167
|
+
const internalUrl = internalPrefix ? `/${pathLocale}${canonicalPath}` : canonicalPath;
|
|
168
|
+
if (!prefixDefault && pathLocale === defaultLocale) return handleDefaultLocaleRedirect(request, pathLocale, pathname);
|
|
169
|
+
const search = request.nextUrl.search;
|
|
170
|
+
return rewriteUrl(request, internalUrl + (search ?? ""), pathLocale);
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.
|
|
174
|
+
*
|
|
175
|
+
* @param request - The incoming Next.js request object.
|
|
176
|
+
* @param pathname - The pathname from the request URL.
|
|
177
|
+
* @param pathLocale - The locale extracted from the pathname.
|
|
178
|
+
* @param localLocale - The locale from the cookie.
|
|
179
|
+
* @param basePath - The base path of the application.
|
|
180
|
+
* @returns - The new URL path with the correct locale.
|
|
181
|
+
*/
|
|
182
|
+
/**
|
|
183
|
+
* The key fix for 404s without [locale] folders
|
|
184
|
+
*/
|
|
185
|
+
const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
186
|
+
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
187
|
+
const targetLocalizedPathResult = getLocalizedPath(canonicalPath, pathLocale, rewriteRules);
|
|
188
|
+
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
189
|
+
const basePathTrailingSlash = basePath.endsWith("/");
|
|
190
|
+
let finalPath = targetLocalizedPath;
|
|
191
|
+
if (finalPath.startsWith("/")) finalPath = finalPath.slice(1);
|
|
192
|
+
return redirectUrl(request, `${basePath}${basePathTrailingSlash ? "" : "/"}${finalPath}` + (appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale) ?? request.nextUrl.search ?? ""));
|
|
193
|
+
}
|
|
194
|
+
const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
195
|
+
const internalPath = internalPrefix ? `/${pathLocale}${canonicalPath}` : canonicalPath;
|
|
196
|
+
return rewriteUrl(request, searchWithLocale ? `${internalPath}${searchWithLocale}` : `${internalPath}${request.nextUrl.search ?? ""}`, pathLocale);
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Constructs a new path by combining the locale, path, basePath, and search parameters.
|
|
200
|
+
*
|
|
201
|
+
* @param locale - The locale to include in the path.
|
|
202
|
+
* @param path - The original path from the request.
|
|
203
|
+
* @param basePath - The base path of the application.
|
|
204
|
+
* @param [search] - The query string from the request URL (optional).
|
|
205
|
+
* @returns - The constructed new path.
|
|
206
|
+
*/
|
|
207
|
+
const constructPath = (locale, path, basePath, search) => {
|
|
208
|
+
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
209
|
+
if (effectiveMode === "no-prefix" || effectiveMode === "search-params") return `${pathWithoutPrefix}${search ? `?${search}` : ""}`;
|
|
210
|
+
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
211
|
+
return `${basePath}${basePath.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`.replace(/\/+/g, "/");
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* This handles the internal path Next.js sees.
|
|
215
|
+
* To support optional [locale] folders, we need to decide if we
|
|
216
|
+
* keep the locale prefix or strip it.
|
|
217
|
+
*/
|
|
218
|
+
const rewriteUrl = (request, newPath, locale) => {
|
|
219
|
+
const search = request.nextUrl.search;
|
|
220
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
221
|
+
const requestHeaders = new Headers(request.headers);
|
|
222
|
+
setLocaleInStorage(locale, { setHeader: (name, value) => {
|
|
223
|
+
requestHeaders.set(name, value);
|
|
224
|
+
} });
|
|
225
|
+
const targetUrl = new URL(pathWithSearch, request.url);
|
|
226
|
+
const response = targetUrl.href === request.nextUrl.href ? NextResponse.next({ request: { headers: requestHeaders } }) : NextResponse.rewrite(targetUrl, { request: { headers: requestHeaders } });
|
|
227
|
+
setLocaleInStorage(locale, { setHeader: (name, value) => {
|
|
228
|
+
response.headers.set(name, value);
|
|
229
|
+
} });
|
|
230
|
+
return response;
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Redirects the request to the new path.
|
|
234
|
+
*
|
|
235
|
+
* @param request - The incoming Next.js request object.
|
|
236
|
+
* @param newPath - The new path to redirect to.
|
|
237
|
+
* @returns - The redirect response.
|
|
238
|
+
*/
|
|
239
|
+
const redirectUrl = (request, newPath) => {
|
|
240
|
+
const search = request.nextUrl.search;
|
|
241
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
242
|
+
return NextResponse.redirect(new URL(pathWithSearch, request.url));
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
export { intlayerProxy };
|
|
2
247
|
//# sourceMappingURL=intlayerProxy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.mjs","names":["localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\n} from '@intlayer/core/localization';\nimport { getLocaleFromStorage, setLocaleInStorage } 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 { internationalization, routing } = configuration ?? {};\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { basePath, mode, rewrite } = routing ?? {};\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 effectiveMode === 'no-prefix' || effectiveMode === 'search-params';\nconst prefixDefault = effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules = getRewriteRules(rewrite, 'url');\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests can be identified by several headers:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js router prefetch)\n * - next-url: present (Next.js internal navigation)\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 const nextUrl = request.headers.get('next-url');\n const xNextjsData = request.headers.get('x-nextjs-data');\n\n return (\n purpose === 'prefetch' ||\n nextRouterPrefetch === '1' ||\n !!nextUrl ||\n !!xNextjsData\n );\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 (effectiveMode !== 'search-params') 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 */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\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 return handlePrefix(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\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 getLocaleFromStorage({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n getHeader: (name: string) => request.headers.get(name) ?? null,\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 return redirectUrl(request, redirectPath);\n }\n\n if (effectiveMode === 'search-params') {\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 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 if (existingLocale === locale) {\n const internalPath = internalPrefix\n ? `/${locale}${canonicalPath}`\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 ? `/${locale}${canonicalPath}`\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 * 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[]).find(\n (locale) => pathname.startsWith(`/${locale}/`) || 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 as Locale[]).includes(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 return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(\n request,\n internalPrefix ? `/${locale}${canonicalPath}` : 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 const internalUrl = internalPrefix\n ? `/${pathLocale}${canonicalPath}`\n : canonicalPath;\n\n // Only handle redirect if we are strictly managing default locale prefixing\n if (!prefixDefault && pathLocale === defaultLocale) {\n return handleDefaultLocaleRedirect(request, pathLocale, pathname);\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 if (!prefixDefault && pathLocale === defaultLocale) {\n // Redirect to remove prefix\n // We use canonicalPath because in no-prefix default mode, the URL is usually just the path\n // But wait, if we are in this function, the URL *has* a prefix.\n // We want to redirect to /about (localized for EN).\n\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 // Construct path without prefix\n const basePathTrailingSlash = (basePath as string).endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? '')\n );\n }\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n // If no redirect needed, we rewrite to the internal canonical path\n const internalPath = internalPrefix\n ? `/${pathLocale}${canonicalPath}`\n : canonicalPath;\n\n const rewriteTarget = searchWithLocale\n ? `${internalPath}${searchWithLocale}`\n : `${internalPath}${request.nextUrl.search ?? ''}`;\n\n return rewriteUrl(request, rewriteTarget, pathLocale);\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 = path.startsWith(`/${locale}`)\n ? path.slice(`/${locale}`.length) || '/'\n : path;\n\n if (effectiveMode === 'no-prefix' || effectiveMode === 'search-params') {\n return `${pathWithoutPrefix}${search ? `?${search}` : ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = path.startsWith(`/${locale}`)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathTrailingSlash = basePath.endsWith('/');\n const newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n return 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 const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorage(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 setLocaleInStorage(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 * @returns - The redirect response.\n */\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse => {\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n"],"mappings":"mYA+CA,KAAM,CAAE,uBAAsB,WAAY,GAAiB,EAAE,CACvD,CAAE,UAAS,iBAAkB,GAAwB,EAAE,CACvD,CAAE,WAAU,OAAM,WAAY,GAAW,EAAE,CAK3C,EAAgB,GAAQ,EACxB,EACJ,IAAkB,aAAe,IAAkB,gBAC/C,EAAgB,IAAkB,aAElC,EAAiB,CAAC,EAElB,EAAe,EAAgB,EAAS,MAAM,CAgB9C,EAAqB,GAAkC,CAC3D,IAAM,EAAU,EAAQ,QAAQ,IAAI,UAAU,CACxC,EAAqB,EAAQ,QAAQ,IAAI,uBAAuB,CAChE,EAAU,EAAQ,QAAQ,IAAI,WAAW,CACzC,EAAc,EAAQ,QAAQ,IAAI,gBAAgB,CAExD,OACE,IAAY,YACZ,IAAuB,KACvB,CAAC,CAAC,GACF,CAAC,CAAC,GAKA,GACJ,EACA,IACuB,CACvB,GAAI,IAAkB,gBAAiB,OAAO,EAC9C,IAAM,EAAS,IAAI,gBAAgB,GAAU,GAAG,CAEhD,OADA,EAAO,IAAI,SAAU,EAAO,CACrB,IAAI,EAAO,UAAU,IA0BjB,GACX,EACA,EACA,IACiB,CACjB,IAAM,EAAW,EAAQ,QAAQ,SAE3B,EAAc,EAAe,EAAQ,CAO3C,OALI,EACK,EAAe,EAAS,EAAa,EAAS,CAIhD,EAAa,EAAS,EADV,EAAc,EAAS,CACY,EAAS,EAS3D,EAAkB,GACtB,EAAqB,CACnB,UAAY,GAAiB,EAAQ,QAAQ,IAAI,EAAK,EAAE,OAAS,KACjE,UAAY,GAAiB,EAAQ,QAAQ,IAAI,EAAK,EAAI,KAC3D,CAAC,CAKE,GACJ,EACA,EACA,IACiB,CACjB,IAAM,EAAa,EAAc,EAAS,CA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,IAAkB,CAC1C,EAAS,QAAQ,IAAI,EAAM,EAAM,EAEpC,CAAC,CACK,GAUH,GAAe,EAAsB,IAAkC,CAC3E,IAAM,EAAS,EAAQ,QAAQ,OACzB,EACJ,GAAU,CAAC,EAAQ,SAAS,IAAI,CAAG,GAAG,IAAU,IAAW,EAE7D,OAAO,EAAa,SAAS,IAAI,IAAI,EAAgB,EAAQ,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"intlayerProxy.mjs","names":["localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\n} from '@intlayer/core/localization';\nimport { getLocaleFromStorage, setLocaleInStorage } 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 { internationalization, routing } = configuration ?? {};\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { basePath, mode, rewrite } = routing ?? {};\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 effectiveMode === 'no-prefix' || effectiveMode === 'search-params';\nconst prefixDefault = effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules = getRewriteRules(rewrite, 'url');\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests can be identified by several headers:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js router prefetch)\n * - next-url: present (Next.js internal navigation)\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 const nextUrl = request.headers.get('next-url');\n const xNextjsData = request.headers.get('x-nextjs-data');\n\n return (\n purpose === 'prefetch' ||\n nextRouterPrefetch === '1' ||\n !!nextUrl ||\n !!xNextjsData\n );\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 (effectiveMode !== 'search-params') 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 */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\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 return handlePrefix(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\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 getLocaleFromStorage({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n getHeader: (name: string) => request.headers.get(name) ?? null,\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 return redirectUrl(request, redirectPath);\n }\n\n if (effectiveMode === 'search-params') {\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 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 if (existingLocale === locale) {\n const internalPath = internalPrefix\n ? `/${locale}${canonicalPath}`\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 ? `/${locale}${canonicalPath}`\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 * 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[]).find(\n (locale) => pathname.startsWith(`/${locale}/`) || 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 as Locale[]).includes(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 return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(\n request,\n internalPrefix ? `/${locale}${canonicalPath}` : 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 const internalUrl = internalPrefix\n ? `/${pathLocale}${canonicalPath}`\n : canonicalPath;\n\n // Only handle redirect if we are strictly managing default locale prefixing\n if (!prefixDefault && pathLocale === defaultLocale) {\n return handleDefaultLocaleRedirect(request, pathLocale, pathname);\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 if (!prefixDefault && pathLocale === defaultLocale) {\n // Redirect to remove prefix\n // We use canonicalPath because in no-prefix default mode, the URL is usually just the path\n // But wait, if we are in this function, the URL *has* a prefix.\n // We want to redirect to /about (localized for EN).\n\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 // Construct path without prefix\n const basePathTrailingSlash = (basePath as string).endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? '')\n );\n }\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n // If no redirect needed, we rewrite to the internal canonical path\n const internalPath = internalPrefix\n ? `/${pathLocale}${canonicalPath}`\n : canonicalPath;\n\n const rewriteTarget = searchWithLocale\n ? `${internalPath}${searchWithLocale}`\n : `${internalPath}${request.nextUrl.search ?? ''}`;\n\n return rewriteUrl(request, rewriteTarget, pathLocale);\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 = path.startsWith(`/${locale}`)\n ? path.slice(`/${locale}`.length) || '/'\n : path;\n\n if (effectiveMode === 'no-prefix' || effectiveMode === 'search-params') {\n return `${pathWithoutPrefix}${search ? `?${search}` : ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = path.startsWith(`/${locale}`)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathTrailingSlash = basePath.endsWith('/');\n const newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n return 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 const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorage(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 setLocaleInStorage(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 * @returns - The redirect response.\n */\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse => {\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n"],"mappings":";;;;;;;;AA+CA,MAAM,EAAE,sBAAsB,YAAY,iBAAiB,EAAE;AAC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G,UAAU,WAAW;CAE7D,MAAM,iBAAiB,IAAI,QAAQ,QAAQ,QAAQ;AACnD,oBAAmB,QAAQ,EACzB,YAAY,MAAc,UAAkB;AAC1C,iBAAe,IAAI,MAAM,MAAM;IAElC,CAAC;CAEF,MAAM,YAAY,IAAI,IAAI,gBAAgB,QAAQ,IAAI;CAItD,MAAM,WACJ,UAAU,SAAS,QAAQ,QAAQ,OAC/B,aAAa,KAAK,EAChB,SAAS,EACP,SAAS,gBACV,EACF,CAAC,GACF,aAAa,QAAQ,WAAW,EAC9B,SAAS,EACP,SAAS,gBACV,EACF,CAAC;AAER,oBAAmB,QAAQ,EACzB,YAAY,MAAc,UAAkB;AAC1C,WAAS,QAAQ,IAAI,MAAM,MAAM;IAEpC,CAAC;AACF,QAAO;;;;;;;;;AAUT,MAAM,eAAe,SAAsB,YAAkC;CAC3E,MAAM,SAAS,QAAQ,QAAQ;CAC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;AAE7D,QAAO,aAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
import{localeDetector as
|
|
1
|
+
import { localeDetector as localeDetector$1 } from "@intlayer/core/localization";
|
|
2
|
+
|
|
3
|
+
//#region src/proxy/localeDetector.ts
|
|
4
|
+
/**
|
|
5
|
+
* Detects the locale from the request headers
|
|
6
|
+
*
|
|
7
|
+
* Headers are provided by the browser and can be used to determine the user's preferred language
|
|
8
|
+
*/
|
|
9
|
+
const localeDetector = (request) => {
|
|
10
|
+
const negotiatorHeaders = {};
|
|
11
|
+
request.headers.forEach((value, key) => {
|
|
12
|
+
negotiatorHeaders[key] = value;
|
|
13
|
+
});
|
|
14
|
+
return localeDetector$1(negotiatorHeaders);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { localeDetector };
|
|
2
19
|
//# sourceMappingURL=localeDetector.mjs.map
|