next-intlayer 5.7.5 → 5.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/index.cjs +1 -1
- package/dist/cjs/client/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middleware/intlayerMiddleware.cjs +6 -2
- package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +2 -0
- package/dist/cjs/server/index.cjs.map +1 -1
- package/dist/esm/client/index.mjs +2 -2
- package/dist/esm/client/index.mjs.map +1 -1
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middleware/intlayerMiddleware.mjs +6 -2
- package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -1
- package/dist/esm/server/index.mjs +2 -0
- package/dist/esm/server/index.mjs.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/server/index.d.ts +1 -1
- package/dist/types/server/index.d.ts.map +1 -1
- package/package.json +16 -16
|
@@ -23,9 +23,9 @@ __export(client_exports, {
|
|
|
23
23
|
useLocalePageRouter: () => import_useLocalePageRouter.useLocalePageRouter
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(client_exports);
|
|
26
|
+
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
26
27
|
var import_useLocale = require('./useLocale.cjs');
|
|
27
28
|
var import_useLocalePageRouter = require('./useLocalePageRouter.cjs');
|
|
28
|
-
var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
|
|
29
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
30
|
0 && (module.exports = {
|
|
31
31
|
IntlayerClientProvider,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './IntlayerClientProvider';\nexport { useLocale } from './useLocale';\nexport { useLocalePageRouter } from './useLocalePageRouter';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oCAGO;AACP,uBAA0B;AAC1B,iCAAoC;","names":[]}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
useDictionary: () => import_react_intlayer.useDictionary,
|
|
27
27
|
useDictionaryAsync: () => import_react_intlayer.useDictionaryAsync,
|
|
28
28
|
useDictionaryDynamic: () => import_react_intlayer.useDictionaryDynamic,
|
|
29
|
+
useI18n: () => import_react_intlayer.useI18n,
|
|
29
30
|
useIntlayer: () => import_react_intlayer.useIntlayer,
|
|
30
31
|
useIntlayerAsync: () => import_react_intlayer.useIntlayerAsync,
|
|
31
32
|
useLoadDynamic: () => import_react_intlayer.useLoadDynamic,
|
|
@@ -47,6 +48,7 @@ var import_generateStaticParams = require('./generateStaticParams.cjs');
|
|
|
47
48
|
useDictionary,
|
|
48
49
|
useDictionaryAsync,
|
|
49
50
|
useDictionaryDynamic,
|
|
51
|
+
useI18n,
|
|
50
52
|
useIntlayer,
|
|
51
53
|
useIntlayerAsync,
|
|
52
54
|
useLoadDynamic,
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n IntlayerClientContext,\n MarkdownProvider,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n useIntlayerAsync,\n useLoadDynamic,\n useLocaleCookie,\n type IntlayerNode,\n} from 'react-intlayer';\nexport {\n IntlayerClientProvider,\n useLocale,\n useLocalePageRouter,\n type IntlayerClientProviderProps,\n} from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n IntlayerClientContext,\n MarkdownProvider,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useI18n,\n useIntlayer,\n useIntlayerAsync,\n useLoadDynamic,\n useLocaleCookie,\n type IntlayerNode,\n} from 'react-intlayer';\nexport {\n IntlayerClientProvider,\n useLocale,\n useLocalePageRouter,\n type IntlayerClientProviderProps,\n} from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAaO;AACP,oBAKO;AACP,kCAAqC;","names":[]}
|
|
@@ -191,12 +191,16 @@ const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) =
|
|
|
191
191
|
return newPath;
|
|
192
192
|
};
|
|
193
193
|
const rewriteUrl = (request, newPath, locale) => {
|
|
194
|
-
const
|
|
194
|
+
const search = request.nextUrl.search;
|
|
195
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
196
|
+
const response = import_server.NextResponse.rewrite(new URL(pathWithSearch, request.url));
|
|
195
197
|
response.headers.set(headerName, locale);
|
|
196
198
|
return response;
|
|
197
199
|
};
|
|
198
200
|
const redirectUrl = (request, newPath) => {
|
|
199
|
-
|
|
201
|
+
const search = request.nextUrl.search;
|
|
202
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
203
|
+
return import_server.NextResponse.redirect(new URL(pathWithSearch, request.url));
|
|
200
204
|
};
|
|
201
205
|
// Annotate the CommonJS export names for ESM import in node:
|
|
202
206
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales } from '@intlayer/config/client';\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 detectLocaleOnPrefetchNoPrefix,\n} = middleware;\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/**\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\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\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 const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {\n return handleMissingPathLocale(\n request,\n defaultLocale,\n pathname,\n basePathTrailingSlash\n );\n }\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 locale = defaultLocale;\n }\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 return NextResponse.redirect(new URL(newPath, request.url));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,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;AAAA,EACA;AACF,IAAI;AAgBJ,MAAM,oBAAoB,CAAC,YAAkC;AAC3D,QAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;AAC7C,QAAM,qBAAqB,QAAQ,QAAQ,IAAI,sBAAsB;AACrE,QAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;AAC9C,QAAM,cAAc,QAAQ,QAAQ,IAAI,eAAe;AAEvD,SACE,YAAY,cACZ,uBAAuB,OACvB,CAAC,CAAC,WACF,CAAC,CAAC;AAEN;AAyBO,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AAEjC,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,IA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AAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YAAkC;AAC3E,SAAO,2BAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AAC5D;","names":["configuration","basePath"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales } from '@intlayer/config/client';\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 detectLocaleOnPrefetchNoPrefix,\n} = middleware;\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/**\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\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\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 const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {\n return handleMissingPathLocale(\n request,\n defaultLocale,\n pathname,\n basePathTrailingSlash\n );\n }\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 locale = defaultLocale;\n }\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 // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const response = NextResponse.rewrite(new URL(pathWithSearch, 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 // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,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;AAAA,EACA;AACF,IAAI;AAgBJ,MAAM,oBAAoB,CAAC,YAAkC;AAC3D,QAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;AAC7C,QAAM,qBAAqB,QAAQ,QAAQ,IAAI,sBAAsB;AACrE,QAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;AAC9C,QAAM,cAAc,QAAQ,QAAQ,IAAI,eAAe;AAEvD,SACE,YAAY,cACZ,uBAAuB,OACvB,CAAC,CAAC,WACF,CAAC,CAAC;AAEN;AAyBO,MAAM,qBAAqB,CAChC,SACA,QACA,cACiB;AACjB,QAAM,WAAW,QAAQ,QAAQ;AAEjC,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,G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AG,OAAO,GAAG,MAAM,KAAK;AAE7D,QAAM,WAAW,2BAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,GAAG,CAAC;AAC1E,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YAAkC;AAE3E,QAAM,SAAS,QAAQ,QAAQ;AAC/B,QAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,KAAK;AAE7D,SAAO,2BAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,GAAG,CAAC;AACnE;","names":["configuration","basePath"]}
|
|
@@ -24,6 +24,7 @@ __export(server_exports, {
|
|
|
24
24
|
t: () => import_server.t,
|
|
25
25
|
useDictionary: () => import_server.useDictionary,
|
|
26
26
|
useDictionaryDynamic: () => import_server.useDictionaryDynamic,
|
|
27
|
+
useI18n: () => import_server.useI18n,
|
|
27
28
|
useIntlayer: () => import_server.useIntlayer,
|
|
28
29
|
useLoadDynamic: () => import_server.useLoadDynamic,
|
|
29
30
|
useLocale: () => import_server.useLocale,
|
|
@@ -40,6 +41,7 @@ var import_withIntlayer = require('./withIntlayer.cjs');
|
|
|
40
41
|
t,
|
|
41
42
|
useDictionary,
|
|
42
43
|
useDictionaryDynamic,
|
|
44
|
+
useI18n,
|
|
43
45
|
useIntlayer,
|
|
44
46
|
useLoadDynamic,
|
|
45
47
|
useLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n t,\n useDictionary,\n useDictionaryDynamic,\n useIntlayer,\n useLoadDynamic,\n useLocale,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n t,\n useDictionary,\n useDictionaryDynamic,\n useI18n,\n useIntlayer,\n useLoadDynamic,\n useLocale,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAWO;AACP,0BAA6B;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { useLocale } from "./useLocale.mjs";
|
|
2
|
-
import { useLocalePageRouter } from "./useLocalePageRouter.mjs";
|
|
3
1
|
import {
|
|
4
2
|
IntlayerClientProvider
|
|
5
3
|
} from "./IntlayerClientProvider.mjs";
|
|
4
|
+
import { useLocale } from "./useLocale.mjs";
|
|
5
|
+
import { useLocalePageRouter } from "./useLocalePageRouter.mjs";
|
|
6
6
|
export {
|
|
7
7
|
IntlayerClientProvider,
|
|
8
8
|
useLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './IntlayerClientProvider';\nexport { useLocale } from './useLocale';\nexport { useLocalePageRouter } from './useLocalePageRouter';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;","names":[]}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
useDictionary,
|
|
6
6
|
useDictionaryAsync,
|
|
7
7
|
useDictionaryDynamic,
|
|
8
|
+
useI18n,
|
|
8
9
|
useIntlayer,
|
|
9
10
|
useIntlayerAsync,
|
|
10
11
|
useLoadDynamic,
|
|
@@ -25,6 +26,7 @@ export {
|
|
|
25
26
|
useDictionary,
|
|
26
27
|
useDictionaryAsync,
|
|
27
28
|
useDictionaryDynamic,
|
|
29
|
+
useI18n,
|
|
28
30
|
useIntlayer,
|
|
29
31
|
useIntlayerAsync,
|
|
30
32
|
useLoadDynamic,
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n IntlayerClientContext,\n MarkdownProvider,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useIntlayer,\n useIntlayerAsync,\n useLoadDynamic,\n useLocaleCookie,\n type IntlayerNode,\n} from 'react-intlayer';\nexport {\n IntlayerClientProvider,\n useLocale,\n useLocalePageRouter,\n type IntlayerClientProviderProps,\n} from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n IntlayerClientContext,\n MarkdownProvider,\n t,\n useDictionary,\n useDictionaryAsync,\n useDictionaryDynamic,\n useI18n,\n useIntlayer,\n useIntlayerAsync,\n useLoadDynamic,\n useLocaleCookie,\n type IntlayerNode,\n} from 'react-intlayer';\nexport {\n IntlayerClientProvider,\n useLocale,\n useLocalePageRouter,\n type IntlayerClientProviderProps,\n} from './client/index';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14LayoutIntlayer,\n Next14PageIntlayer,\n Next15LayoutIntlayer,\n Next15PageIntlayer,\n NextLayoutIntlayer,\n NextPageIntlayer,\n} from './types/index';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,4BAA4B;","names":[]}
|
|
@@ -160,12 +160,16 @@ const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) =
|
|
|
160
160
|
return newPath;
|
|
161
161
|
};
|
|
162
162
|
const rewriteUrl = (request, newPath, locale) => {
|
|
163
|
-
const
|
|
163
|
+
const search = request.nextUrl.search;
|
|
164
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
165
|
+
const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));
|
|
164
166
|
response.headers.set(headerName, locale);
|
|
165
167
|
return response;
|
|
166
168
|
};
|
|
167
169
|
const redirectUrl = (request, newPath) => {
|
|
168
|
-
|
|
170
|
+
const search = request.nextUrl.search;
|
|
171
|
+
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
172
|
+
return NextResponse.redirect(new URL(pathWithSearch, request.url));
|
|
169
173
|
};
|
|
170
174
|
export {
|
|
171
175
|
intlayerMiddleware
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales } from '@intlayer/config/client';\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 detectLocaleOnPrefetchNoPrefix,\n} = middleware;\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/**\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\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\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 const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {\n return handleMissingPathLocale(\n request,\n defaultLocale,\n pathname,\n basePathTrailingSlash\n );\n }\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 locale = defaultLocale;\n }\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 return NextResponse.redirect(new URL(newPath, request.url));\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B;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;AAAA,EACA;AACF,IAAI;AAgBJ,MAAM,oBAAoB,CAAC,YAAkC;AAC3D,QAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;AAC7C,QAAM,qBAAqB,QAAQ,QAAQ,IAAI,sBAAsB;AACrE,QAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;AAC9C,QAAM,cAAc,QAAQ,QAAQ,IAAI,eAAe;AAE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I,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,YAAkC;AAC3E,SAAO,aAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AAC5D;","names":["basePath"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locales } from '@intlayer/config/client';\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 detectLocaleOnPrefetchNoPrefix,\n} = middleware;\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/**\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\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\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 const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {\n return handleMissingPathLocale(\n request,\n defaultLocale,\n pathname,\n basePathTrailingSlash\n );\n }\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 locale = defaultLocale;\n }\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 // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const response = NextResponse.rewrite(new URL(pathWithSearch, 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 // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B;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;AAAA,EACA;AACF,IAAI;AAgBJ,MAAM,oBAAoB,CAAC,YAAkC;AAC3D,QAAM,UAAU,QAAQ,QAAQ,IAAI,SAAS;AAC7C,QAAM,qBAAqB,QAAQ,QAAQ,IAAI,sBAAsB;AACrE,QAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;AAC9C,QAAM,cAAc,QAAQ,QAAQ,IAAI,eAAe;AAEvD,SACE,YAAY,cACZ,uBAAuB,OACvB,CAAC,CAAC,WACF,CAAC,CA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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;AAEjB,QAAM,SAAS,QAAQ,QAAQ;AAC/B,QAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,KAAK;AAE7D,QAAM,WAAW,aAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,GAAG,CAAC;AAC1E,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YAAkC;AAE3E,QAAM,SAAS,QAAQ,QAAQ;AAC/B,QAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,MAAM,KAAK;AAE7D,SAAO,aAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,GAAG,CAAC;AACnE;","names":["basePath"]}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
t,
|
|
6
6
|
useDictionary,
|
|
7
7
|
useDictionaryDynamic,
|
|
8
|
+
useI18n,
|
|
8
9
|
useIntlayer,
|
|
9
10
|
useLoadDynamic,
|
|
10
11
|
useLocale
|
|
@@ -17,6 +18,7 @@ export {
|
|
|
17
18
|
t,
|
|
18
19
|
useDictionary,
|
|
19
20
|
useDictionaryDynamic,
|
|
21
|
+
useI18n,
|
|
20
22
|
useIntlayer,
|
|
21
23
|
useLoadDynamic,
|
|
22
24
|
useLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n t,\n useDictionary,\n useDictionaryDynamic,\n useIntlayer,\n useLoadDynamic,\n useLocale,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n t,\n useDictionary,\n useDictionaryDynamic,\n useI18n,\n useIntlayer,\n useLoadDynamic,\n useLocale,\n} from 'react-intlayer/server';\nexport { withIntlayer } from './withIntlayer';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
export { IntlayerClientProvider, type IntlayerClientProviderProps, } from './IntlayerClientProvider';
|
|
1
2
|
export { useLocale } from './useLocale';
|
|
2
3
|
export { useLocalePageRouter } from './useLocalePageRouter';
|
|
3
|
-
export { IntlayerClientProvider, type IntlayerClientProviderProps, } from './IntlayerClientProvider';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { IntlayerClientContext, MarkdownProvider, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useIntlayerAsync, useLoadDynamic, useLocaleCookie, type IntlayerNode, } from 'react-intlayer';
|
|
1
|
+
export { IntlayerClientContext, MarkdownProvider, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useIntlayerAsync, useLoadDynamic, useLocaleCookie, type IntlayerNode, } from 'react-intlayer';
|
|
2
2
|
export { IntlayerClientProvider, useLocale, useLocalePageRouter, type IntlayerClientProviderProps, } from './client/index';
|
|
3
3
|
export { generateStaticParams } from './generateStaticParams';
|
|
4
4
|
export type { LocalParams, LocalPromiseParams, Next14LayoutIntlayer, Next14PageIntlayer, Next15LayoutIntlayer, Next15PageIntlayer, NextLayoutIntlayer, NextPageIntlayer, } from './types/index';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,CAAC,EACD,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,mBAAmB,EACnB,KAAK,2BAA2B,GACjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,CAAC,EACD,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,sBAAsB,EACtB,SAAS,EACT,mBAAmB,EACnB,KAAK,2BAA2B,GACjC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,eAAe,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryDynamic, useIntlayer, useLoadDynamic, useLocale, } from 'react-intlayer/server';
|
|
1
|
+
export { IntlayerServer, IntlayerServerProvider, locale, t, useDictionary, useDictionaryDynamic, useI18n, useIntlayer, useLoadDynamic, useLocale, } from 'react-intlayer/server';
|
|
2
2
|
export { withIntlayer } from './withIntlayer';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,MAAM,EACN,CAAC,EACD,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,SAAS,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,MAAM,EACN,CAAC,EACD,aAAa,EACb,oBAAoB,EACpB,OAAO,EACP,WAAW,EACX,cAAc,EACd,SAAS,GACV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.6",
|
|
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": [
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"deepmerge": "^4.3.1",
|
|
71
71
|
"node-loader": "^2.1.0",
|
|
72
|
-
"@intlayer/chokidar": "5.7.
|
|
73
|
-
"@intlayer/
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"@intlayer/dictionaries-entry": "5.7.
|
|
77
|
-
"@intlayer/webpack": "5.7.
|
|
72
|
+
"@intlayer/chokidar": "5.7.6",
|
|
73
|
+
"@intlayer/config": "5.7.6",
|
|
74
|
+
"@intlayer/core": "5.7.6",
|
|
75
|
+
"react-intlayer": "5.7.6",
|
|
76
|
+
"@intlayer/dictionaries-entry": "5.7.6",
|
|
77
|
+
"@intlayer/webpack": "5.7.6"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/node": "^22.15.30",
|
|
@@ -89,22 +89,22 @@
|
|
|
89
89
|
"tsup": "^8.5.0",
|
|
90
90
|
"typescript": "^5.8.3",
|
|
91
91
|
"vitest": "^3.2.2",
|
|
92
|
-
"@utils/ts-config-types": "1.0.4",
|
|
93
|
-
"@utils/tsup-config": "1.0.4",
|
|
94
92
|
"@utils/eslint-config": "1.0.4",
|
|
95
93
|
"@utils/ts-config": "1.0.4",
|
|
96
|
-
"
|
|
94
|
+
"@utils/ts-config-types": "1.0.4",
|
|
95
|
+
"@utils/tsup-config": "1.0.4",
|
|
96
|
+
"intlayer": "5.7.6"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"next": ">=14.0.0",
|
|
100
100
|
"react": ">=16.0.0",
|
|
101
101
|
"react-dom": ">=16.0.0",
|
|
102
|
-
"@intlayer/config": "5.7.
|
|
103
|
-
"@intlayer/
|
|
104
|
-
"
|
|
105
|
-
"intlayer": "5.7.
|
|
106
|
-
"@intlayer/
|
|
107
|
-
"
|
|
102
|
+
"@intlayer/config": "5.7.6",
|
|
103
|
+
"@intlayer/dictionaries-entry": "5.7.6",
|
|
104
|
+
"intlayer": "5.7.6",
|
|
105
|
+
"react-intlayer": "5.7.6",
|
|
106
|
+
"@intlayer/webpack": "5.7.6",
|
|
107
|
+
"@intlayer/core": "5.7.6"
|
|
108
108
|
},
|
|
109
109
|
"engines": {
|
|
110
110
|
"node": ">=14.18"
|