next-intlayer 3.4.9 → 3.5.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.
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/middleware/intlayerMiddleware.cjs +1 -1
- package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +8 -1
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/cjs/types/NextPage.cjs.map +1 -1
- package/dist/cjs/types/index.cjs.map +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/middleware/intlayerMiddleware.mjs +1 -1
- package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -1
- package/dist/esm/server/withIntlayer.mjs +8 -1
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/server/withIntlayer.d.ts.map +1 -1
- package/dist/types/types/NextPage.d.ts +5 -3
- package/dist/types/types/NextPage.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/index.d.ts.map +1 -1
- package/package.json +15 -15
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useDictionary,\n useLocaleCookie,\n type IntlayerNode,\n t,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useDictionary,\n useLocaleCookie,\n type IntlayerNode,\n t,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n Next14LayoutIntlayer,\n Next15LayoutIntlayer,\n NextLayoutIntlayer,\n} from './types/index';\nexport {\n useLocale,\n useLocalePageRouter,\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/index';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BASO;AACP,kCAAqC;AAWrC,oBAKO;","names":[]}
|
|
@@ -145,7 +145,7 @@ const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrai
|
|
|
145
145
|
// If default locale should not be prefixed and the pathLocale is the defaultLocale
|
|
146
146
|
!prefixDefault && pathLocale === defaultLocale
|
|
147
147
|
) {
|
|
148
|
-
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length)
|
|
148
|
+
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? "/";
|
|
149
149
|
if (basePathTrailingSlash) {
|
|
150
150
|
pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
151
151
|
}
|
|
@@ -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 );\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 );\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,sB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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,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, 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 );\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 );\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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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,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"]}
|
|
@@ -33,7 +33,14 @@ const withIntlayer = (nextConfig = {}) => {
|
|
|
33
33
|
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
34
34
|
return Object.assign({}, nextConfig, {
|
|
35
35
|
env: { ...nextConfig.env, ...env },
|
|
36
|
-
serverExternalPackages: [
|
|
36
|
+
serverExternalPackages: [
|
|
37
|
+
...nextConfig.serverExternalPackages ?? [],
|
|
38
|
+
"esbuild",
|
|
39
|
+
"module",
|
|
40
|
+
"fs",
|
|
41
|
+
"chokidar",
|
|
42
|
+
"fsevents"
|
|
43
|
+
],
|
|
37
44
|
experimental: {
|
|
38
45
|
...nextConfig.experimental ?? {},
|
|
39
46
|
// Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)
|
|
@@ -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';\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 *\n */\nexport const withIntlayer = (\n nextConfig: Partial<NextConfig> = {}\n): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n serverExternalPackages: ['esbuild'
|
|
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';\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 *\n */\nexport const withIntlayer = (\n nextConfig: Partial<NextConfig> = {}\n): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n // Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n if (nextConfig.webpack) {\n // Invoke the existing webpack config if it exists\n config = nextConfig.webpack(config, options);\n }\n\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n const { isServer, nextRuntime } = options;\n\n // Apply IntLayerPlugin only on the server-side\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntLayerPlugin());\n }\n\n return config;\n },\n } satisfies Partial<NextConfig>);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAwC;AACxC,oBAAoD;AACpD,qBAA+B;AAkBxB,MAAM,eAAe,CAC1B,aAAkC,CAAC,MACX;AACxB,MAAI,OAAO,eAAe,SAAU,cAAa,CAAC;AAElD,QAAM,qBAAiB,gCAAiB;AAGxC,QAAM,UAAM,iCAAkB,MAAM;AAEpC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAC5C,QAAM,uBAAmB,kBAAK,SAAS,kBAAkB;AACzD,QAAM,+BAA2B,sBAAS,SAAS,gBAAgB;AAEnE,SAAO,OAAO,OAAO,CAAC,GAAG,YAAY;AAAA,IACnC,KAAK,EAAE,GAAG,WAAW,KAAK,GAAG,IAAI;AAAA,IAEjC,wBAAwB;AAAA,MACtB,GAAI,WAAW,0BAA0B,CAAC;AAAA,MAC1C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IAEA,cAAc;AAAA,MACZ,GAAI,WAAW,gBAAgB,CAAC;AAAA;AAAA,MAEhC,OAAO;AAAA,QACL,GAAI,WAAW,cAAc,SAAS,CAAC;AAAA,QACvC,cAAc;AAAA,UACZ,GAAI,WAAW,cAAc,OAAO,gBAAgB,CAAC;AAAA,UACrD,oCAAgC,qBAAQ,wBAAwB;AAAA,QAClE;AAAA,QAEA,OAAO;AAAA,UACL,UAAU;AAAA,YACR,IAAI;AAAA,YACJ,SAAS,CAAC,aAAa;AAAA,UACzB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,SAAS,CAAC,QAA4B,YAA8B;AAClE,UAAI,WAAW,SAAS;AAEtB,iBAAS,WAAW,QAAQ,QAAQ,OAAO;AAAA,MAC7C;AAEA,aAAO,QAAQ,MAAM,8BAA8B,QAAI;AAAA,QACrD;AAAA,MACF;AAEA,aAAO,UAAU,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,IAAI;AAAA,QACJ,UAAU;AAAA,QACV,UAAU;AAAA,MACZ,CAAC;AACD,aAAO,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAED,YAAM,EAAE,UAAU,YAAY,IAAI;AAGlC,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,8BAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAA+B;AACjC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/NextPage.ts"],"sourcesContent":["import type { Locales } from 'intlayer';\nimport type { NextPage } from 'next';\nimport type { PropsWithChildren } from 'react';\n\nexport type LocalParams<T = undefined> = {\n params: { locale: Locales } & T;\n};\n\nexport type LocalPromiseParams<T = undefined> = {\n params: Promise<{ locale: Locales } & T>;\n};\n\nexport type Next14PageIntlayer<T = undefined> = NextPage<LocalParams<T>>;\nexport type Next15PageIntlayer<T = undefined> =
|
|
1
|
+
{"version":3,"sources":["../../../src/types/NextPage.ts"],"sourcesContent":["import type { Locales } from 'intlayer';\nimport type { NextPage } from 'next';\nimport type { PropsWithChildren, ReactNode } from 'react';\n\nexport type LocalParams<T = undefined> = {\n params: { locale: Locales } & T;\n};\n\nexport type LocalPromiseParams<T = undefined> = {\n params: Promise<{ locale: Locales } & T>;\n};\n\nexport type Next14PageIntlayer<T = undefined> = NextPage<LocalParams<T>>;\nexport type Next15PageIntlayer<T = undefined> = (\n props: LocalPromiseParams<T>\n) => ReactNode | Promise<ReactNode>;\nexport type NextPageIntlayer<T = undefined> = Next15PageIntlayer<T>;\n\nexport type Next14LayoutIntlayer<T = undefined> = NextPage<\n PropsWithChildren<LocalParams<T>>\n>;\nexport type Next15LayoutIntlayer<T = undefined> = (\n props: PropsWithChildren<LocalPromiseParams<T>>\n) => ReactNode | Promise<ReactNode>;\nexport type NextLayoutIntlayer<T = undefined> = Next15LayoutIntlayer<T>;\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n NextLayoutIntlayer,\n LocalPromiseParams,\n} from './NextPage';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["export type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n Next14LayoutIntlayer,\n Next15LayoutIntlayer,\n NextLayoutIntlayer,\n LocalPromiseParams,\n} from './NextPage';\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useDictionary,\n useLocaleCookie,\n type IntlayerNode,\n t,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useDictionary,\n useLocaleCookie,\n type IntlayerNode,\n t,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type {\n LocalParams,\n LocalPromiseParams,\n Next14PageIntlayer,\n Next15PageIntlayer,\n NextPageIntlayer,\n Next14LayoutIntlayer,\n Next15LayoutIntlayer,\n NextLayoutIntlayer,\n} from './types/index';\nexport {\n useLocale,\n useLocalePageRouter,\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './client/index';\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,4BAA4B;AAWrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;","names":[]}
|
|
@@ -124,7 +124,7 @@ const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrai
|
|
|
124
124
|
// If default locale should not be prefixed and the pathLocale is the defaultLocale
|
|
125
125
|
!prefixDefault && pathLocale === defaultLocale
|
|
126
126
|
) {
|
|
127
|
-
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length)
|
|
127
|
+
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? "/";
|
|
128
128
|
if (basePathTrailingSlash) {
|
|
129
129
|
pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
130
130
|
}
|
|
@@ -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 );\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 );\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,SAAS,WAAW,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAWA,MAAM,iBAAiB,CACrB,SACA,cACA,UACA,0BACiB;AACjB,QAAM,SAAS,gBAAgB;AAC/B,QAAM,UAAU;AAAA,IACd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AAI,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
|
+
{"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 );\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 );\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,SAAS,WAAW,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAWA,MAAM,iBAAiB,CACrB,SACA,cACA,UACA,0BACiB;AACjB,QAAM,SAAS,gBAAgB;AAC/B,QAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,WAAW,SAAS,SAAS,MAAM;AAC5C;AAQA,MAAM,gBAAgB,CAAC,aACrB,QAAQ;AAAA,EACN,CAAC,WAAW,SAAS,WAAW,IAAI,MAAM,GAAG,KAAK,aAA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AAC,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"]}
|
|
@@ -10,7 +10,14 @@ const withIntlayer = (nextConfig = {}) => {
|
|
|
10
10
|
const relativeDictionariesPath = relative(baseDir, dictionariesPath);
|
|
11
11
|
return Object.assign({}, nextConfig, {
|
|
12
12
|
env: { ...nextConfig.env, ...env },
|
|
13
|
-
serverExternalPackages: [
|
|
13
|
+
serverExternalPackages: [
|
|
14
|
+
...nextConfig.serverExternalPackages ?? [],
|
|
15
|
+
"esbuild",
|
|
16
|
+
"module",
|
|
17
|
+
"fs",
|
|
18
|
+
"chokidar",
|
|
19
|
+
"fsevents"
|
|
20
|
+
],
|
|
14
21
|
experimental: {
|
|
15
22
|
...nextConfig.experimental ?? {},
|
|
16
23
|
// Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)
|
|
@@ -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';\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 *\n */\nexport const withIntlayer = (\n nextConfig: Partial<NextConfig> = {}\n): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n serverExternalPackages: ['esbuild'
|
|
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';\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 *\n */\nexport const withIntlayer = (\n nextConfig: Partial<NextConfig> = {}\n): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n const dictionariesPath = join(mainDir, 'dictionaries.mjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n serverExternalPackages: [\n ...(nextConfig.serverExternalPackages ?? []),\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ],\n\n experimental: {\n ...(nextConfig.experimental ?? {}),\n // Using Intlayer with Turbopack is not supported as long external modules can't be resolved (such as esbuild or fs)\n turbo: {\n ...(nextConfig.experimental?.turbo ?? {}),\n resolveAlias: {\n ...(nextConfig.experimental?.turbo?.resolveAlias ?? {}),\n '@intlayer/dictionaries-entry': resolve(relativeDictionariesPath),\n },\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n },\n },\n\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n if (nextConfig.webpack) {\n // Invoke the existing webpack config if it exists\n config = nextConfig.webpack(config, options);\n }\n\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n const { isServer, nextRuntime } = options;\n\n // Apply IntLayerPlugin only on the server-side\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntLayerPlugin());\n }\n\n return config;\n },\n } satisfies Partial<NextConfig>);\n};\n"],"mappings":"AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,sBAAsB;AAkBxB,MAAM,eAAe,CAC1B,aAAkC,CAAC,MACX;AACxB,MAAI,OAAO,eAAe,SAA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I,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,eAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAA+B;AACjC;","names":[]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getTranslation, IntlayerClientContext, useIntlayer, useTraduction, useDictionary, useLocaleCookie, type IntlayerNode, t, } from 'react-intlayer';
|
|
2
2
|
export { generateStaticParams } from './generateStaticParams';
|
|
3
|
-
export type { LocalParams, Next14PageIntlayer, Next15PageIntlayer, NextPageIntlayer,
|
|
3
|
+
export type { LocalParams, LocalPromiseParams, Next14PageIntlayer, Next15PageIntlayer, NextPageIntlayer, Next14LayoutIntlayer, Next15LayoutIntlayer, NextLayoutIntlayer, } from './types/index';
|
|
4
4
|
export { useLocale, useLocalePageRouter, IntlayerClientProvider, type IntlayerClientProviderProps, } from './client/index';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,KAAK,YAAY,EACjB,CAAC,GACF,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,KAAK,YAAY,EACjB,CAAC,GACF,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,gBAAgB,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;AAKvC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,gBACX,OAAO,CAAC,UAAU,CAAC,KAC9B,OAAO,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"withIntlayer.d.ts","sourceRoot":"","sources":["../../../src/server/withIntlayer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAKvC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,YAAY,gBACX,OAAO,CAAC,UAAU,CAAC,KAC9B,OAAO,CAAC,UAAU,CA2EpB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locales } from 'intlayer';
|
|
2
2
|
import type { NextPage } from 'next';
|
|
3
|
-
import type { PropsWithChildren } from 'react';
|
|
3
|
+
import type { PropsWithChildren, ReactNode } from 'react';
|
|
4
4
|
export type LocalParams<T = undefined> = {
|
|
5
5
|
params: {
|
|
6
6
|
locale: Locales;
|
|
@@ -12,7 +12,9 @@ export type LocalPromiseParams<T = undefined> = {
|
|
|
12
12
|
} & T>;
|
|
13
13
|
};
|
|
14
14
|
export type Next14PageIntlayer<T = undefined> = NextPage<LocalParams<T>>;
|
|
15
|
-
export type Next15PageIntlayer<T = undefined> =
|
|
15
|
+
export type Next15PageIntlayer<T = undefined> = (props: LocalPromiseParams<T>) => ReactNode | Promise<ReactNode>;
|
|
16
16
|
export type NextPageIntlayer<T = undefined> = Next15PageIntlayer<T>;
|
|
17
|
-
export type
|
|
17
|
+
export type Next14LayoutIntlayer<T = undefined> = NextPage<PropsWithChildren<LocalParams<T>>>;
|
|
18
|
+
export type Next15LayoutIntlayer<T = undefined> = (props: PropsWithChildren<LocalPromiseParams<T>>) => ReactNode | Promise<ReactNode>;
|
|
19
|
+
export type NextLayoutIntlayer<T = undefined> = Next15LayoutIntlayer<T>;
|
|
18
20
|
//# sourceMappingURL=NextPage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NextPage.d.ts","sourceRoot":"","sources":["../../../src/types/NextPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"NextPage.d.ts","sourceRoot":"","sources":["../../../src/types/NextPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE1D,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,SAAS,IAAI;IACvC,MAAM,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,SAAS,IAAI;IAC9C,MAAM,EAAE,OAAO,CAAC;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,GAAG,CAAC,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,SAAS,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,SAAS,IAAI,CAC9C,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,KACzB,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,SAAS,IAAI,kBAAkB,CAAC,CAAC,CAAC,CAAC;AAEpE,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,SAAS,IAAI,QAAQ,CACxD,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAClC,CAAC;AACF,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,SAAS,IAAI,CAChD,KAAK,EAAE,iBAAiB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,KAC5C,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACpC,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,SAAS,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type { LocalParams, Next14PageIntlayer, Next15PageIntlayer, NextPageIntlayer, NextLayoutIntlayer, LocalPromiseParams, } from './NextPage';
|
|
1
|
+
export type { LocalParams, Next14PageIntlayer, Next15PageIntlayer, NextPageIntlayer, Next14LayoutIntlayer, Next15LayoutIntlayer, NextLayoutIntlayer, LocalPromiseParams, } from './NextPage';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Internationalisation tool for Next.js applications. Declare your multilingual contant in the same lever than your component. Powered by TypeScript, declaration files.",
|
|
6
6
|
"keywords": [
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
],
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"webpack": "^5.96.1",
|
|
75
|
-
"@intlayer/
|
|
76
|
-
"@intlayer/
|
|
77
|
-
"@intlayer/core": "^3.
|
|
78
|
-
"
|
|
79
|
-
"@intlayer/
|
|
80
|
-
"
|
|
75
|
+
"@intlayer/chokidar": "^3.5.1",
|
|
76
|
+
"@intlayer/config": "^3.5.1",
|
|
77
|
+
"@intlayer/core": "^3.5.1",
|
|
78
|
+
"@intlayer/dictionaries-entry": "^3.5.1",
|
|
79
|
+
"@intlayer/webpack": "^3.5.1",
|
|
80
|
+
"react-intlayer": "^3.5.1"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@types/node": "^22.10.1",
|
|
@@ -89,21 +89,21 @@
|
|
|
89
89
|
"tsc-alias": "^1.8.10",
|
|
90
90
|
"tsup": "^8.3.5",
|
|
91
91
|
"typescript": "^5.7.2",
|
|
92
|
+
"@utils/eslint-config": "^1.0.4",
|
|
92
93
|
"@utils/ts-config": "^1.0.4",
|
|
93
94
|
"@utils/ts-config-types": "^1.0.4",
|
|
94
95
|
"@utils/tsup-config": "^1.0.4",
|
|
95
|
-
"
|
|
96
|
-
"intlayer": "^3.4.9"
|
|
96
|
+
"intlayer": "^3.5.1"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"next": ">=14.0.0 <16.0.0",
|
|
100
100
|
"react": ">=16.0.0 <19.0.0",
|
|
101
|
-
"@intlayer/
|
|
102
|
-
"@intlayer/
|
|
103
|
-
"@intlayer/webpack": "^3.
|
|
104
|
-
"intlayer": "^3.
|
|
105
|
-
"@intlayer/
|
|
106
|
-
"
|
|
101
|
+
"@intlayer/core": "^3.5.1",
|
|
102
|
+
"@intlayer/dictionaries-entry": "^3.5.1",
|
|
103
|
+
"@intlayer/webpack": "^3.5.1",
|
|
104
|
+
"react-intlayer": "^3.5.1",
|
|
105
|
+
"@intlayer/config": "^3.5.1",
|
|
106
|
+
"intlayer": "^3.5.1"
|
|
107
107
|
},
|
|
108
108
|
"engines": {
|
|
109
109
|
"node": ">=14.18"
|