next-intlayer 5.1.8 → 5.2.1

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.
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,14 +17,22 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var generateStaticParams_exports = {};
20
30
  __export(generateStaticParams_exports, {
21
31
  generateStaticParams: () => generateStaticParams
22
32
  });
23
33
  module.exports = __toCommonJS(generateStaticParams_exports);
24
- var import_client = require("@intlayer/config/client");
25
- const { locales } = (0, import_client.getConfiguration)().internationalization;
34
+ var import_built = __toESM(require("@intlayer/config/built"));
35
+ const { locales } = import_built.default.internationalization;
26
36
  const generateStaticParams = () => locales.map((locale) => ({ locale }));
27
37
  // Annotate the CommonJS export names for ESM import in node:
28
38
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\n\nconst { locales } = getConfiguration().internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,MAAM,EAAE,QAAQ,QAAI,gCAAiB,EAAE;AAEhC,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
1
+ {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,MAAM,EAAE,QAAQ,IAAI,aAAAA,QAAc;AAE3B,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":["configuration"]}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,16 +17,24 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var intlayerMiddleware_exports = {};
20
30
  __export(intlayerMiddleware_exports, {
21
31
  intlayerMiddleware: () => intlayerMiddleware
22
32
  });
23
33
  module.exports = __toCommonJS(intlayerMiddleware_exports);
24
- var import_client = require("@intlayer/config/client");
34
+ var import_built = __toESM(require("@intlayer/config/built"));
25
35
  var import_server = require("next/server");
26
36
  var import_localeDetector = require('./localeDetector.cjs');
27
- const { internationalization, middleware } = (0, import_client.getConfiguration)();
37
+ const { internationalization, middleware } = import_built.default;
28
38
  const { locales, defaultLocale } = internationalization;
29
39
  const {
30
40
  headerName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = getConfiguration();\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware 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 intlayerMiddleware = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - 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 rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n return rewriteUrl(request, newPath, 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): Locales | undefined =>\n locales.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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\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 cookieLocale - 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 handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\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 rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n return rewriteUrl(request, pathname, 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 basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\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 NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,oBAIO;AACP,4BAA+B;AAE/B,MAAM,EAAE,sBAAsB,WAAW,QAAI,gCAAiB;AAC9D,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAyBG,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MACE,UACA;AACA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AClE,MAAI,QAAQ;AACV,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAUA,MAAM,aAAa,CACjB,SACA,SACA,WACiB;AACjB,QAAM,WAAW,2BAAa,QAAQ,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YACzC,2BAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["basePath"]}
1
+ {"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = configuration;\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware 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 intlayerMiddleware = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - 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 rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n return rewriteUrl(request, newPath, 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): Locales | undefined =>\n locales.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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = (cookieLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locales;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\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 cookieLocale - 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 handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\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 rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n return rewriteUrl(request, pathname, 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 basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\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 NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA0B;AAE1B,oBAIO;AACP,4BAA+B;AAE/B,MAAM,EAAE,sBAAsB,WAAW,IAAI,aAAAA;AAC7C,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAyBG,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MACE,UACA;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,I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MAAM,aAAa,CACjB,SACA,SACA,WACiB;AACjB,QAAM,WAAW,2BAAa,QAAQ,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YACzC,2BAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["configuration","basePath"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): Locales => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAqD;AAQ9C,MAAM,iBAAiB,CAAC,YAAkC;AAC/D,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,aAAS,YAAAA,gBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":["localeDetectorCore"]}
1
+ {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): LocalesValues => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAqD;AAQ9C,MAAM,iBAAiB,CAAC,YAAwC;AACrE,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,aAAS,YAAAA,gBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":["localeDetectorCore"]}
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var withIntlayer_exports = {};
30
20
  __export(withIntlayer_exports, {
@@ -34,8 +24,8 @@ module.exports = __toCommonJS(withIntlayer_exports);
34
24
  var import_path = require("path");
35
25
  var import_config = require("@intlayer/config");
36
26
  var import_webpack = require("@intlayer/webpack");
37
- var import_package = __toESM(require("next/package.json"));
38
- const nextMajorVersion = parseInt(import_package.default.version.split(".")[0], 10);
27
+ const nextPkg = (0, import_config.ESMxCJSRequire)("next/package.json");
28
+ const nextMajorVersion = parseInt(nextPkg.version.split(".")[0], 10);
39
29
  const isTurbopackEnabled = process.env.npm_lifecycle_script?.includes("--turbo");
40
30
  const withIntlayer = (nextConfig = {}) => {
41
31
  if (typeof nextConfig !== "object") {
@@ -43,15 +33,18 @@ const withIntlayer = (nextConfig = {}) => {
43
33
  }
44
34
  const intlayerConfig = (0, import_config.getConfiguration)();
45
35
  const env = (0, import_config.formatEnvVariable)("next");
46
- const { mainDir, baseDir } = intlayerConfig.content;
36
+ const { mainDir, configDir, baseDir } = intlayerConfig.content;
47
37
  const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.mjs");
48
38
  const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
39
+ const configurationPath = (0, import_path.join)(configDir, "configuration.json");
40
+ const relativeConfigurationPath = (0, import_path.relative)(baseDir, configurationPath);
49
41
  const turboConfig = isTurbopackEnabled ? {
50
42
  turbo: {
51
43
  ...nextConfig.experimental?.turbo ?? {},
52
44
  resolveAlias: {
53
45
  ...nextConfig.experimental?.turbo?.resolveAlias ?? {},
54
- "@intlayer/dictionaries-entry": relativeDictionariesPath
46
+ "@intlayer/dictionaries-entry": relativeDictionariesPath,
47
+ "@intlayer/config/built": relativeConfigurationPath
55
48
  },
56
49
  rules: {
57
50
  "*.node": {
@@ -86,6 +79,9 @@ const withIntlayer = (nextConfig = {}) => {
86
79
  config.resolve.alias["@intlayer/dictionaries-entry"] = (0, import_path.resolve)(
87
80
  relativeDictionariesPath
88
81
  );
82
+ config.resolve.alias["@intlayer/config/built"] = (0, import_path.resolve)(
83
+ relativeConfigurationPath
84
+ );
89
85
  config.externals.push({
90
86
  esbuild: "esbuild",
91
87
  module: "module",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPkg from 'next/package.json' with { type: 'json' };\n\nconst nextMajorVersion = parseInt(nextPkg.version.split('.')[0], 10);\n\n// Extract from the start script if --turbo or --turbopack flag is used\nconst isTurbopackEnabled =\n process.env.npm_lifecycle_script?.includes('--turbo');\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n */\nexport const withIntlayer = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration();\n\n // Format all configuration values as environment variables\n const env = formatEnvVariable('next');\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = isTurbopackEnabled\n ? {\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': relativeDictionariesPath,\n },\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n }\n : {};\n\n const newConfig: Partial<NextConfig> = {\n // Merge environment variables\n env: { ...nextConfig.env, ...env },\n\n // Only add `serverExternalPackages` if Next.js is v15+\n ...(nextMajorVersion >= 15\n ? {\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n }\n : {}),\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n ...turboConfig,\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Alias the dictionary entry for all builds\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin());\n }\n\n return config;\n },\n };\n\n // Merge the new config with the user's config\n return { ...nextConfig, ...newConfig };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AACxC,oBAAoD;AACpD,qBAA+B;AAG/B,qBAAoB;AAEpB,MAAM,mBAAmB,SAAS,eAAAA,QAAQ,QAAQ,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE;AAGnE,MAAM,qBACJ,QAAQ,IAAI,sBAAsB,SAAS,SAAS;AAe/C,MAAM,eAAe,CAC1B,aAAgB,CAAC,MACE;AACnB,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,CAAC;AAAA,EAChB;AAEA,QAAM,qBAAiB,gCAAiB;AAGxC,QAAM,UAAM,iCAAkB,MAAM;AACpC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,QAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,QAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAGnE,QAAM,cAAc,qBAChB;AAAA,IACE,OAAO;AAAA,MACL,GAAI,WAAW,cAAc,SAAS,CAAC;AAAA,MACvC,cAAc;AAAA,QACZ,GAAI,WAAW,cAAc,OAAO,gBAAgB,CAAC;AAAA,QACrD,gCAAgC;AAAA,MAClC;AAAA,MACA,OAAO;AAAA,QACL,UAAU;AAAA,UACR,IAAI;AAAA,UACJ,SAAS,CAAC,aAAa;AAAA,QACzB;AAAA,MACF;AAAA,IACF;AAAA,EACF,IACA,CAAC;AAEL,QAAM,YAAiC;AAAA;AAAA,IAErC,KAAK,EAAE,GAAG,WAAW,KAAK,GAAG,IAAI;AAAA;AAAA,IAGjC,GAAI,oBAAoB,KACpB;AAAA,MACE,wBAAwB;AAAA,QACtB,GAAI,WAAW,0BAA0B,CAAC;AAAA,QAC1C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,IACA,CAAC;AAAA,IAEL,cAAc;AAAA,MACZ,GAAI,WAAW,gBAAgB,CAAC;AAAA,MAChC,GAAG;AAAA,IACL;AAAA,IAEA,SAAS,CAAC,QAA4B,YAA8B;AAElE,UAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,iBAAS,WAAW,QAAQ,QAAQ,OAAO;AAAA,MAC7C;AAGA,aAAO,QAAQ,MAAM,8BAA8B,QAAI;AAAA,QACrD;AAAA,MACF;AAGA,aAAO,UAAU,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,UAAU;AAAA,MACZ,CAAC;AAGD,aAAO,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAGD,YAAM,EAAE,UAAU,YAAY,IAAI;AAElC,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,8BAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,EAAE,GAAG,YAAY,GAAG,UAAU;AACvC;","names":["nextPkg"]}
1
+ {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport {\n getConfiguration,\n formatEnvVariable,\n ESMxCJSRequire,\n} from '@intlayer/config';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\n\nconst nextPkg = ESMxCJSRequire('next/package.json');\n\nconst nextMajorVersion = parseInt(nextPkg.version.split('.')[0], 10);\n\n// Extract from the start script if --turbo or --turbopack flag is used\nconst isTurbopackEnabled =\n process.env.npm_lifecycle_script?.includes('--turbo');\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n */\nexport const withIntlayer = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration();\n\n // Format all configuration values as environment variables\n const env = formatEnvVariable('next');\n const { mainDir, configDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n const configurationPath = join(configDir, 'configuration.json');\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = isTurbopackEnabled\n ? {\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': relativeDictionariesPath,\n '@intlayer/config/built': relativeConfigurationPath,\n },\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n }\n : {};\n\n const newConfig: Partial<NextConfig> = {\n // Merge environment variables\n env: { ...nextConfig.env, ...env },\n\n // Only add `serverExternalPackages` if Next.js is v15+\n ...(nextMajorVersion >= 15\n ? {\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n }\n : {}),\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n ...turboConfig,\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Alias the dictionary entry for all builds\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n config.resolve.alias['@intlayer/config/built'] = resolve(\n relativeConfigurationPath\n );\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin());\n }\n\n return config;\n },\n };\n\n // Merge the new config with the user's config\n return { ...nextConfig, ...newConfig };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AACxC,oBAIO;AACP,qBAA+B;AAI/B,MAAM,cAAU,8BAAe,mBAAmB;AAElD,MAAM,mBAAmB,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE;AAGnE,MAAM,qBACJ,QAAQ,IAAI,sBAAsB,SAAS,SAAS;AAe/C,MAAM,eAAe,CAC1B,aAAgB,CAAC,MACE;AACnB,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,CAAC;AAAA,EAChB;AAEA,QAAM,qBAAiB,gCAAiB;AAGxC,QAAM,UAAM,iCAAkB,MAAM;AACpC,QAAM,EAAE,SAAS,WAAW,QAAQ,IAAI,eAAe;AAEvD,QAAM,uBAAmB,kBAAK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O,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAGD,YAAM,EAAE,UAAU,YAAY,IAAI;AAElC,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,8BAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,EAAE,GAAG,YAAY,GAAG,UAAU;AACvC;","names":[]}
@@ -1,5 +1,5 @@
1
- import { getConfiguration } from "@intlayer/config/client";
2
- const { locales } = getConfiguration().internationalization;
1
+ import configuration from "@intlayer/config/built";
2
+ const { locales } = configuration.internationalization;
3
3
  const generateStaticParams = () => locales.map((locale) => ({ locale }));
4
4
  export {
5
5
  generateStaticParams
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\n\nconst { locales } = getConfiguration().internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"AAAA,SAAS,wBAAwB;AAEjC,MAAM,EAAE,QAAQ,IAAI,iBAAiB,EAAE;AAEhC,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
1
+ {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,MAAM,EAAE,QAAQ,IAAI,cAAc;AAE3B,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
@@ -1,9 +1,9 @@
1
- import { getConfiguration } from "@intlayer/config/client";
1
+ import configuration from "@intlayer/config/built";
2
2
  import {
3
3
  NextResponse
4
4
  } from "next/server";
5
5
  import { localeDetector } from "./localeDetector.mjs";
6
- const { internationalization, middleware } = getConfiguration();
6
+ const { internationalization, middleware } = configuration;
7
7
  const { locales, defaultLocale } = internationalization;
8
8
  const {
9
9
  headerName,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = getConfiguration();\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware 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 intlayerMiddleware = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - 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 rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n return rewriteUrl(request, newPath, 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): Locales | undefined =>\n locales.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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\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 cookieLocale - 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 handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\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 rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n return rewriteUrl(request, pathname, 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 basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\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 NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C;AAAA,EAGE;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,MAAM,EAAE,sBAAsB,WAAW,IAAI,iBAAiB;AAC9D,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAyBG,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MACE,UACA;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,QAAQ;AAEzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQA,MAAM,kBAAkB,CAAC,YAA8C;AACrE,MAAI,CAAC,WAAY,QAAO;AACxB,QAAM,cAAc,QAAQ,QAAQ,IAAI,UAAU,GAAG;AACrD,MAAI,eAAe,QAAQ,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3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport configuration from '@intlayer/config/built';\n\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = configuration;\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware 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 intlayerMiddleware = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - 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 rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n return rewriteUrl(request, newPath, 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): Locales | undefined =>\n locales.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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - 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 cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = (cookieLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locales;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\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 cookieLocale - 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 handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\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 cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\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 rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n return rewriteUrl(request, pathname, 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 basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\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 NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":"AACA,OAAO,mBAAmB;AAE1B;AAAA,EAGE;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,MAAM,EAAE,sBAAsB,WAAW,IAAI;AAC7C,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAyBG,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MACE,UACA;AACA,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,QAAQ;AAEzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAQA,MAAM,kBAAkB,CAAC,YAA8C;AACrE,MAAI,CAAC,WAAY,QAAO;AACxB,QAAM,cAAc,QAAQ,QAAQ,IAAI,UAAU,GAAG;AACrD,MAAI,eAAe,QAAQ,SAAS,WAAW,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAWA,MAAM,iBAAiB,CACrB,SACA,cACA,UACA,0BACiB;AACjB,QA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6BAA6B,CACjC,SACA,UACA,YACA,cACAA,WACA,0BACW;AAEX,QAAM,UAAU,SAAS,QAAQ,IAAI,UAAU,IAAI,IAAI,YAAY,EAAE;AAErE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACAA;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,EAClB;AACF;AAWA,MAAM,8BAA8B,CAClC,SACA,YACA,UACA,0BACiB;AACjB;AAAA;AAAA,IAEE,CAAC,iBACD,eAAe;AAAA,IACf;AACA,QAAI,oBAAoB,SAAS,MAAM,IAAI,UAAU,GAAG,MAAM,KAAK;AAEnE,QAAI,uBAAuB;AACzB,0BAAoB,kBAAkB,MAAM,CAAC;AAAA,IAC/C;AAEA,QAAI,QAAQ,QAAQ,QAAQ;AAC1B,2BAAqB,QAAQ,QAAQ;AAAA,IACvC;AAEA,WAAO,WAAW,SAAS,GAAG,QAAQ,GAAG,iBAAiB,IAAI,UAAU;AAAA,EAC1E;AAIA,SAAO,WAAW,SAAS,UAAU,UAAU;AACjD;AAYA,MAAM,gBAAgB,CACpB,QACA,MACAA,WACA,uBACA,WACW;AACX,MAAI,UAAU,GAAG,MAAM,GAAG,IAAI;AAE9B,YAAU,GAAGA,SAAQ,GAAG,wBAAwB,KAAK,GAAG,GAAG,OAAO;AAClE,MAAI,QAAQ;AACV,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAUA,MAAM,aAAa,CACjB,SACA,SACA,WACiB;AACjB,QAAM,WAAW,aAAa,QAAQ,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YACzC,aAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["basePath"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): Locales => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":"AACA,SAAS,kBAAkB,0BAA0B;AAQ9C,MAAM,iBAAiB,CAAC,YAAkC;AAC/D,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,SAAS,mBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): LocalesValues => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":"AACA,SAAS,kBAAkB,0BAA0B;AAQ9C,MAAM,iBAAiB,CAAC,YAAwC;AACrE,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,SAAS,mBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":[]}
@@ -1,7 +1,11 @@
1
1
  import { resolve, relative, join } from "path";
2
- import { getConfiguration, formatEnvVariable } from "@intlayer/config";
2
+ import {
3
+ getConfiguration,
4
+ formatEnvVariable,
5
+ ESMxCJSRequire
6
+ } from "@intlayer/config";
3
7
  import { IntlayerPlugin } from "@intlayer/webpack";
4
- import nextPkg from "next/package.json" with { type: "json" };
8
+ const nextPkg = ESMxCJSRequire("next/package.json");
5
9
  const nextMajorVersion = parseInt(nextPkg.version.split(".")[0], 10);
6
10
  const isTurbopackEnabled = process.env.npm_lifecycle_script?.includes("--turbo");
7
11
  const withIntlayer = (nextConfig = {}) => {
@@ -10,15 +14,18 @@ const withIntlayer = (nextConfig = {}) => {
10
14
  }
11
15
  const intlayerConfig = getConfiguration();
12
16
  const env = formatEnvVariable("next");
13
- const { mainDir, baseDir } = intlayerConfig.content;
17
+ const { mainDir, configDir, baseDir } = intlayerConfig.content;
14
18
  const dictionariesPath = join(mainDir, "dictionaries.mjs");
15
19
  const relativeDictionariesPath = relative(baseDir, dictionariesPath);
20
+ const configurationPath = join(configDir, "configuration.json");
21
+ const relativeConfigurationPath = relative(baseDir, configurationPath);
16
22
  const turboConfig = isTurbopackEnabled ? {
17
23
  turbo: {
18
24
  ...nextConfig.experimental?.turbo ?? {},
19
25
  resolveAlias: {
20
26
  ...nextConfig.experimental?.turbo?.resolveAlias ?? {},
21
- "@intlayer/dictionaries-entry": relativeDictionariesPath
27
+ "@intlayer/dictionaries-entry": relativeDictionariesPath,
28
+ "@intlayer/config/built": relativeConfigurationPath
22
29
  },
23
30
  rules: {
24
31
  "*.node": {
@@ -53,6 +60,9 @@ const withIntlayer = (nextConfig = {}) => {
53
60
  config.resolve.alias["@intlayer/dictionaries-entry"] = resolve(
54
61
  relativeDictionariesPath
55
62
  );
63
+ config.resolve.alias["@intlayer/config/built"] = resolve(
64
+ relativeConfigurationPath
65
+ );
56
66
  config.externals.push({
57
67
  esbuild: "esbuild",
58
68
  module: "module",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPkg from 'next/package.json' with { type: 'json' };\n\nconst nextMajorVersion = parseInt(nextPkg.version.split('.')[0], 10);\n\n// Extract from the start script if --turbo or --turbopack flag is used\nconst isTurbopackEnabled =\n process.env.npm_lifecycle_script?.includes('--turbo');\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n */\nexport const withIntlayer = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration();\n\n // Format all configuration values as environment variables\n const env = formatEnvVariable('next');\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = isTurbopackEnabled\n ? {\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': relativeDictionariesPath,\n },\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n }\n : {};\n\n const newConfig: Partial<NextConfig> = {\n // Merge environment variables\n env: { ...nextConfig.env, ...env },\n\n // Only add `serverExternalPackages` if Next.js is v15+\n ...(nextMajorVersion >= 15\n ? {\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n }\n : {}),\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n ...turboConfig,\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Alias the dictionary entry for all builds\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin());\n }\n\n return config;\n },\n };\n\n // Merge the new config with the user's config\n return { ...nextConfig, ...newConfig };\n};\n"],"mappings":"AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,sBAAsB;AAG/B,OAAO,aAAa,oBAAoB,KAAK,EAAE,MAAM,OAAO;AAE5D,MAAM,mBAAmB,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE;AAGnE,MAAM,qBACJ,QAAQ,IAAI,sBAAsB,SAAS,SAAS;AAe/C,MAAM,eAAe,CAC1B,aAAgB,CAAC,MACE;AACnB,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,CAAC;AAAA,EAChB;AAEA,QAAM,iBAAiB,iBAAiB;AAGxC,QAAM,MAAM,kBAAkB,MAAM;AACpC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,QAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,QAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAGnE,QAAM,cAAc,qBAChB;AAAA,IACE,OAAO;AAAA,MACL,GAAI,WAAW,cAAc,SAAS,CAAC;AAAA,MACvC,cAAc;AAAA,QACZ,GAAI,WAAW,cAAc,OAAO,gBAAgB,CAAC;AAAA,QACrD,gCAAgC;AAAA,MAClC;AAAA,MACA,OAAO;AAAA,QACL,UAAU;AAAA,UACR,IAAI;AAAA,UACJ,SAAS,CAAC,aAAa;AAAA,QACzB;AAAA,MACF;AAAA,IACF;AAAA,EACF,IACA,CAAC;AAEL,QAAM,YAAiC;AAAA;AAAA,IAErC,KAAK,EAAE,GAAG,WAAW,KAAK,GAAG,IAAI;AAAA;AAAA,IAGjC,GAAI,oBAAoB,KACpB;AAAA,MACE,wBAAwB;AAAA,QACtB,GAAI,WAAW,0BAA0B,CAAC;AAAA,QAC1C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF,IACA,CAAC;AAAA,IAEL,cAAc;AAAA,MACZ,GAAI,WAAW,gBAAgB,CAAC;AAAA,MAChC,GAAG;AAAA,IACL;AAAA,IAEA,SAAS,CAAC,QAA4B,YAA8B;AAElE,UAAI,OAAO,WAAW,YAAY,YAAY;AAC5C,iBAAS,WAAW,QAAQ,QAAQ,OAAO;AAAA,MAC7C;AAGA,aAAO,QAAQ,MAAM,8BAA8B,IAAI;AAAA,QACrD;AAAA,MACF;AAGA,aAAO,UAAU,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,UAAU;AAAA,MACZ,CAAC;AAGD,aAAO,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAGD,YAAM,EAAE,UAAU,YAAY,IAAI;AAElC,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,eAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,EAAE,GAAG,YAAY,GAAG,UAAU;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport {\n getConfiguration,\n formatEnvVariable,\n ESMxCJSRequire,\n} from '@intlayer/config';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\n\nconst nextPkg = ESMxCJSRequire('next/package.json');\n\nconst nextMajorVersion = parseInt(nextPkg.version.split('.')[0], 10);\n\n// Extract from the start script if --turbo or --turbopack flag is used\nconst isTurbopackEnabled =\n process.env.npm_lifecycle_script?.includes('--turbo');\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n */\nexport const withIntlayer = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration();\n\n // Format all configuration values as environment variables\n const env = formatEnvVariable('next');\n const { mainDir, configDir, baseDir } = intlayerConfig.content;\n\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n const configurationPath = join(configDir, 'configuration.json');\n const relativeConfigurationPath = relative(baseDir, configurationPath);\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = isTurbopackEnabled\n ? {\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': relativeDictionariesPath,\n '@intlayer/config/built': relativeConfigurationPath,\n },\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n }\n : {};\n\n const newConfig: Partial<NextConfig> = {\n // Merge environment variables\n env: { ...nextConfig.env, ...env },\n\n // Only add `serverExternalPackages` if Next.js is v15+\n ...(nextMajorVersion >= 15\n ? {\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n }\n : {}),\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n ...turboConfig,\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Alias the dictionary entry for all builds\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n config.resolve.alias['@intlayer/config/built'] = resolve(\n relativeConfigurationPath\n );\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin());\n }\n\n return config;\n },\n };\n\n // Merge the new config with the user's config\n return { ...nextConfig, ...newConfig };\n};\n"],"mappings":"AAAA,SAAS,SAAS,UAAU,YAAY;AACxC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAI/B,MAAM,UAAU,eAAe,mBAAmB;AAElD,MAAM,mBAAmB,SAAS,QAAQ,QAAQ,MAAM,GAAG,EAAE,CAAC,GAAG,EAAE;AAGnE,MAAM,qBACJ,QAAQ,IAAI,sBAAsB,SAAS,SAAS;AAe/C,MAAM,eAAe,CAC1B,aAAgB,CAAC,MACE;AACnB,MAAI,OAAO,eAAe,UAAU;AAClC,iBAAa,CAAC;AAAA,EAChB;AAEA,QAAM,iBAAiB,iBAAiB;AAGxC,QAAM,MAAM,kBAAkB,MAAM;AACpC,QAAM,EAAE,SAAS,WAAW,QAAQ,IAAI,eAAe;AAEvD,QAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,QAAM,2BAA2B,SAAS,SA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,QAAQ;AAAA,MACV,CAAC;AAGD,YAAM,EAAE,UAAU,YAAY,IAAI;AAElC,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,eAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,EAAE,GAAG,YAAY,GAAG,UAAU;AACvC;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"intlayerMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/intlayerMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAcrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,kBAAkB,YACpB,WAAW,WACX,cAAc,cACX,YAAY,KACvB,YAyBF,CAAC"}
1
+ {"version":3,"file":"intlayerMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/intlayerMiddleware.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAcrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,WAAW,EACpB,SAAS,cAAc,EACvB,YAAY,YAAY,KACvB,YAyBF,CAAC"}
@@ -1,9 +1,9 @@
1
- import type { Locales } from '@intlayer/config';
1
+ import type { LocalesValues } from '@intlayer/config';
2
2
  import type { NextRequest } from 'next/server.js';
3
3
  /**
4
4
  * Detects the locale from the request headers
5
5
  *
6
6
  * Headers are provided by the browser and can be used to determine the user's preferred language
7
7
  */
8
- export declare const localeDetector: (request: NextRequest) => Locales;
8
+ export declare const localeDetector: (request: NextRequest) => LocalesValues;
9
9
  //# sourceMappingURL=localeDetector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"localeDetector.d.ts","sourceRoot":"","sources":["../../../src/middleware/localeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAa,WAAW,KAAG,OAQrD,CAAC"}
1
+ {"version":3,"file":"localeDetector.d.ts","sourceRoot":"","sources":["../../../src/middleware/localeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,KAAG,aAQrD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"withIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/withIntlayer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAYvC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,eAC5C,CAAC,KACZ,UAAU,GAAG,CA8Ff,CAAC"}
1
+ {"version":3,"file":"withIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/withIntlayer.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAavC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,OAAO,CAAC,UAAU,CAAC,EACxD,aAAY,CAAW,KACtB,UAAU,GAAG,CAsGf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intlayer",
3
- "version": "5.1.8",
3
+ "version": "5.2.1",
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": [
@@ -67,16 +67,15 @@
67
67
  ],
68
68
  "dependencies": {
69
69
  "node-loader": "^2.1.0",
70
- "@intlayer/chokidar": "5.1.8",
71
- "@intlayer/config": "5.1.8",
72
- "@intlayer/core": "5.1.8",
73
- "@intlayer/dictionaries-entry": "5.1.8",
74
- "@intlayer/webpack": "5.1.8",
75
- "react-intlayer": "5.1.8"
70
+ "@intlayer/chokidar": "5.2.1",
71
+ "@intlayer/config": "5.2.1",
72
+ "@intlayer/core": "5.2.1",
73
+ "@intlayer/dictionaries-entry": "5.2.1",
74
+ "react-intlayer": "5.2.1",
75
+ "@intlayer/webpack": "5.2.1"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@types/node": "^22.10.6",
79
- "@types/react": "^19.0.0",
80
79
  "@typescript-eslint/parser": "^8.24.0",
81
80
  "concurrently": "^9.1.2",
82
81
  "eslint": "^9.20.0",
@@ -86,20 +85,23 @@
86
85
  "tsup": "^8.3.5",
87
86
  "typescript": "^5.7.3",
88
87
  "@utils/eslint-config": "1.0.4",
88
+ "@utils/ts-config": "1.0.4",
89
89
  "@utils/ts-config-types": "1.0.4",
90
90
  "@utils/tsup-config": "1.0.4",
91
- "intlayer": "5.1.8",
92
- "@utils/ts-config": "1.0.4"
91
+ "intlayer": "5.2.1"
93
92
  },
94
93
  "peerDependencies": {
94
+ "@types/react": ">=16.0.0",
95
+ "@types/react-dom": ">=16.0.0",
95
96
  "next": ">=14.0.0",
96
97
  "react": ">=16.0.0",
97
- "@intlayer/config": "5.1.8",
98
- "@intlayer/core": "5.1.8",
99
- "@intlayer/dictionaries-entry": "5.1.8",
100
- "@intlayer/webpack": "5.1.8",
101
- "intlayer": "5.1.8",
102
- "react-intlayer": "5.1.8"
98
+ "react-dom": ">=16.0.0",
99
+ "@intlayer/config": "5.2.1",
100
+ "@intlayer/core": "5.2.1",
101
+ "@intlayer/dictionaries-entry": "5.2.1",
102
+ "@intlayer/webpack": "5.2.1",
103
+ "intlayer": "5.2.1",
104
+ "react-intlayer": "5.2.1"
103
105
  },
104
106
  "engines": {
105
107
  "node": ">=14.18"