next-intlayer 8.7.11 → 8.7.12
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/client/useLocale.cjs +2 -7
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/proxy/intlayerProxy.cjs +8 -32
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +2 -7
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/proxy/intlayerProxy.mjs +8 -32
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/generateStaticParams.d.ts +2 -2
- package/dist/types/generateStaticParams.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/dist/types/server/useDictionary.d.ts +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +1 -1
- package/package.json +8 -8
- package/dist/types/intlayer/dist/types/index.d.ts +0 -3
|
@@ -9,11 +9,6 @@ let next_navigation_js = require("next/navigation.js");
|
|
|
9
9
|
let react = require("react");
|
|
10
10
|
|
|
11
11
|
//#region src/client/useLocale.ts
|
|
12
|
-
/**
|
|
13
|
-
* True when no domain routing is configured at build time
|
|
14
|
-
* (INTLAYER_ROUTING_DOMAINS === 'false').
|
|
15
|
-
*/
|
|
16
|
-
const TREE_SHAKE_DOMAINS = process.env["INTLAYER_ROUTING_DOMAINS"] === "false";
|
|
17
12
|
const usePathWithoutLocale = () => {
|
|
18
13
|
const pathname = (0, next_navigation_js.usePathname)();
|
|
19
14
|
const [fullPath, setFullPath] = (0, react.useState)(pathname);
|
|
@@ -53,7 +48,7 @@ const useLocale = ({ onChange = "replace" } = {}) => {
|
|
|
53
48
|
return {
|
|
54
49
|
...(0, react_intlayer.useLocale)({ onLocaleChange: (0, react.useCallback)((locale) => {
|
|
55
50
|
if (!onChange) return;
|
|
56
|
-
const pathWithLocale = (0, _intlayer_core_localization.getLocalizedUrl)(pathWithoutLocale, locale, { currentDomain:
|
|
51
|
+
const pathWithLocale = (0, _intlayer_core_localization.getLocalizedUrl)(pathWithoutLocale, locale, { currentDomain: process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && typeof window !== "undefined" ? window.location.hostname : void 0 });
|
|
57
52
|
if (typeof onChange === "function") {
|
|
58
53
|
onChange({
|
|
59
54
|
locale,
|
|
@@ -61,7 +56,7 @@ const useLocale = ({ onChange = "replace" } = {}) => {
|
|
|
61
56
|
});
|
|
62
57
|
return;
|
|
63
58
|
}
|
|
64
|
-
if (
|
|
59
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && (0, _intlayer_core_utils.checkIsURLAbsolute)(pathWithLocale)) {
|
|
65
60
|
window.location.href = pathWithLocale;
|
|
66
61
|
return;
|
|
67
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\nimport { checkIsURLAbsolute } from '@intlayer/core/utils';\nimport type { LocalesValues } 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: LocalesValues; 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: 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 window.location.href = 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":";;;;;;;;;;;AAoBA,MAAM,6BAA6B;CACjC,MAAM,gDAAwB;CAC9B,MAAM,CAAC,UAAU,mCAAwB,SAAS;AAElD,4BAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,uFAA0C,SAAS,EAAE,CAAC,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BlE,MAAa,aAAa,EAAE,WAAW,cAA8B,EAAE,KAAK;CAC1E,MAAM,EAAE,SAAS,4CAAoB;CACrC,MAAM,oBAAoB,sBAAsB;AA6ChD,QAAO;EACL,iCALqC,EACrC,wCAvCC,WAA0B;AACzB,OAAI,CAAC,SAAU;GAQf,MAAM,kEAAiC,mBAAmB,QAAQ,EAChE,eANA,QAAQ,IAAI,gCAAgC,WAC5C,OAAO,WAAW,cACd,OAAO,SAAS,WAChB,QAIL,CAAC;AAEF,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS;KAAE;KAAQ,MAAM;KAAgB,CAAC;AAC1C;;AAKF,OACE,QAAQ,IAAI,gCAAgC,wDACzB,eAAe,EAClC;AACA,WAAO,SAAS,OAAO;AACvB;;AAGF,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAIT,EACpC,CAGmB;EAClB;EACD"}
|
|
@@ -8,37 +8,13 @@ let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
|
8
8
|
let next_server = require("next/server");
|
|
9
9
|
|
|
10
10
|
//#region src/proxy/intlayerProxy.ts
|
|
11
|
-
/**
|
|
12
|
-
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
13
|
-
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
14
|
-
*/
|
|
15
|
-
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
16
|
-
/**
|
|
17
|
-
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
18
|
-
*/
|
|
19
|
-
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
20
|
-
/**
|
|
21
|
-
* True when the build-time routing mode is known and is not a prefix-based
|
|
22
|
-
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
23
|
-
*/
|
|
24
|
-
const TREE_SHAKE_PREFIX_MODES = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default";
|
|
25
|
-
/**
|
|
26
|
-
* True when rewrite rules are explicitly disabled at build time
|
|
27
|
-
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
28
|
-
*/
|
|
29
|
-
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
30
|
-
/**
|
|
31
|
-
* True when no domain routing is configured at build time
|
|
32
|
-
* (INTLAYER_ROUTING_DOMAINS === 'false').
|
|
33
|
-
*/
|
|
34
|
-
const TREE_SHAKE_DOMAINS = process.env["INTLAYER_ROUTING_DOMAINS"] === "false";
|
|
35
11
|
const { locales, defaultLocale } = _intlayer_config_built.internationalization ?? {};
|
|
36
12
|
const { basePath, mode, rewrite, domains } = _intlayer_config_built.routing ?? {};
|
|
37
13
|
const effectiveMode = mode ?? _intlayer_config_defaultValues.ROUTING_MODE;
|
|
38
|
-
const noPrefix = !
|
|
39
|
-
const prefixDefault = !
|
|
14
|
+
const noPrefix = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix") && effectiveMode === "no-prefix" || !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params";
|
|
15
|
+
const prefixDefault = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default") && effectiveMode === "prefix-all";
|
|
40
16
|
const internalPrefix = !noPrefix;
|
|
41
|
-
const rewriteRules =
|
|
17
|
+
const rewriteRules = process.env["INTLAYER_ROUTING_REWRITE_RULES"] !== "false" ? (0, _intlayer_core_localization.getRewriteRules)(rewrite, "url") : void 0;
|
|
42
18
|
/**
|
|
43
19
|
* Strips the protocol from a domain string and returns only the hostname.
|
|
44
20
|
* e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'
|
|
@@ -85,7 +61,7 @@ const isPrefetchRequest = (request) => {
|
|
|
85
61
|
return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
|
|
86
62
|
};
|
|
87
63
|
const appendLocaleSearchIfNeeded = (search, locale) => {
|
|
88
|
-
if (
|
|
64
|
+
if (process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params" || effectiveMode !== "search-params") return search;
|
|
89
65
|
const params = new URLSearchParams(search ?? "");
|
|
90
66
|
params.set("locale", locale);
|
|
91
67
|
return `?${params.toString()}`;
|
|
@@ -118,7 +94,7 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
118
94
|
const localLocale = getLocalLocale(request);
|
|
119
95
|
if (noPrefix) return handleNoPrefix(request, localLocale, pathname);
|
|
120
96
|
const pathLocale = getPathLocale(pathname);
|
|
121
|
-
if (
|
|
97
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && pathLocale && domains) {
|
|
122
98
|
const localeDomain = domains[pathLocale];
|
|
123
99
|
if (localeDomain) {
|
|
124
100
|
if (normalizeDomainHostname(localeDomain) !== request.nextUrl.hostname) {
|
|
@@ -128,7 +104,7 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
128
104
|
}
|
|
129
105
|
}
|
|
130
106
|
}
|
|
131
|
-
if (
|
|
107
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && !pathLocale) {
|
|
132
108
|
const domainLocale = getLocaleFromDomain(request.nextUrl.hostname);
|
|
133
109
|
if (domainLocale) return rewriteUrl(request, `/${domainLocale}${(0, _intlayer_core_localization.getCanonicalPath)(pathname, domainLocale, rewriteRules)}` + (request.nextUrl.search ?? ""), domainLocale);
|
|
134
110
|
}
|
|
@@ -154,7 +130,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
154
130
|
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
155
131
|
return redirectUrl(request, search ? `${canonicalPath}${search}` : `${canonicalPath}${request.nextUrl.search ?? ""}`);
|
|
156
132
|
}
|
|
157
|
-
if (!
|
|
133
|
+
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") {
|
|
158
134
|
const existingLocale = new URLSearchParams(request.nextUrl.search).get("locale");
|
|
159
135
|
const isExistingValid = locales?.includes(existingLocale);
|
|
160
136
|
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ?? localLocale ?? require_proxy_localeDetector.localeDetector?.(request) ?? defaultLocale;
|
|
@@ -270,7 +246,7 @@ const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
|
270
246
|
*/
|
|
271
247
|
const constructPath = (locale, path, basePath, search) => {
|
|
272
248
|
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
273
|
-
if (!
|
|
249
|
+
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix") && effectiveMode === "no-prefix" || !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") return `${pathWithoutPrefix}${search ? `?${search}` : ""}`;
|
|
274
250
|
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
275
251
|
return `${basePath}${basePath.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`.replace(/\/+/g, "/");
|
|
276
252
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.cjs","names":["internationalization","routing","ROUTING_MODE","NextResponse","localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n * Use to guard no-prefix-specific code paths so bundlers can eliminate them.\n */\nconst TREE_SHAKE_NO_PREFIX =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n */\nconst TREE_SHAKE_SEARCH_PARAMS =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n */\nconst TREE_SHAKE_PREFIX_MODES =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-all' &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default';\n\n/**\n * True when rewrite rules are explicitly disabled at build time\n * (INTLAYER_ROUTING_REWRITE_RULES === 'false').\n */\nconst TREE_SHAKE_REWRITE =\n process.env['INTLAYER_ROUTING_REWRITE_RULES'] === 'false';\n\n/**\n * True when no domain routing is configured at build time\n * (INTLAYER_ROUTING_DOMAINS === 'false').\n */\nconst TREE_SHAKE_DOMAINS = process.env['INTLAYER_ROUTING_DOMAINS'] === 'false';\n\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\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 } = 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 (!TREE_SHAKE_NO_PREFIX && effectiveMode === 'no-prefix') ||\n (!TREE_SHAKE_SEARCH_PARAMS && effectiveMode === 'search-params');\nconst prefixDefault =\n !TREE_SHAKE_PREFIX_MODES && effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules = !TREE_SHAKE_REWRITE\n ? getRewriteRules(rewrite, 'url')\n : undefined;\n\n/**\n * Strips the protocol from a domain string and returns only the hostname.\n * e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'\n */\nconst normalizeDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or undefined if zero or more than one locale share that hostname.\n *\n * Example: with domains = { zh: 'intlayer.zh', fr: 'intlayer.org' }\n * getLocaleFromDomain('intlayer.zh') → 'zh'\n * getLocaleFromDomain('intlayer.org') → undefined (multiple locales share it)\n */\nconst getLocaleFromDomain = (hostname: string): Locale | undefined => {\n if (!domains) return undefined;\n const matching = Object.entries(domains).filter(\n ([, domain]) => normalizeDomainHostname(domain!) === hostname\n );\n return matching.length === 1 ? (matching[0][0] as Locale) : undefined;\n};\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 (TREE_SHAKE_SEARCH_PARAMS || effectiveMode !== 'search-params')\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 */\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\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 (!TREE_SHAKE_DOMAINS && pathLocale && domains) {\n const localeDomain = domains[pathLocale];\n\n if (localeDomain) {\n const domainHost = normalizeDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = /^https?:\\/\\//.test(localeDomain)\n ? localeDomain\n : `https://${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 (!TREE_SHAKE_DOMAINS && !pathLocale) {\n const domainLocale = getLocaleFromDomain(request.nextUrl.hostname);\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n const internalPath = `/${domainLocale}${canonicalPath}`;\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 * @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 getLocaleFromStorageServer({\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 (!TREE_SHAKE_SEARCH_PARAMS && 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 // 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 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 (\n (!TREE_SHAKE_NO_PREFIX && effectiveMode === 'no-prefix') ||\n (!TREE_SHAKE_SEARCH_PARAMS && effectiveMode === 'search-params')\n ) {\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 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 * @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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AC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;CAE7D,MAAM,iBAAiB,IAAI,QAAQ,QAAQ,QAAQ;AACnD,oDAAyB,QAAQ,EAC/B,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/BD,yBAAa,KAAK,EAChB,SAAS,EACP,SAAS,gBACV,EACF,CAAC,GACFA,yBAAa,QAAQ,WAAW,EAC9B,SAAS,EACP,SAAS,gBACV,EACF,CAAC;AAER,oDAAyB,QAAQ,EAC/B,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,QAAOA,yBAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"intlayerProxy.cjs","names":["internationalization","routing","ROUTING_MODE","NextResponse","localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\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 } = 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 (!(\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 process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default'\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 * Strips the protocol from a domain string and returns only the hostname.\n * e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'\n */\nconst normalizeDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or undefined if zero or more than one locale share that hostname.\n *\n * Example: with domains = { zh: 'intlayer.zh', fr: 'intlayer.org' }\n * getLocaleFromDomain('intlayer.zh') → 'zh'\n * getLocaleFromDomain('intlayer.org') → undefined (multiple locales share it)\n */\nconst getLocaleFromDomain = (hostname: string): Locale | undefined => {\n if (!domains) return undefined;\n const matching = Object.entries(domains).filter(\n ([, domain]) => normalizeDomainHostname(domain!) === hostname\n );\n return matching.length === 1 ? (matching[0][0] as Locale) : undefined;\n};\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 (\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 */\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\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 = normalizeDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = /^https?:\\/\\//.test(localeDomain)\n ? localeDomain\n : `https://${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(request.nextUrl.hostname);\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n const internalPath = `/${domainLocale}${canonicalPath}`;\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 * @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 getLocaleFromStorageServer({\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 (\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 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 // 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 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 (\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 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 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 * @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":";;;;;;;;;;AAuDA,MAAM,EAAE,SAAS,kBAAkBA,+CAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,MAAM,SAAS,YAAYC,kCAAW,EAAE;AAK1D,MAAM,gBAAgB,QAAQC;AAC9B,MAAM,WACH,EACC,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBAEzC,kBAAkB,eACnB,EACC,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,oBAEzC,kBAAkB;AACtB,MAAM,gBACJ,EACE,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B,wBACtC,kBAAkB;AAEzB,MAAM,iBAAiB,CAAC;AAExB,MAAM,eACJ,QAAQ,IAAI,sCAAsC,2DAC9B,SAAS,MAAM,GAC/B;;;;;AAMN,MAAM,2BAA2B,WAA2B;AAC1D,KAAI;AACF,SAAO,eAAe,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,CAAC,WAAW;SAC1D;AACN,SAAO;;;;;;;;;;;AAYX,MAAM,uBAAuB,aAAyC;AACpE,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,WAAW,OAAO,QAAQ,QAAQ,CAAC,QACtC,GAAG,YAAY,wBAAwB,OAAQ,KAAK,SACtD;AACD,QAAO,SAAS,WAAW,IAAK,SAAS,GAAG,KAAgB;;;;;;;;;;;;;;;;AAiB9D,MAAM,qBAAqB,YAAkC;CAC3D,MAAM,UAAU,QAAQ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QAAO,GAAG,oBAAoB,SAAS,IAAI,WAAW;CAIxD,MAAM,uBAAuB,KAAK,WAAW,IAAI,SAAS,GACtD,OACA,GAAG,SAAS,KAAK,WAAW,IAAI,GAAG,KAAK,MAAM;AAQlD,QAFkB,GAHC,WADW,SAAS,SAAS,IACG,GAAG,KAAK,MAAM,uBAGvC,QAAQ,QAAQ,IAE1B;;;;;;;AAQlB,MAAM,cACJ,SACA,SACA,WACiB;CACjB,MAAM,SAAS,QAAQ,QAAQ;CAC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;CAE7D,MAAM,iBAAiB,IAAI,QAAQ,QAAQ,QAAQ;AACnD,oDAAyB,QAAQ,EAC/B,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/BD,yBAAa,KAAK,EAChB,SAAS,EACP,SAAS,gBACV,EACF,CAAC,GACFA,yBAAa,QAAQ,WAAW,EAC9B,SAAS,EACP,SAAS,gBACV,EACF,CAAC;AAER,oDAAyB,QAAQ,EAC/B,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,QAAOA,yBAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC"}
|
|
@@ -7,11 +7,6 @@ import { usePathname, useRouter } from "next/navigation.js";
|
|
|
7
7
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
8
8
|
|
|
9
9
|
//#region src/client/useLocale.ts
|
|
10
|
-
/**
|
|
11
|
-
* True when no domain routing is configured at build time
|
|
12
|
-
* (INTLAYER_ROUTING_DOMAINS === 'false').
|
|
13
|
-
*/
|
|
14
|
-
const TREE_SHAKE_DOMAINS = process.env["INTLAYER_ROUTING_DOMAINS"] === "false";
|
|
15
10
|
const usePathWithoutLocale = () => {
|
|
16
11
|
const pathname = usePathname();
|
|
17
12
|
const [fullPath, setFullPath] = useState(pathname);
|
|
@@ -51,7 +46,7 @@ const useLocale = ({ onChange = "replace" } = {}) => {
|
|
|
51
46
|
return {
|
|
52
47
|
...useLocale$1({ onLocaleChange: useCallback((locale) => {
|
|
53
48
|
if (!onChange) return;
|
|
54
|
-
const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale, { currentDomain:
|
|
49
|
+
const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale, { currentDomain: process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && typeof window !== "undefined" ? window.location.hostname : void 0 });
|
|
55
50
|
if (typeof onChange === "function") {
|
|
56
51
|
onChange({
|
|
57
52
|
locale,
|
|
@@ -59,7 +54,7 @@ const useLocale = ({ onChange = "replace" } = {}) => {
|
|
|
59
54
|
});
|
|
60
55
|
return;
|
|
61
56
|
}
|
|
62
|
-
if (
|
|
57
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && checkIsURLAbsolute(pathWithLocale)) {
|
|
63
58
|
window.location.href = pathWithLocale;
|
|
64
59
|
return;
|
|
65
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\
|
|
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 { checkIsURLAbsolute } from '@intlayer/core/utils';\nimport type { LocalesValues } 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: LocalesValues; 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: 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 window.location.href = 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":";;;;;;;;;AAoBA,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;AA6ChD,QAAO;EACL,GALsBA,YAAe,EACrC,gBAxC0B,aACzB,WAA0B;AACzB,OAAI,CAAC,SAAU;GAQf,MAAM,iBAAiB,gBAAgB,mBAAmB,QAAQ,EAChE,eANA,QAAQ,IAAI,gCAAgC,WAC5C,OAAO,WAAW,cACd,OAAO,SAAS,WAChB,QAIL,CAAC;AAEF,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS;KAAE;KAAQ,MAAM;KAAgB,CAAC;AAC1C;;AAKF,OACE,QAAQ,IAAI,gCAAgC,WAC5C,mBAAmB,eAAe,EAClC;AACA,WAAO,SAAS,OAAO;AACvB;;AAGF,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAIT,EACpC,CAGmB;EAClB;EACD"}
|
|
@@ -6,37 +6,13 @@ import { ROUTING_MODE } from "@intlayer/config/defaultValues";
|
|
|
6
6
|
import { NextResponse } from "next/server";
|
|
7
7
|
|
|
8
8
|
//#region src/proxy/intlayerProxy.ts
|
|
9
|
-
/**
|
|
10
|
-
* True when the build-time routing mode is known and is NOT 'no-prefix'.
|
|
11
|
-
* Use to guard no-prefix-specific code paths so bundlers can eliminate them.
|
|
12
|
-
*/
|
|
13
|
-
const TREE_SHAKE_NO_PREFIX = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix";
|
|
14
|
-
/**
|
|
15
|
-
* True when the build-time routing mode is known and is NOT 'search-params'.
|
|
16
|
-
*/
|
|
17
|
-
const TREE_SHAKE_SEARCH_PARAMS = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params";
|
|
18
|
-
/**
|
|
19
|
-
* True when the build-time routing mode is known and is not a prefix-based
|
|
20
|
-
* mode (neither 'prefix-all' nor 'prefix-no-default').
|
|
21
|
-
*/
|
|
22
|
-
const TREE_SHAKE_PREFIX_MODES = process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default";
|
|
23
|
-
/**
|
|
24
|
-
* True when rewrite rules are explicitly disabled at build time
|
|
25
|
-
* (INTLAYER_ROUTING_REWRITE_RULES === 'false').
|
|
26
|
-
*/
|
|
27
|
-
const TREE_SHAKE_REWRITE = process.env["INTLAYER_ROUTING_REWRITE_RULES"] === "false";
|
|
28
|
-
/**
|
|
29
|
-
* True when no domain routing is configured at build time
|
|
30
|
-
* (INTLAYER_ROUTING_DOMAINS === 'false').
|
|
31
|
-
*/
|
|
32
|
-
const TREE_SHAKE_DOMAINS = process.env["INTLAYER_ROUTING_DOMAINS"] === "false";
|
|
33
9
|
const { locales, defaultLocale } = internationalization ?? {};
|
|
34
10
|
const { basePath, mode, rewrite, domains } = routing ?? {};
|
|
35
11
|
const effectiveMode = mode ?? ROUTING_MODE;
|
|
36
|
-
const noPrefix = !
|
|
37
|
-
const prefixDefault = !
|
|
12
|
+
const noPrefix = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix") && effectiveMode === "no-prefix" || !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params";
|
|
13
|
+
const prefixDefault = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all" && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-no-default") && effectiveMode === "prefix-all";
|
|
38
14
|
const internalPrefix = !noPrefix;
|
|
39
|
-
const rewriteRules =
|
|
15
|
+
const rewriteRules = process.env["INTLAYER_ROUTING_REWRITE_RULES"] !== "false" ? getRewriteRules(rewrite, "url") : void 0;
|
|
40
16
|
/**
|
|
41
17
|
* Strips the protocol from a domain string and returns only the hostname.
|
|
42
18
|
* e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'
|
|
@@ -83,7 +59,7 @@ const isPrefetchRequest = (request) => {
|
|
|
83
59
|
return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
|
|
84
60
|
};
|
|
85
61
|
const appendLocaleSearchIfNeeded = (search, locale) => {
|
|
86
|
-
if (
|
|
62
|
+
if (process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params" || effectiveMode !== "search-params") return search;
|
|
87
63
|
const params = new URLSearchParams(search ?? "");
|
|
88
64
|
params.set("locale", locale);
|
|
89
65
|
return `?${params.toString()}`;
|
|
@@ -116,7 +92,7 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
116
92
|
const localLocale = getLocalLocale(request);
|
|
117
93
|
if (noPrefix) return handleNoPrefix(request, localLocale, pathname);
|
|
118
94
|
const pathLocale = getPathLocale(pathname);
|
|
119
|
-
if (
|
|
95
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && pathLocale && domains) {
|
|
120
96
|
const localeDomain = domains[pathLocale];
|
|
121
97
|
if (localeDomain) {
|
|
122
98
|
if (normalizeDomainHostname(localeDomain) !== request.nextUrl.hostname) {
|
|
@@ -126,7 +102,7 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
126
102
|
}
|
|
127
103
|
}
|
|
128
104
|
}
|
|
129
|
-
if (
|
|
105
|
+
if (process.env["INTLAYER_ROUTING_DOMAINS"] !== "false" && !pathLocale) {
|
|
130
106
|
const domainLocale = getLocaleFromDomain(request.nextUrl.hostname);
|
|
131
107
|
if (domainLocale) return rewriteUrl(request, `/${domainLocale}${getCanonicalPath(pathname, domainLocale, rewriteRules)}` + (request.nextUrl.search ?? ""), domainLocale);
|
|
132
108
|
}
|
|
@@ -152,7 +128,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
152
128
|
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
153
129
|
return redirectUrl(request, search ? `${canonicalPath}${search}` : `${canonicalPath}${request.nextUrl.search ?? ""}`);
|
|
154
130
|
}
|
|
155
|
-
if (!
|
|
131
|
+
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") {
|
|
156
132
|
const existingLocale = new URLSearchParams(request.nextUrl.search).get("locale");
|
|
157
133
|
const isExistingValid = locales?.includes(existingLocale);
|
|
158
134
|
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ?? localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
@@ -268,7 +244,7 @@ const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
|
268
244
|
*/
|
|
269
245
|
const constructPath = (locale, path, basePath, search) => {
|
|
270
246
|
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
271
|
-
if (!
|
|
247
|
+
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "no-prefix") && effectiveMode === "no-prefix" || !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") return `${pathWithoutPrefix}${search ? `?${search}` : ""}`;
|
|
272
248
|
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
273
249
|
return `${basePath}${basePath.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`.replace(/\/+/g, "/");
|
|
274
250
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.mjs","names":["localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\n/**\n * True when the build-time routing mode is known and is NOT 'no-prefix'.\n * Use to guard no-prefix-specific code paths so bundlers can eliminate them.\n */\nconst TREE_SHAKE_NO_PREFIX =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'no-prefix';\n\n/**\n * True when the build-time routing mode is known and is NOT 'search-params'.\n */\nconst TREE_SHAKE_SEARCH_PARAMS =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'search-params';\n\n/**\n * True when the build-time routing mode is known and is not a prefix-based\n * mode (neither 'prefix-all' nor 'prefix-no-default').\n */\nconst TREE_SHAKE_PREFIX_MODES =\n process.env['INTLAYER_ROUTING_MODE'] &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-all' &&\n process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default';\n\n/**\n * True when rewrite rules are explicitly disabled at build time\n * (INTLAYER_ROUTING_REWRITE_RULES === 'false').\n */\nconst TREE_SHAKE_REWRITE =\n process.env['INTLAYER_ROUTING_REWRITE_RULES'] === 'false';\n\n/**\n * True when no domain routing is configured at build time\n * (INTLAYER_ROUTING_DOMAINS === 'false').\n */\nconst TREE_SHAKE_DOMAINS = process.env['INTLAYER_ROUTING_DOMAINS'] === 'false';\n\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\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 } = 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 (!TREE_SHAKE_NO_PREFIX && effectiveMode === 'no-prefix') ||\n (!TREE_SHAKE_SEARCH_PARAMS && effectiveMode === 'search-params');\nconst prefixDefault =\n !TREE_SHAKE_PREFIX_MODES && effectiveMode === 'prefix-all';\n\nconst internalPrefix = !noPrefix;\n\nconst rewriteRules = !TREE_SHAKE_REWRITE\n ? getRewriteRules(rewrite, 'url')\n : undefined;\n\n/**\n * Strips the protocol from a domain string and returns only the hostname.\n * e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'\n */\nconst normalizeDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or undefined if zero or more than one locale share that hostname.\n *\n * Example: with domains = { zh: 'intlayer.zh', fr: 'intlayer.org' }\n * getLocaleFromDomain('intlayer.zh') → 'zh'\n * getLocaleFromDomain('intlayer.org') → undefined (multiple locales share it)\n */\nconst getLocaleFromDomain = (hostname: string): Locale | undefined => {\n if (!domains) return undefined;\n const matching = Object.entries(domains).filter(\n ([, domain]) => normalizeDomainHostname(domain!) === hostname\n );\n return matching.length === 1 ? (matching[0][0] as Locale) : undefined;\n};\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 (TREE_SHAKE_SEARCH_PARAMS || effectiveMode !== 'search-params')\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 */\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\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 (!TREE_SHAKE_DOMAINS && pathLocale && domains) {\n const localeDomain = domains[pathLocale];\n\n if (localeDomain) {\n const domainHost = normalizeDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = /^https?:\\/\\//.test(localeDomain)\n ? localeDomain\n : `https://${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 (!TREE_SHAKE_DOMAINS && !pathLocale) {\n const domainLocale = getLocaleFromDomain(request.nextUrl.hostname);\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n const internalPath = `/${domainLocale}${canonicalPath}`;\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 * @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 getLocaleFromStorageServer({\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 (!TREE_SHAKE_SEARCH_PARAMS && 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 // 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 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 (\n (!TREE_SHAKE_NO_PREFIX && effectiveMode === 'no-prefix') ||\n (!TREE_SHAKE_SEARCH_PARAMS && effectiveMode === 'search-params')\n ) {\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 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 * @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":";;;;;;;;;;;;AAWA,MAAM,uBACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;AAK3C,MAAM,2BACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B;;;;;AAM3C,MAAM,0BACJ,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B;;;;;AAM3C,MAAM,qBACJ,QAAQ,IAAI,sCAAsC;;;;;AAMpD,MAAM,qBAAqB,QAAQ,IAAI,gCAAgC;AAkDvE,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,MAAM,SAAS,YAAY,WAAW,EAAE;AAK1D,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,WACH,CAAC,wBAAwB,kBAAkB,eAC3C,CAAC,4BAA4B,kBAAkB;AAClD,MAAM,gBACJ,CAAC,2BAA2B,kBAAkB;AAEhD,MAAM,iBAAiB,CAAC;AAExB,MAAM,eAAe,CAAC,qBAClB,gBAAgB,SAAS,MAAM,GAC/B;;;;;AAMJ,MAAM,2BAA2B,WAA2B;AAC1D,KAAI;AACF,SAAO,eAAe,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,CAAC,WAAW;SAC1D;AACN,SAAO;;;;;;;;;;;AAYX,MAAM,uBAAuB,aAAyC;AACpE,KAAI,CAAC,QAAS,QAAO;CACrB,MAAM,WAAW,OAAO,QAAQ,QAAQ,CAAC,QACtC,GAAG,YAAY,wBAAwB,O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C,CAAC,4BAA4B,kBAAkB,gBAEhD,QAAO,GAAG,oBAAoB,SAAS,IAAI,WAAW;CAIxD,MAAM,uBAAuB,KAAK,WAAW,IAAI,SAAS,GACtD,OACA,GAAG,SAAS,KAAK,WAAW,IAAI,GAAG,KAAK,MAAM;AAQlD,QAFkB,GAHC,WADW,SAAS,SAAS,IACG,GAAG,KAAK,MAAM,uBAGvC,QAAQ,QAAQ,IAE1B;;;;;;;AAQlB,MAAM,cACJ,SACA,SACA,WACiB;CACjB,MAAM,SAAS,QAAQ,QAAQ;CAC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;CAE7D,MAAM,iBAAiB,IAAI,QAAQ,QAAQ,QAAQ;AACnD,0BAAyB,QAAQ,EAC/B,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,0BAAyB,QAAQ,EAC/B,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
|
+
{"version":3,"file":"intlayerProxy.mjs","names":["localeDetector"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport { ROUTING_MODE } from '@intlayer/config/defaultValues';\n\n// ── Tree-shake constants ──────────────────────────────────────────────────────\n// When these env vars are injected at build time, bundlers eliminate the\n// branches guarded by these constants.\n\nimport {\n getCanonicalPath,\n getLocalizedPath,\n getRewriteRules,\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 } = 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 (!(\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 process.env['INTLAYER_ROUTING_MODE'] !== 'prefix-no-default'\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 * Strips the protocol from a domain string and returns only the hostname.\n * e.g. 'https://intlayer.zh' → 'intlayer.zh', 'intlayer.zh' → 'intlayer.zh'\n */\nconst normalizeDomainHostname = (domain: string): string => {\n try {\n return /^https?:\\/\\//.test(domain) ? new URL(domain).hostname : domain;\n } catch {\n return domain;\n }\n};\n\n/**\n * Returns the locale exclusively mapped to a given hostname via `routing.domains`,\n * or undefined if zero or more than one locale share that hostname.\n *\n * Example: with domains = { zh: 'intlayer.zh', fr: 'intlayer.org' }\n * getLocaleFromDomain('intlayer.zh') → 'zh'\n * getLocaleFromDomain('intlayer.org') → undefined (multiple locales share it)\n */\nconst getLocaleFromDomain = (hostname: string): Locale | undefined => {\n if (!domains) return undefined;\n const matching = Object.entries(domains).filter(\n ([, domain]) => normalizeDomainHostname(domain!) === hostname\n );\n return matching.length === 1 ? (matching[0][0] as Locale) : undefined;\n};\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 (\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 */\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\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 = normalizeDomainHostname(localeDomain);\n\n if (domainHost !== request.nextUrl.hostname) {\n const rawPath = pathname.slice(`/${pathLocale}`.length) || '/';\n const targetOrigin = /^https?:\\/\\//.test(localeDomain)\n ? localeDomain\n : `https://${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(request.nextUrl.hostname);\n\n if (domainLocale) {\n const canonicalPath = getCanonicalPath(\n pathname,\n domainLocale,\n rewriteRules\n );\n const internalPath = `/${domainLocale}${canonicalPath}`;\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 * @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 getLocaleFromStorageServer({\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 (\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 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 // 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 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 (\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 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 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 * @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":";;;;;;;;AAuDA,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,MAAM,SAAS,YAAY,WAAW,EAAE;AAK1D,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,WACH,EACC,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBAEzC,kBAAkB,eACnB,EACC,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,oBAEzC,kBAAkB;AACtB,MAAM,gBACJ,EACE,QAAQ,IAAI,4BACZ,QAAQ,IAAI,6BAA6B,gBACzC,QAAQ,IAAI,6BAA6B,wBACtC,kBAAkB;AAEzB,MAAM,iBAAiB,CAAC;AAExB,MAAM,eACJ,QAAQ,IAAI,sCAAsC,UAC9C,gBAAgB,SAAS,MAAM,GAC/B;;;;;AAMN,MAAM,2BAA2B,WAA2B;AAC1D,KAAI;AACF,SAAO,eAAe,KAAK,OAAO,GAAG,IAAI,IAAI,OAAO,CAA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,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"mappings":";;;KAYK,cAAA;EACH,QAAA,mCAIM,MAAA;IAAU,MAAA,EAAQ,aAAA;IAAe,IAAA;EAAA;AAAA;;;;;;;;AAyCzC;;;;;;;;;;;;;;;;;cAAa,SAAA;EAAa;AAAA,IAA0B,cAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _$_intlayer_types_allLocales0 from "@intlayer/types/allLocales";
|
|
2
2
|
|
|
3
3
|
//#region src/generateStaticParams.d.ts
|
|
4
4
|
/**
|
|
@@ -20,7 +20,7 @@ import { Locale } from "./intlayer/dist/types/index.js";
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
declare const generateStaticParams: () => {
|
|
23
|
-
locale: Locale;
|
|
23
|
+
locale: _$_intlayer_types_allLocales0.Locale;
|
|
24
24
|
}[];
|
|
25
25
|
//#endregion
|
|
26
26
|
export { generateStaticParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.d.ts","names":[],"sources":["../../src/generateStaticParams.ts"],"mappings":";;;;;;AAwBA;;;;;;;;;;;;;;;cAAa,oBAAA;UAAkE,MAAA;AAAA"}
|
|
1
|
+
{"version":3,"file":"generateStaticParams.d.ts","names":[],"sources":["../../src/generateStaticParams.ts"],"mappings":";;;;;;AAwBA;;;;;;;;;;;;;;;cAAa,oBAAA;UAAkE,6BAAA,CAAA,MAAA;AAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
18
18
|
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
19
19
|
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
20
20
|
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
21
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
22
21
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
23
22
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
24
23
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -87,6 +86,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
87
86
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
88
87
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
89
88
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
89
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
90
90
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
91
91
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
92
92
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -123,7 +123,6 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
123
123
|
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
124
124
|
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
125
125
|
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
126
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
127
126
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
128
127
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
129
128
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -192,6 +191,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
192
191
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
193
192
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
194
193
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
194
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
195
195
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
196
196
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
197
197
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -234,7 +234,6 @@ declare const useMarkdownContext: () => {
|
|
|
234
234
|
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
235
235
|
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
236
236
|
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
237
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
238
237
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
239
238
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
240
239
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -303,6 +302,7 @@ declare const useMarkdownContext: () => {
|
|
|
303
302
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
304
303
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
305
304
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
305
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
306
306
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
307
307
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
308
308
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -338,7 +338,6 @@ declare const useMarkdownContext: () => {
|
|
|
338
338
|
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
339
339
|
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
340
340
|
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
341
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
342
341
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
343
342
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
344
343
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -407,6 +406,7 @@ declare const useMarkdownContext: () => {
|
|
|
407
406
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
408
407
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
409
408
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
409
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
410
410
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
411
411
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
412
412
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.d.ts","names":[],"sources":["../../../src/proxy/intlayerProxy.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"intlayerProxy.d.ts","names":[],"sources":["../../../src/proxy/intlayerProxy.ts"],"mappings":";;;;;AAsLA;;;;;;;;;;;;;;;;;;;;;cAAa,aAAA,GACX,OAAA,EAAS,WAAA,EACT,MAAA,GAAS,cAAA,EACT,SAAA,GAAY,YAAA,KACX,YAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeclaredLocales } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
2
|
import { useDictionary as useDictionary$1 } from "react-intlayer/server";
|
|
3
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
4
|
|
|
5
5
|
//#region src/server/useDictionary.d.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeclaredLocales, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
2
|
import { useDictionaryAsync as useDictionaryAsync$1 } from "react-intlayer/server";
|
|
3
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
4
|
|
|
5
5
|
//#region src/server/useDictionaryAsync.d.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeclaredLocales, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
|
-
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
2
|
import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer/server";
|
|
3
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
4
4
|
|
|
5
5
|
//#region src/server/useDictionaryDynamic.d.ts
|
|
6
6
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "8.7.
|
|
3
|
+
"version": "8.7.12",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.",
|
|
6
6
|
"keywords": [
|
|
@@ -128,15 +128,15 @@
|
|
|
128
128
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
129
129
|
},
|
|
130
130
|
"dependencies": {
|
|
131
|
-
"@intlayer/chokidar": "8.7.
|
|
132
|
-
"@intlayer/config": "8.7.
|
|
133
|
-
"@intlayer/core": "8.7.
|
|
134
|
-
"@intlayer/dictionaries-entry": "8.7.
|
|
135
|
-
"@intlayer/types": "8.7.
|
|
136
|
-
"@intlayer/webpack": "8.7.
|
|
131
|
+
"@intlayer/chokidar": "8.7.12",
|
|
132
|
+
"@intlayer/config": "8.7.12",
|
|
133
|
+
"@intlayer/core": "8.7.12",
|
|
134
|
+
"@intlayer/dictionaries-entry": "8.7.12",
|
|
135
|
+
"@intlayer/types": "8.7.12",
|
|
136
|
+
"@intlayer/webpack": "8.7.12",
|
|
137
137
|
"defu": "6.1.7",
|
|
138
138
|
"node-loader": "2.1.0",
|
|
139
|
-
"react-intlayer": "8.7.
|
|
139
|
+
"react-intlayer": "8.7.12"
|
|
140
140
|
},
|
|
141
141
|
"devDependencies": {
|
|
142
142
|
"@types/node": "25.6.0",
|