next-intlayer 8.12.4 → 8.12.5-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/proxy/intlayerProxy.cjs +14 -17
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/esm/proxy/intlayerProxy.mjs +14 -17
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/types/index.d.ts +17 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -12,7 +12,7 @@ const { locales, defaultLocale } = _intlayer_config_built.internationalization ?
|
|
|
12
12
|
const { basePath, mode, rewrite, domains } = _intlayer_config_built.routing ?? {};
|
|
13
13
|
const effectiveMode = mode ?? _intlayer_config_defaultValues.ROUTING_MODE;
|
|
14
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"
|
|
15
|
+
const prefixDefault = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all") && effectiveMode === "prefix-all";
|
|
16
16
|
const internalPrefix = !noPrefix;
|
|
17
17
|
const rewriteRules = process.env["INTLAYER_ROUTING_REWRITE_RULES"] !== "false" ? (0, _intlayer_core_localization.getRewriteRules)(rewrite, "url") : void 0;
|
|
18
18
|
/**
|
|
@@ -133,7 +133,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
133
133
|
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") {
|
|
134
134
|
const existingLocale = new URLSearchParams(request.nextUrl.search).get("locale");
|
|
135
135
|
const isExistingValid = locales?.includes(existingLocale);
|
|
136
|
-
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ??
|
|
136
|
+
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ?? require_proxy_localeDetector.localeDetector?.(request) ?? defaultLocale;
|
|
137
137
|
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
138
138
|
const canonicalPath = (0, _intlayer_core_localization.getCanonicalPath)(pathname, locale, rewriteRules);
|
|
139
139
|
if (existingLocale === locale) return rewriteUrl(request, `${internalPrefix ? `/${locale}${canonicalPath}` : canonicalPath}${request.nextUrl.search ?? ""}`, locale);
|
|
@@ -153,7 +153,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
153
153
|
* @param pathname - The pathname from the request URL.
|
|
154
154
|
* @returns - The locale found in the pathname, or undefined if not found.
|
|
155
155
|
*/
|
|
156
|
-
const getPathLocale = (pathname) => locales
|
|
156
|
+
const getPathLocale = (pathname) => locales?.find((locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`);
|
|
157
157
|
/**
|
|
158
158
|
* Handles the case where URLs have locale prefixes.
|
|
159
159
|
*
|
|
@@ -182,7 +182,7 @@ const handlePrefix = (request, localLocale, pathLocale, pathname) => {
|
|
|
182
182
|
*/
|
|
183
183
|
const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
184
184
|
let locale = localLocale ?? require_proxy_localeDetector.localeDetector?.(request) ?? defaultLocale;
|
|
185
|
-
if (!locales
|
|
185
|
+
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
186
186
|
const canonicalPath = (0, _intlayer_core_localization.getCanonicalPath)(pathname, locale, rewriteRules);
|
|
187
187
|
const targetLocalizedPathResult = (0, _intlayer_core_localization.getLocalizedPath)(canonicalPath, locale, rewriteRules);
|
|
188
188
|
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
@@ -223,17 +223,13 @@ const handleExistingPathLocale = (request, pathLocale, pathname) => {
|
|
|
223
223
|
* The key fix for 404s without [locale] folders
|
|
224
224
|
*/
|
|
225
225
|
const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
235
|
-
const internalPath = internalPrefix ? `/${pathLocale}${canonicalPath}` : canonicalPath;
|
|
236
|
-
return rewriteUrl(request, searchWithLocale ? `${internalPath}${searchWithLocale}` : `${internalPath}${request.nextUrl.search ?? ""}`, pathLocale);
|
|
226
|
+
const targetLocalizedPathResult = (0, _intlayer_core_localization.getLocalizedPath)(canonicalPath, pathLocale, rewriteRules);
|
|
227
|
+
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
228
|
+
const basePathValue = basePath || "";
|
|
229
|
+
const basePathTrailingSlash = basePathValue.endsWith("/");
|
|
230
|
+
let finalPath = targetLocalizedPath;
|
|
231
|
+
if (finalPath.startsWith("/")) finalPath = finalPath.slice(1);
|
|
232
|
+
return redirectUrl(request, `${basePathValue}${basePathTrailingSlash ? "" : "/"}${finalPath}` + (appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale) ?? request.nextUrl.search ?? ""));
|
|
237
233
|
};
|
|
238
234
|
/**
|
|
239
235
|
* Constructs a new path by combining the locale, path, basePath, and search parameters.
|
|
@@ -246,9 +242,10 @@ const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
|
246
242
|
*/
|
|
247
243
|
const constructPath = (locale, path, basePath, search) => {
|
|
248
244
|
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
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
|
|
245
|
+
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 ?? ""}`;
|
|
250
246
|
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
251
|
-
|
|
247
|
+
const basePathValue = basePath || "";
|
|
248
|
+
return `${basePathValue}${basePathValue.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`.replace(/\/+/g, "/");
|
|
252
249
|
};
|
|
253
250
|
/**
|
|
254
251
|
* This handles the internal path Next.js sees.
|
|
@@ -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\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\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @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 const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.hash}`,\n request.url\n );\n\n return NextResponse.redirect(safeTarget);\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,2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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;CAE7D,MAAM,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI;CAInD,MAAM,aACJ,OAAO,WAAW,QAAQ,QAAQ,SAC9B,SACA,IAAI,IACF,GAAG,OAAO,WAAW,OAAO,SAAS,OAAO,QAC5C,QAAQ,IACT;AAEP,QAAOA,yBAAa,SAAS,WAAW"}
|
|
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 ) && 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 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[] | undefined)?.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?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n // Resolve to canonical path.\n // If user visits /a-propos (implied 'fr'), we resolve to /about\n const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);\n\n // Determine target localized path for redirection\n // /about + 'fr' -> /a-propos\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n locale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const newPath = constructPath(\n locale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n 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 // Always called with !prefixDefault && pathLocale === defaultLocale (pre-validated by caller).\n // Redirect to strip the default-locale prefix from the URL.\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const basePathValue = (basePath as string) || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? '')\n );\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n search?: string\n): string => {\n // Remove existing locale prefix from path if it was passed by mistake,\n // though we usually pass localized paths here now.\n const pathWithoutPrefix = 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 // `search` is either undefined or already has a leading '?' (from\n // appendLocaleSearchIfNeeded / request.nextUrl.search), so append as-is.\n return `${pathWithoutPrefix}${search ?? ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = path.startsWith(`/${locale}`)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathValue = basePath || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n const newPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n 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\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @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 const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.hash}`,\n request.url\n );\n\n return NextResponse.redirect(safeTarget);\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,iBACtC,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,QAAQ,IAAI,UAAU;CAC9C,MAAM,qBAAqB,QAAQ,QAA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,MAAM,cACJ,SACA,SACA,WACiB;CACjB,MAAM,SAAS,QAAQ,QAAQ;CAS/B,MAAM,gBAAiB,YAAuB;CAC9C,MAAM,eACJ,iBAAiB,CAAC,QAAQ,WAAW,cAAc,GAC/C,GAAG,gBAAgB,YACnB;CAEN,MAAM,iBACJ,UAAU,CAAC,aAAa,SAAS,IAAI,GACjC,GAAG,eAAe,WAClB;CAEN,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;CAE7D,MAAM,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI;CAInD,MAAM,aACJ,OAAO,WAAW,QAAQ,QAAQ,SAC9B,SACA,IAAI,IACF,GAAG,OAAO,WAAW,OAAO,SAAS,OAAO,QAC5C,QAAQ,IACT;AAEP,QAAOA,yBAAa,SAAS,WAAW"}
|
|
@@ -10,7 +10,7 @@ const { locales, defaultLocale } = internationalization ?? {};
|
|
|
10
10
|
const { basePath, mode, rewrite, domains } = routing ?? {};
|
|
11
11
|
const effectiveMode = mode ?? ROUTING_MODE;
|
|
12
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"
|
|
13
|
+
const prefixDefault = !(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "prefix-all") && effectiveMode === "prefix-all";
|
|
14
14
|
const internalPrefix = !noPrefix;
|
|
15
15
|
const rewriteRules = process.env["INTLAYER_ROUTING_REWRITE_RULES"] !== "false" ? getRewriteRules(rewrite, "url") : void 0;
|
|
16
16
|
/**
|
|
@@ -131,7 +131,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
131
131
|
if (!(process.env["INTLAYER_ROUTING_MODE"] && process.env["INTLAYER_ROUTING_MODE"] !== "search-params") && effectiveMode === "search-params") {
|
|
132
132
|
const existingLocale = new URLSearchParams(request.nextUrl.search).get("locale");
|
|
133
133
|
const isExistingValid = locales?.includes(existingLocale);
|
|
134
|
-
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ??
|
|
134
|
+
let locale = localLocale ?? (isExistingValid ? existingLocale : void 0) ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
135
135
|
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
136
136
|
const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);
|
|
137
137
|
if (existingLocale === locale) return rewriteUrl(request, `${internalPrefix ? `/${locale}${canonicalPath}` : canonicalPath}${request.nextUrl.search ?? ""}`, locale);
|
|
@@ -151,7 +151,7 @@ const handleNoPrefix = (request, localLocale, pathname) => {
|
|
|
151
151
|
* @param pathname - The pathname from the request URL.
|
|
152
152
|
* @returns - The locale found in the pathname, or undefined if not found.
|
|
153
153
|
*/
|
|
154
|
-
const getPathLocale = (pathname) => locales
|
|
154
|
+
const getPathLocale = (pathname) => locales?.find((locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`);
|
|
155
155
|
/**
|
|
156
156
|
* Handles the case where URLs have locale prefixes.
|
|
157
157
|
*
|
|
@@ -180,7 +180,7 @@ const handlePrefix = (request, localLocale, pathLocale, pathname) => {
|
|
|
180
180
|
*/
|
|
181
181
|
const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
182
182
|
let locale = localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
183
|
-
if (!locales
|
|
183
|
+
if (!locales?.includes(locale)) locale = defaultLocale;
|
|
184
184
|
const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);
|
|
185
185
|
const targetLocalizedPathResult = getLocalizedPath(canonicalPath, locale, rewriteRules);
|
|
186
186
|
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
@@ -221,17 +221,13 @@ const handleExistingPathLocale = (request, pathLocale, pathname) => {
|
|
|
221
221
|
* The key fix for 404s without [locale] folders
|
|
222
222
|
*/
|
|
223
223
|
const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
233
|
-
const internalPath = internalPrefix ? `/${pathLocale}${canonicalPath}` : canonicalPath;
|
|
234
|
-
return rewriteUrl(request, searchWithLocale ? `${internalPath}${searchWithLocale}` : `${internalPath}${request.nextUrl.search ?? ""}`, pathLocale);
|
|
224
|
+
const targetLocalizedPathResult = getLocalizedPath(canonicalPath, pathLocale, rewriteRules);
|
|
225
|
+
const targetLocalizedPath = typeof targetLocalizedPathResult === "string" ? targetLocalizedPathResult : targetLocalizedPathResult.path;
|
|
226
|
+
const basePathValue = basePath || "";
|
|
227
|
+
const basePathTrailingSlash = basePathValue.endsWith("/");
|
|
228
|
+
let finalPath = targetLocalizedPath;
|
|
229
|
+
if (finalPath.startsWith("/")) finalPath = finalPath.slice(1);
|
|
230
|
+
return redirectUrl(request, `${basePathValue}${basePathTrailingSlash ? "" : "/"}${finalPath}` + (appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale) ?? request.nextUrl.search ?? ""));
|
|
235
231
|
};
|
|
236
232
|
/**
|
|
237
233
|
* Constructs a new path by combining the locale, path, basePath, and search parameters.
|
|
@@ -244,9 +240,10 @@ const handleDefaultLocaleRedirect = (request, pathLocale, canonicalPath) => {
|
|
|
244
240
|
*/
|
|
245
241
|
const constructPath = (locale, path, basePath, search) => {
|
|
246
242
|
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
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
|
|
243
|
+
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 ?? ""}`;
|
|
248
244
|
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
249
|
-
|
|
245
|
+
const basePathValue = basePath || "";
|
|
246
|
+
return `${basePathValue}${basePathValue.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`.replace(/\/+/g, "/");
|
|
250
247
|
};
|
|
251
248
|
/**
|
|
252
249
|
* This handles the internal path Next.js sees.
|
|
@@ -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\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\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @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 const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.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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 ) && 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 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[] | undefined)?.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?.includes(locale as Locale)) {\n locale = defaultLocale as Locale;\n }\n\n // Resolve to canonical path.\n // If user visits /a-propos (implied 'fr'), we resolve to /about\n const canonicalPath = getCanonicalPath(pathname, locale, rewriteRules);\n\n // Determine target localized path for redirection\n // /about + 'fr' -> /a-propos\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n locale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const newPath = constructPath(\n locale,\n targetLocalizedPath,\n basePath as string,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n 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 // Always called with !prefixDefault && pathLocale === defaultLocale (pre-validated by caller).\n // Redirect to strip the default-locale prefix from the URL.\n const targetLocalizedPathResult = getLocalizedPath(\n canonicalPath,\n pathLocale,\n rewriteRules\n );\n const targetLocalizedPath =\n typeof targetLocalizedPathResult === 'string'\n ? targetLocalizedPathResult\n : targetLocalizedPathResult.path;\n\n const basePathValue = (basePath as string) || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n let finalPath = targetLocalizedPath;\n if (finalPath.startsWith('/')) finalPath = finalPath.slice(1);\n\n const fullPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${finalPath}`;\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n\n return redirectUrl(\n request,\n fullPath + (searchWithLocale ?? request.nextUrl.search ?? '')\n );\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n search?: string\n): string => {\n // Remove existing locale prefix from path if it was passed by mistake,\n // though we usually pass localized paths here now.\n const pathWithoutPrefix = 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 // `search` is either undefined or already has a leading '?' (from\n // appendLocaleSearchIfNeeded / request.nextUrl.search), so append as-is.\n return `${pathWithoutPrefix}${search ?? ''}`;\n }\n\n // Prefix handling\n const pathWithLocalePrefix = path.startsWith(`/${locale}`)\n ? path\n : `${locale}${path.startsWith('/') ? '' : '/'}${path}`;\n\n const basePathValue = basePath || '';\n const basePathTrailingSlash = basePathValue.endsWith('/');\n const newPath = `${basePathValue}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n // Clean double slashes\n const cleanPath = newPath.replace(/\\/+/g, '/');\n\n 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\n // Next.js strips `basePath` from `request.nextUrl.pathname` before the\n // middleware runs, so every path computed from it (e.g. `/en/about`) lacks\n // the basePath prefix. When we pass that as an absolute path to `new URL`,\n // it replaces the entire path after the origin, silently discarding the\n // basePath (e.g. `new URL('/en/', 'http://host/weather/')` →\n // `http://host/en/`). Prepending the configured basePath restores the\n // correct mount-point so rewrites resolve under the app root.\n const basePathValue = (basePath as string) || '';\n const pathWithBase =\n basePathValue && !newPath.startsWith(basePathValue)\n ? `${basePathValue}${newPath}`\n : newPath;\n\n const pathWithSearch =\n search && !pathWithBase.includes('?')\n ? `${pathWithBase}${search}`\n : pathWithBase;\n\n const requestHeaders = new Headers(request.headers);\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n requestHeaders.set(name, value);\n },\n });\n\n const targetUrl = new URL(pathWithSearch, request.url);\n\n // If the target URL is exactly the current request URL,\n // we just want to `next()` to avoid losing headers on a redundant rewrite.\n const response =\n targetUrl.href === request.nextUrl.href\n ? NextResponse.next({\n request: {\n headers: requestHeaders,\n },\n })\n : NextResponse.rewrite(targetUrl, {\n request: {\n headers: requestHeaders,\n },\n });\n\n setLocaleInStorageServer(locale, {\n setHeader: (name: string, value: string) => {\n response.headers.set(name, value);\n },\n });\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @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 const target = new URL(pathWithSearch, request.url);\n\n // Prevent open redirect: if the resolved origin differs from the request\n // origin, strip it back to a same-origin URL using only the path/search/hash.\n const safeTarget =\n target.origin === request.nextUrl.origin\n ? target\n : new URL(\n `${target.pathname}${target.search}${target.hash}`,\n request.url\n );\n\n return NextResponse.redirect(safeTarget);\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,iBACt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P,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;CAE7D,MAAM,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI;CAInD,MAAM,aACJ,OAAO,WAAW,QAAQ,QAAQ,SAC9B,SACA,IAAI,IACF,GAAG,OAAO,WAAW,OAAO,SAAS,OAAO,QAC5C,QAAQ,IACT;AAEP,QAAO,aAAa,SAAS,WAAW"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,10 +16,6 @@ import * as _$react_intlayer_markdown0 from "react-intlayer/markdown";
|
|
|
16
16
|
declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptions & {
|
|
17
17
|
components?: {} & {
|
|
18
18
|
object?: _$react.FC<_$react.DetailedHTMLProps<_$react.ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>>;
|
|
19
|
-
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
20
|
-
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
21
|
-
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
22
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
23
19
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
24
20
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
25
21
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -73,6 +69,8 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
73
69
|
thead?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
74
70
|
tbody?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
75
71
|
tfoot?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
72
|
+
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
73
|
+
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
76
74
|
td?: _$react.FC<_$react.DetailedHTMLProps<_$react.TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>>;
|
|
77
75
|
caption?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
78
76
|
colgroup?: _$react.FC<_$react.DetailedHTMLProps<_$react.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>>;
|
|
@@ -88,6 +86,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
88
86
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
89
87
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
90
88
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
89
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
91
90
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
92
91
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
93
92
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -106,6 +105,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
106
105
|
summary?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
107
106
|
dialog?: _$react.FC<_$react.DetailedHTMLProps<_$react.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>>;
|
|
108
107
|
br?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBRElement>, HTMLBRElement>>;
|
|
108
|
+
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
109
109
|
wbr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
110
110
|
ruby?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
111
111
|
rt?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
@@ -121,10 +121,6 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
121
121
|
wrapper?: _$react.FC<_$react.HTMLAttributes<HTMLElement>>;
|
|
122
122
|
renderMarkdown?: (markdown: string | _$react_intlayer_markdown0.ParsedMarkdown, options?: index_d_exports.MarkdownProviderOptions, components?: {} & {
|
|
123
123
|
object?: _$react.FC<_$react.DetailedHTMLProps<_$react.ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>>;
|
|
124
|
-
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
125
|
-
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
126
|
-
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
127
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
128
124
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
129
125
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
130
126
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -178,6 +174,8 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
178
174
|
thead?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
179
175
|
tbody?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
180
176
|
tfoot?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
177
|
+
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
178
|
+
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
181
179
|
td?: _$react.FC<_$react.DetailedHTMLProps<_$react.TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>>;
|
|
182
180
|
caption?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
183
181
|
colgroup?: _$react.FC<_$react.DetailedHTMLProps<_$react.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>>;
|
|
@@ -193,6 +191,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
193
191
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
194
192
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
195
193
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
194
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
196
195
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
197
196
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
198
197
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -211,6 +210,7 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
211
210
|
summary?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
212
211
|
dialog?: _$react.FC<_$react.DetailedHTMLProps<_$react.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>>;
|
|
213
212
|
br?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBRElement>, HTMLBRElement>>;
|
|
213
|
+
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
214
214
|
wbr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
215
215
|
ruby?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
216
216
|
rt?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
@@ -232,10 +232,6 @@ declare const MarkdownProvider: _$react.FC<index_d_exports.MarkdownProviderOptio
|
|
|
232
232
|
declare const useMarkdownContext: () => {
|
|
233
233
|
components?: {} & {
|
|
234
234
|
object?: _$react.FC<_$react.DetailedHTMLProps<_$react.ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>>;
|
|
235
|
-
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
236
|
-
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
237
|
-
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
238
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
239
235
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
240
236
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
241
237
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -289,6 +285,8 @@ declare const useMarkdownContext: () => {
|
|
|
289
285
|
thead?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
290
286
|
tbody?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
291
287
|
tfoot?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
288
|
+
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
289
|
+
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
292
290
|
td?: _$react.FC<_$react.DetailedHTMLProps<_$react.TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>>;
|
|
293
291
|
caption?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
294
292
|
colgroup?: _$react.FC<_$react.DetailedHTMLProps<_$react.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>>;
|
|
@@ -304,6 +302,7 @@ declare const useMarkdownContext: () => {
|
|
|
304
302
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
305
303
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
306
304
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
305
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
307
306
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
308
307
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
309
308
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -322,6 +321,7 @@ declare const useMarkdownContext: () => {
|
|
|
322
321
|
summary?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
323
322
|
dialog?: _$react.FC<_$react.DetailedHTMLProps<_$react.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>>;
|
|
324
323
|
br?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBRElement>, HTMLBRElement>>;
|
|
324
|
+
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
325
325
|
wbr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
326
326
|
ruby?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
327
327
|
rt?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
@@ -336,10 +336,6 @@ declare const useMarkdownContext: () => {
|
|
|
336
336
|
};
|
|
337
337
|
renderMarkdown: (markdown: string | _$react_intlayer_markdown0.ParsedMarkdown, options?: index_d_exports.MarkdownProviderOptions, components?: {} & {
|
|
338
338
|
object?: _$react.FC<_$react.DetailedHTMLProps<_$react.ObjectHTMLAttributes<HTMLObjectElement>, HTMLObjectElement>>;
|
|
339
|
-
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
340
|
-
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
341
|
-
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
342
|
-
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
343
339
|
html?: _$react.FC<_$react.DetailedHTMLProps<_$react.HtmlHTMLAttributes<HTMLHtmlElement>, HTMLHtmlElement>>;
|
|
344
340
|
head?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHeadElement>, HTMLHeadElement>>;
|
|
345
341
|
body?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBodyElement>, HTMLBodyElement>>;
|
|
@@ -393,6 +389,8 @@ declare const useMarkdownContext: () => {
|
|
|
393
389
|
thead?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
394
390
|
tbody?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
395
391
|
tfoot?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>>;
|
|
392
|
+
tr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>>;
|
|
393
|
+
th?: _$react.FC<_$react.DetailedHTMLProps<_$react.ThHTMLAttributes<HTMLTableHeaderCellElement>, HTMLTableHeaderCellElement>>;
|
|
396
394
|
td?: _$react.FC<_$react.DetailedHTMLProps<_$react.TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>>;
|
|
397
395
|
caption?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
398
396
|
colgroup?: _$react.FC<_$react.DetailedHTMLProps<_$react.ColgroupHTMLAttributes<HTMLTableColElement>, HTMLTableColElement>>;
|
|
@@ -408,6 +406,7 @@ declare const useMarkdownContext: () => {
|
|
|
408
406
|
fieldset?: _$react.FC<_$react.DetailedHTMLProps<_$react.FieldsetHTMLAttributes<HTMLFieldSetElement>, HTMLFieldSetElement>>;
|
|
409
407
|
legend?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLLegendElement>, HTMLLegendElement>>;
|
|
410
408
|
datalist?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLDataListElement>, HTMLDataListElement>>;
|
|
409
|
+
output?: _$react.FC<_$react.DetailedHTMLProps<_$react.OutputHTMLAttributes<HTMLOutputElement>, HTMLOutputElement>>;
|
|
411
410
|
progress?: _$react.FC<_$react.DetailedHTMLProps<_$react.ProgressHTMLAttributes<HTMLProgressElement>, HTMLProgressElement>>;
|
|
412
411
|
meter?: _$react.FC<_$react.DetailedHTMLProps<_$react.MeterHTMLAttributes<HTMLMeterElement>, HTMLMeterElement>>;
|
|
413
412
|
img?: _$react.FC<_$react.DetailedHTMLProps<_$react.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>>;
|
|
@@ -426,6 +425,7 @@ declare const useMarkdownContext: () => {
|
|
|
426
425
|
summary?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
427
426
|
dialog?: _$react.FC<_$react.DetailedHTMLProps<_$react.DialogHTMLAttributes<HTMLDialogElement>, HTMLDialogElement>>;
|
|
428
427
|
br?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLBRElement>, HTMLBRElement>>;
|
|
428
|
+
hr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLHRElement>, HTMLHRElement>>;
|
|
429
429
|
wbr?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
430
430
|
ruby?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
431
431
|
rt?: _$react.FC<_$react.DetailedHTMLProps<_$react.HTMLAttributes<HTMLElement>, HTMLElement>>;
|
|
@@ -464,7 +464,7 @@ declare const useMarkdownRenderer: ({
|
|
|
464
464
|
forceInline,
|
|
465
465
|
preserveFrontmatter,
|
|
466
466
|
tagfilter
|
|
467
|
-
}?: index_d_exports.RenderMarkdownProps) => (content: string | _$react_intlayer_markdown0.ParsedMarkdown) => string | number | bigint | boolean | Iterable<_$react.ReactNode> | _$react.
|
|
467
|
+
}?: index_d_exports.RenderMarkdownProps) => (content: string | _$react_intlayer_markdown0.ParsedMarkdown) => string | number | bigint | boolean | Iterable<_$react.ReactNode> | Promise<_$react.ReactNode> | _$react.JSX.Element;
|
|
468
468
|
/**
|
|
469
469
|
* @deprecated import from next-intlayer/markdown instead
|
|
470
470
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;cAiDa,gBAAA,UAAgB,EAAA,CAAA,eAAA,CAAA,uBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4FAAD,eAAA,CAAA,uBAAA,EAAA,UAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAE2B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IAAA,OAAA,CAAA,OAAA,CAAA,SAAA,IAAA,OAAA,CAAA,GAAA,CAAA,OAAA;;;;cAInB,gBAAA,EAAgB,OAAA,CAAA,EAAA,CAAA,eAAA,CAAA,qBAAA;;;;KAIjB,mBAAA,GAAsB,eAAA,CAAA,mBAAA;;;;KAItB,qBAAA,GAAwB,eAAA,CAAA,qBAAA"}
|
|
@@ -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":";;;;;AAqLA;;;;;;;;;;;;;;;;;;;;;cAAa,aAAA,GACX,OAAA,EAAS,WAAA,EACT,MAAA,GAAS,cAAA,EACT,SAAA,GAAY,YAAA,KACX,YAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.5-canary.0",
|
|
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": [
|
|
@@ -133,15 +133,15 @@
|
|
|
133
133
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@intlayer/chokidar": "8.12.
|
|
137
|
-
"@intlayer/config": "8.12.
|
|
138
|
-
"@intlayer/core": "8.12.
|
|
139
|
-
"@intlayer/dictionaries-entry": "8.12.
|
|
140
|
-
"@intlayer/types": "8.12.
|
|
141
|
-
"@intlayer/webpack": "8.12.
|
|
136
|
+
"@intlayer/chokidar": "8.12.5-canary.0",
|
|
137
|
+
"@intlayer/config": "8.12.5-canary.0",
|
|
138
|
+
"@intlayer/core": "8.12.5-canary.0",
|
|
139
|
+
"@intlayer/dictionaries-entry": "8.12.5-canary.0",
|
|
140
|
+
"@intlayer/types": "8.12.5-canary.0",
|
|
141
|
+
"@intlayer/webpack": "8.12.5-canary.0",
|
|
142
142
|
"defu": "6.1.7",
|
|
143
143
|
"node-loader": "2.1.0",
|
|
144
|
-
"react-intlayer": "8.12.
|
|
144
|
+
"react-intlayer": "8.12.5-canary.0"
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
147
|
"@types/node": "25.9.2",
|