next-intlayer 2.0.13 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +31 -28
  2. package/dist/cjs/client/useLocale.cjs +55 -13
  3. package/dist/cjs/client/useLocale.cjs.map +1 -1
  4. package/dist/cjs/index.cjs +4 -0
  5. package/dist/cjs/index.cjs.map +1 -1
  6. package/dist/cjs/middleware/intlayerMiddleware.cjs +9 -3
  7. package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -1
  8. package/dist/cjs/middleware/localeDetector.cjs +3 -24
  9. package/dist/cjs/middleware/localeDetector.cjs.map +1 -1
  10. package/dist/cjs/server/index.cjs +4 -0
  11. package/dist/cjs/server/index.cjs.map +1 -1
  12. package/dist/esm/client/useLocale.mjs +55 -13
  13. package/dist/esm/client/useLocale.mjs.map +1 -1
  14. package/dist/esm/index.mjs +5 -1
  15. package/dist/esm/index.mjs.map +1 -1
  16. package/dist/esm/middleware/intlayerMiddleware.mjs +12 -4
  17. package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -1
  18. package/dist/esm/middleware/localeDetector.mjs +3 -14
  19. package/dist/esm/middleware/localeDetector.mjs.map +1 -1
  20. package/dist/esm/server/index.mjs +5 -1
  21. package/dist/esm/server/index.mjs.map +1 -1
  22. package/dist/types/client/IntlayerClientProvider.d.ts +5 -0
  23. package/dist/types/client/IntlayerClientProvider.d.ts.map +1 -0
  24. package/dist/types/client/index.d.ts +4 -0
  25. package/dist/types/client/index.d.ts.map +1 -0
  26. package/dist/types/client/useLocale.d.ts +10 -0
  27. package/dist/types/client/useLocale.d.ts.map +1 -0
  28. package/dist/types/generateStaticParams.d.ts +4 -0
  29. package/dist/types/generateStaticParams.d.ts.map +1 -0
  30. package/dist/types/index.d.ts +5 -0
  31. package/dist/types/index.d.ts.map +1 -0
  32. package/dist/types/middleware/index.d.ts +2 -0
  33. package/dist/types/middleware/index.d.ts.map +1 -0
  34. package/dist/types/middleware/intlayerMiddleware.d.ts +26 -0
  35. package/dist/types/middleware/intlayerMiddleware.d.ts.map +1 -0
  36. package/dist/types/middleware/localeDetector.d.ts +9 -0
  37. package/dist/types/middleware/localeDetector.d.ts.map +1 -0
  38. package/dist/types/server/index.d.ts +3 -0
  39. package/dist/types/server/index.d.ts.map +1 -0
  40. package/dist/{cjs → types}/server/withIntlayer.d.ts +3 -6
  41. package/dist/types/server/withIntlayer.d.ts.map +1 -0
  42. package/dist/types/types/NextPage.d.ts +11 -0
  43. package/dist/types/types/NextPage.d.ts.map +1 -0
  44. package/dist/types/types/index.d.ts +2 -0
  45. package/dist/types/types/index.d.ts.map +1 -0
  46. package/package.json +36 -29
  47. package/dist/cjs/client/IntlayerClientProvider.d.ts +0 -7
  48. package/dist/cjs/client/index.d.ts +0 -5
  49. package/dist/cjs/client/useLocale.d.ts +0 -11
  50. package/dist/cjs/generateStaticParams.d.ts +0 -7
  51. package/dist/cjs/index.d.ts +0 -9
  52. package/dist/cjs/middleware/index.d.ts +0 -2
  53. package/dist/cjs/middleware/intlayerMiddleware.d.ts +0 -22
  54. package/dist/cjs/middleware/localeDetector.d.ts +0 -11
  55. package/dist/cjs/server/index.d.ts +0 -3
  56. package/dist/cjs/types/NextPage.d.ts +0 -13
  57. package/dist/cjs/types/index.d.ts +0 -4
  58. package/dist/esm/client/IntlayerClientProvider.d.mts +0 -7
  59. package/dist/esm/client/index.d.mts +0 -5
  60. package/dist/esm/client/useLocale.d.mts +0 -11
  61. package/dist/esm/generateStaticParams.d.mts +0 -7
  62. package/dist/esm/index.d.mts +0 -9
  63. package/dist/esm/middleware/index.d.mts +0 -2
  64. package/dist/esm/middleware/intlayerMiddleware.d.mts +0 -22
  65. package/dist/esm/middleware/localeDetector.d.mts +0 -11
  66. package/dist/esm/server/index.d.mts +0 -3
  67. package/dist/esm/server/withIntlayer.d.mts +0 -18
  68. package/dist/esm/types/NextPage.d.mts +0 -13
  69. package/dist/esm/types/index.d.mts +0 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { type NextRequest, NextResponse } 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 * // ./src/middleware.ts\n *\n * ```ts\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 */\nexport const intlayerMiddleware = (request: NextRequest): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (noPrefix) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\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\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\nconst getPathLocale = (pathname: string): Locales | undefined =>\n locales.find(\n (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`\n );\n\nconst handlePrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (!pathLocale) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\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 return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\n};\n\nconst handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\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 return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (!prefixDefault && pathLocale === defaultLocale) {\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 return rewriteUrl(request, pathname, pathLocale);\n};\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 newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\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\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse =>\n NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":"AAAA,SAAuB,wBAAwB;AAC/C,SAA2B,oBAAoB;AAC/C,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;AAmBG,MAAM,qBAAqB,CAAC,YAAuC;AACxE,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MAAI,UAAU;AACZ,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,QAAQ;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IAC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AsB,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,iBAA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ACjC,SACA,UACA,YACA,cACAA,WACA,0BACW;AAEX,QAAM,UAAU,SAAS,QAAQ,IAAI,UAAU,IAAI,IAAI,YAAY,EAAE;AAErE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACAA;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,EAClB;AACF;AAWA,MAAM,8BAA8B,CAClC,SACA,YACA,UACA,0BACiB;AACjB;AAAA;AAAA,IAEE,CAAC,iBACD,eAAe;AAAA,IACf;AACA,QAAI,oBAAoB,SAAS,MAAM,IAAI,UAAU,GAAG,MAAM,KAAK;AAEnE,QAAI,uBAAuB;AACzB,0BAAoB,kBAAkB,MAAM,CAAC;AAAA,IAC/C;AAEA,QAAI,QAAQ,QAAQ,QAAQ;AAC1B,2BAAqB,QAAQ,QAAQ;AAAA,IACvC;AAEA,WAAO,WAAW,SAAS,GAAG,QAAQ,GAAG,iBAAiB,IAAI,UAAU;AAAA,EAC1E;AAIA,SAAO,WAAW,SAAS,UAAU,UAAU;AACjD;AAYA,MAAM,gBAAgB,CACpB,QACA,MACAA,WACA,uBACA,WACW;AACX,MAAI,UAAU,GAAG,MAAM,GAAG,IAAI;AAE9B,YAAU,GAAGA,SAAQ,GAAG,wBAAwB,KAAK,GAAG,GAAG,OAAO;AAClE,MAAI,QAAQ;AACV,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAUA,MAAM,aAAa,CACjB,SACA,SACA,WACiB;AACjB,QAAM,WAAW,aAAa,QAAQ,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AASA,MAAM,cAAc,CAAC,SAAsB,YACzC,aAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["basePath"]}
@@ -1,20 +1,9 @@
1
- import { match } from "@formatjs/intl-localematcher";
2
- import { getConfiguration } from "@intlayer/config/client";
3
- import Negotiator from "negotiator";
4
- const { locales, defaultLocale } = getConfiguration().internationalization;
1
+ import { localeDetector as localeDetectorCore } from "@intlayer/core";
5
2
  const localeDetector = (request) => {
6
3
  const negotiatorHeaders = {};
7
4
  request.headers.forEach((value, key) => negotiatorHeaders[key] = value);
8
- const languages = new Negotiator({ headers: negotiatorHeaders }).languages();
9
- try {
10
- return match(languages, locales, defaultLocale);
11
- } catch (e) {
12
- console.warn(
13
- `No valid locales in accept-language header: ${languages.join(", ")}`
14
- );
15
- console.warn(`Reverting to using defaultLocale: ${defaultLocale}`);
16
- return defaultLocale;
17
- }
5
+ const locale = localeDetectorCore(negotiatorHeaders);
6
+ return locale;
18
7
  };
19
8
  export {
20
9
  localeDetector
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import { match } from '@formatjs/intl-localematcher';\nimport type { Locales } from '@intlayer/config';\nimport { getConfiguration } from '@intlayer/config/client';\nimport Negotiator from 'negotiator';\nimport type { NextRequest } from 'next/server.js';\n\nconst { locales, defaultLocale } = getConfiguration().internationalization;\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): Locales => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const languages = new Negotiator({ headers: negotiatorHeaders }).languages();\n\n // match can only use specifically formatted locales\n // https://stackoverflow.com/questions/76447732/nextjs-13-i18n-incorrect-locale-information-provided\n try {\n return match(languages, locales, defaultLocale) as Locales;\n } catch (e) {\n console.warn(\n `No valid locales in accept-language header: ${languages.join(', ')}`\n );\n console.warn(`Reverting to using defaultLocale: ${defaultLocale}`);\n\n return defaultLocale;\n }\n};\n"],"mappings":"AAAA,SAAS,aAAa;AAEtB,SAAS,wBAAwB;AACjC,OAAO,gBAAgB;AAGvB,MAAM,EAAE,SAAS,cAAc,IAAI,iBAAiB,EAAE;AAO/C,MAAM,iBAAiB,CAAC,YAAkC;AAC/D,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,YAAY,IAAI,WAAW,EAAE,SAAS,kBAAkB,CAAC,EAAE,UAAU;AAI3E,MAAI;AACF,WAAO,MAAM,WAAW,SAAS,aAAa;AAAA,EAChD,SAAS,GAAG;AACV,YAAQ;AAAA,MACN,+CAA+C,UAAU,KAAK,IAAI,CAAC;AAAA,IACrE;AACA,YAAQ,KAAK,qCAAqC,aAAa,EAAE;AAEjE,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/middleware/localeDetector.ts"],"sourcesContent":["import type { Locales } from '@intlayer/config';\nimport { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): Locales => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":"AACA,SAAS,kBAAkB,0BAA0B;AAQ9C,MAAM,iBAAiB,CAAC,YAAkC;AAC/D,QAAM,oBAA4C,CAAC;AAEnD,UAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAS,kBAAkB,GAAG,IAAI,KAAM;AAExE,QAAM,SAAS,mBAAmB,iBAAiB;AAEnD,SAAO;AACT;","names":[]}
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  getLocaleContent,
3
+ useDictionary,
3
4
  useTraduction,
4
5
  IntlayerServer,
5
6
  IntlayerServerProvider,
6
7
  locale,
7
- useIntlayer
8
+ useIntlayer,
9
+ t
8
10
  } from "react-intlayer/server";
9
11
  import { withIntlayer } from './withIntlayer.mjs';
10
12
  export {
@@ -12,6 +14,8 @@ export {
12
14
  IntlayerServerProvider,
13
15
  getLocaleContent,
14
16
  locale,
17
+ t,
18
+ useDictionary,
15
19
  useIntlayer,
16
20
  useTraduction,
17
21
  withIntlayer
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n getLocaleContent,\n useTraduction,\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n useIntlayer,\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,OACK;AACP,SAAS,oBAAoB;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/index.ts"],"sourcesContent":["export {\n getLocaleContent,\n useDictionary,\n useTraduction,\n IntlayerServer,\n IntlayerServerProvider,\n locale,\n useIntlayer,\n t,\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,OACK;AACP,SAAS,oBAAoB;","names":[]}
@@ -0,0 +1,5 @@
1
+ import type { FC } from 'react';
2
+ import { type IntlayerProviderProps } from 'react-intlayer';
3
+ export type IntlayerClientProviderProps = IntlayerProviderProps;
4
+ export declare const IntlayerClientProvider: FC<IntlayerProviderProps>;
5
+ //# sourceMappingURL=IntlayerClientProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlayerClientProvider.d.ts","sourceRoot":"","sources":["../../../src/client/IntlayerClientProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAoB,KAAK,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAG9E,MAAM,MAAM,2BAA2B,GAAG,qBAAqB,CAAC;AAEhE,eAAO,MAAM,sBAAsB,EAAE,EAAE,CAAC,qBAAqB,CAG5D,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { getTranslation, IntlayerClientContext, useIntlayer, useTraduction, useLocaleCookie, } from 'react-intlayer';
2
+ export { useLocale } from './useLocale';
3
+ export { IntlayerClientProvider, type IntlayerClientProviderProps, } from './IntlayerClientProvider';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,aAAa,EACb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type Locales } from '@intlayer/config/client';
2
+ export declare const useLocale: () => {
3
+ setLocale: (locale: Locales) => void;
4
+ pathWithoutLocale: string;
5
+ locale: import("intlayer").Locales;
6
+ defaultLocale: import("intlayer").Locales;
7
+ availableLocales: import("intlayer").Locales[];
8
+ localeList: import("intlayer").Locales[];
9
+ };
10
+ //# sourceMappingURL=useLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,yBAAyB,CAAC;AAKzE,eAAO,MAAM,SAAS;wBAiDT,OAAO;;mBApDP,UAAU;0BACA,UAAU;6BAE1B,UAAU;uBAGZ,UAAO;CA+EX,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const generateStaticParams: () => {
2
+ locale: import("intlayer").Locales;
3
+ }[];
4
+ //# sourceMappingURL=generateStaticParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateStaticParams.d.ts","sourceRoot":"","sources":["../../src/generateStaticParams.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB;;GAA8C,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { getTranslation, IntlayerClientContext, useIntlayer, useTraduction, useDictionary, useLocaleCookie, type IntlayerNode, t, } from 'react-intlayer';
2
+ export { generateStaticParams } from './generateStaticParams';
3
+ export type { LocalParams, NextPageIntlayer, NextLayoutIntlayer, } from './types/index';
4
+ export { useLocale, IntlayerClientProvider, type IntlayerClientProviderProps, } from './client/index';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,SAAS,EACT,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './intlayerMiddleware';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { type NextFetchEvent, type NextRequest, NextResponse } from 'next/server';
2
+ /**
3
+ * Middleware that handles the internationalization layer
4
+ *
5
+ * Usage:
6
+ *
7
+ * ```ts
8
+ * // ./src/middleware.ts
9
+ *
10
+ * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';
11
+ *
12
+ * // applies this middleware only to files in the app directory
13
+ * export const config = {
14
+ * matcher: '/((?!api|static|.*\\..*|_next).*)',
15
+ * };
16
+ * ```
17
+ *
18
+ * Main middleware function for handling internationalization.
19
+ *
20
+ * @param request - The incoming Next.js request object.
21
+ * @param event - The Next.js fetch event (optional).
22
+ * @param response - The Next.js response object (optional).
23
+ * @returns - The response to be returned to the client.
24
+ */
25
+ export declare const intlayerMiddleware: (request: NextRequest, _event?: NextFetchEvent, _response?: NextResponse) => NextResponse;
26
+ //# sourceMappingURL=intlayerMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intlayerMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middleware/intlayerMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAcrB;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,kBAAkB,YACpB,WAAW,WACX,cAAc,cACX,YAAY,KACvB,YAyBF,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { Locales } from '@intlayer/config';
2
+ import type { NextRequest } from 'next/server.js';
3
+ /**
4
+ * Detects the locale from the request headers
5
+ *
6
+ * Headers are provided by the browser and can be used to determine the user's preferred language
7
+ */
8
+ export declare const localeDetector: (request: NextRequest) => Locales;
9
+ //# sourceMappingURL=localeDetector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeDetector.d.ts","sourceRoot":"","sources":["../../../src/middleware/localeDetector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,cAAc,YAAa,WAAW,KAAG,OAQrD,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { getLocaleContent, useDictionary, useTraduction, IntlayerServer, IntlayerServerProvider, locale, useIntlayer, t, } from 'react-intlayer/server';
2
+ export { withIntlayer } from './withIntlayer';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,MAAM,EACN,WAAW,EACX,CAAC,GACF,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,6 +1,4 @@
1
- import 'react-intlayer/server';
2
- import { NextConfig } from 'next';
3
-
1
+ import type { NextConfig } from 'next';
4
2
  /**
5
3
  * A Next.js plugin that adds the intlayer configuration to the webpack configuration
6
4
  * and sets the environment variables
@@ -13,6 +11,5 @@ import { NextConfig } from 'next';
13
11
  * ```
14
12
  *
15
13
  */
16
- declare const withIntlayer: (nextConfig?: Partial<NextConfig>) => Partial<NextConfig>;
17
-
18
- export { withIntlayer };
14
+ export declare const withIntlayer: (nextConfig?: Partial<NextConfig>) => Partial<NextConfig>;
15
+ //# sourceMappingURL=withIntlayer.d.ts.map
@@ -0,0 +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,CAgEpB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Locales } from 'intlayer';
2
+ import type { NextPage } from 'next';
3
+ import type { PropsWithChildren } from 'react';
4
+ export type LocalParams<T = undefined> = {
5
+ params: {
6
+ locale: Locales;
7
+ } & T;
8
+ };
9
+ export type NextPageIntlayer<T = undefined> = NextPage<LocalParams<T>>;
10
+ export type NextLayoutIntlayer<T = undefined> = NextPage<PropsWithChildren<LocalParams<T>>>;
11
+ //# sourceMappingURL=NextPage.d.ts.map
@@ -0,0 +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;AAE/C,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,gBAAgB,CAAC,CAAC,GAAG,SAAS,IAAI,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,SAAS,IAAI,QAAQ,CACtD,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAClC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type { LocalParams, NextPageIntlayer, NextLayoutIntlayer, } from './NextPage';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intlayer",
3
- "version": "2.0.13",
3
+ "version": "3.0.0",
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": [
@@ -15,42 +15,42 @@
15
15
  ],
16
16
  "homepage": "https://intlayer.org",
17
17
  "bugs": {
18
- "url": "https://github.com/aypineau/intlayer/issues"
18
+ "url": "https://github.com/aymericzip/intlayer/issues"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "git+https://github.com/aypineau/intlayer.git"
22
+ "url": "git+https://github.com/aymericzip/intlayer.git"
23
23
  },
24
24
  "license": "Apache-2.0",
25
25
  "author": {
26
26
  "name": "Aymeric PINEAU",
27
- "url": "https://github.com/aypineau"
27
+ "url": "https://github.com/aymericzip"
28
28
  },
29
29
  "contributors": [
30
30
  {
31
31
  "name": "Aymeric Pineau",
32
32
  "email": "ay.pineau@gmail.com",
33
- "url": "https://github.com/aypineau"
33
+ "url": "https://github.com/aymericzip"
34
34
  }
35
35
  ],
36
36
  "exports": {
37
37
  ".": {
38
- "types": "./dist/esm/index.d.mts",
38
+ "types": "./dist/types/index.d.ts",
39
39
  "require": "./dist/cjs/index.cjs",
40
40
  "import": "./dist/esm/index.mjs"
41
41
  },
42
42
  "./client": {
43
- "types": "./dist/esm/client/index.d.mts",
43
+ "types": "./dist/types/client/index.d.ts",
44
44
  "require": "./dist/cjs/client/index.cjs",
45
45
  "import": "./dist/esm/client/index.mjs"
46
46
  },
47
47
  "./middleware": {
48
- "types": "./dist/esm/middleware/index.d.mts",
48
+ "types": "./dist/types/middleware/index.d.ts",
49
49
  "require": "./dist/cjs/middleware/index.cjs",
50
50
  "import": "./dist/esm/middleware/index.mjs"
51
51
  },
52
52
  "./server": {
53
- "types": "./dist/esm/server/index.d.mts",
53
+ "types": "./dist/types/server/index.d.ts",
54
54
  "require": "./dist/cjs/server/index.cjs",
55
55
  "import": "./dist/esm/server/index.mjs"
56
56
  },
@@ -58,6 +58,7 @@
58
58
  },
59
59
  "main": "dist/cjs/index.cjs",
60
60
  "module": "dist/esm/index.mjs",
61
+ "types": "dist/types/index.d.ts",
61
62
  "typesVersions": {
62
63
  "*": {
63
64
  "package.json": [
@@ -70,28 +71,31 @@
70
71
  "./package.json"
71
72
  ],
72
73
  "dependencies": {
73
- "@formatjs/intl-localematcher": "^0.5.4",
74
- "negotiator": "^0.6.3",
75
- "next": "14.2.5",
74
+ "next": "14.2.16",
76
75
  "webpack": "^5.93.0",
77
- "@intlayer/chokidar": "^2.0.13",
78
- "@intlayer/config": "^2.0.13",
79
- "@intlayer/core": "^2.0.13",
80
- "@intlayer/dictionaries-entry": "^2.0.13",
81
- "intlayer": "^2.0.13",
82
- "@intlayer/webpack": "^2.0.13",
83
- "react-intlayer": "^2.0.13"
76
+ "@intlayer/chokidar": "^3.0.0",
77
+ "@intlayer/config": "^3.0.0",
78
+ "@intlayer/core": "^3.0.0",
79
+ "@intlayer/dictionaries-entry": "^3.0.0",
80
+ "@intlayer/webpack": "^3.0.0",
81
+ "intlayer": "^3.0.0",
82
+ "react-intlayer": "^3.0.0"
84
83
  },
85
84
  "devDependencies": {
86
- "@types/negotiator": "^0.6.3",
87
85
  "@types/node": "^22.1.0",
88
86
  "@types/react": "^18.3.3",
87
+ "concurrently": "^8.2.2",
88
+ "eslint": "^9.11.1",
89
+ "prettier": "3.3.3",
89
90
  "react": "^18.3.1",
90
91
  "rimraf": "6.0.1",
91
- "tsup": "^8.2.4",
92
+ "tsc-alias": "^1.8.10",
93
+ "tsup": "^8.3.0",
92
94
  "typescript": "^5.5.4",
93
95
  "@utils/eslint-config": "^1.0.4",
94
- "@utils/ts-config": "^1.0.4"
96
+ "@utils/ts-config": "^1.0.4",
97
+ "@utils/ts-config-types": "^1.0.4",
98
+ "@utils/tsup-config": "^1.0.4"
95
99
  },
96
100
  "peerDependencies": {
97
101
  "react": "^18.2.0"
@@ -100,16 +104,19 @@
100
104
  "node": ">=14.18"
101
105
  },
102
106
  "bug": {
103
- "url": "https://github.com/aypineau/intlayer/issues"
107
+ "url": "https://github.com/aymericzip/intlayer/issues"
104
108
  },
105
109
  "scripts": {
106
- "build": "tsup",
110
+ "build": "pnpm build:package & pnpm build:types",
111
+ "build:package": "tsup",
112
+ "build:types": "tsc --project ./tsconfig.types.json && tsc-alias --project ./tsconfig.types.json",
107
113
  "clean": "rimraf ./dist",
108
- "dev": "tsup --watch",
109
- "lint": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs",
110
- "lint:fix": "eslint . --ext .ts,.tsx,.js,.jsx,.cjs,.mjs --fix",
111
- "prettier:fix": "prettier --write src/**/*",
114
+ "dev": "concurrently --prefix none \"tsup --watch\" \"tsc --project ./tsconfig.types.json --watch\" \"tsc-alias --project ./tsconfig.types.json --watch\"",
115
+ "lint": "eslint . --cache",
116
+ "lint:fix": "eslint . --cache --fix",
117
+ "prettier": "prettier . --check",
118
+ "prettier:fix": "prettier . --write",
112
119
  "test": "",
113
- "typecheck": "tsup--project ./tsconfig.json --noEmit"
120
+ "typecheck": "tsup --project ./tsconfig.json --noEmit"
114
121
  }
115
122
  }
@@ -1,7 +0,0 @@
1
- import { FC } from 'react';
2
- import { IntlayerProviderProps } from 'react-intlayer';
3
-
4
- type IntlayerClientProviderProps = IntlayerProviderProps;
5
- declare const IntlayerClientProvider: FC<IntlayerProviderProps>;
6
-
7
- export { IntlayerClientProvider, type IntlayerClientProviderProps };
@@ -1,5 +0,0 @@
1
- export { IntlayerClientContext, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
- export { useLocale } from './useLocale.js';
3
- export { IntlayerClientProvider, IntlayerClientProviderProps } from './IntlayerClientProvider.js';
4
- import '@intlayer/config/client';
5
- import 'react';
@@ -1,11 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
-
3
- declare const useLocale: () => {
4
- setLocale: (locale: Locales) => void;
5
- locale: Locales;
6
- defaultLocale: Locales;
7
- availableLocales: Locales[];
8
- localeList: Locales[];
9
- };
10
-
11
- export { useLocale };
@@ -1,7 +0,0 @@
1
- import * as _intlayer_config_client from '@intlayer/config/client';
2
-
3
- declare const generateStaticParams: () => {
4
- locale: _intlayer_config_client.Locales;
5
- }[];
6
-
7
- export { generateStaticParams };
@@ -1,9 +0,0 @@
1
- export { IntlayerClientContext, IntlayerNode, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
- export { generateStaticParams } from './generateStaticParams.js';
3
- export { LocalParams, NextLayoutIntlayer, NextPageIntlayer } from './types/NextPage.js';
4
- export { useLocale } from './client/useLocale.js';
5
- export { IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.js';
6
- import '@intlayer/config/client';
7
- import 'intlayer';
8
- import 'next';
9
- import 'react';
@@ -1,2 +0,0 @@
1
- export { intlayerMiddleware } from './intlayerMiddleware.js';
2
- import 'next/server';
@@ -1,22 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
-
3
- /**
4
- * Middleware that handles the internationalization layer
5
- *
6
- * Usage:
7
- *
8
- * // ./src/middleware.ts
9
- *
10
- * ```ts
11
- * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';
12
- *
13
- * // applies this middleware only to files in the app directory
14
- * export const config = {
15
- * matcher: '/((?!api|static|.*\\..*|_next).*)',
16
- * };
17
- * ```
18
- *
19
- */
20
- declare const intlayerMiddleware: (request: NextRequest) => NextResponse;
21
-
22
- export { intlayerMiddleware };
@@ -1,11 +0,0 @@
1
- import { Locales } from '@intlayer/config';
2
- import { NextRequest } from 'next/server.js';
3
-
4
- /**
5
- * Detects the locale from the request headers
6
- *
7
- * Headers are provided by the browser and can be used to determine the user's preferred language
8
- */
9
- declare const localeDetector: (request: NextRequest) => Locales;
10
-
11
- export { localeDetector };
@@ -1,3 +0,0 @@
1
- export { IntlayerServer, IntlayerServerProvider, getLocaleContent, locale, useIntlayer, useTraduction } from 'react-intlayer/server';
2
- export { withIntlayer } from './withIntlayer.js';
3
- import 'next';
@@ -1,13 +0,0 @@
1
- import { Locales } from 'intlayer';
2
- import { NextPage } from 'next';
3
- import { PropsWithChildren } from 'react';
4
-
5
- type LocalParams<T = undefined> = {
6
- params: {
7
- locale: Locales;
8
- } & T;
9
- };
10
- type NextPageIntlayer<T = undefined> = NextPage<LocalParams<T>>;
11
- type NextLayoutIntlayer<T = undefined> = NextPage<PropsWithChildren<LocalParams<T>>>;
12
-
13
- export type { LocalParams, NextLayoutIntlayer, NextPageIntlayer };
@@ -1,4 +0,0 @@
1
- export { LocalParams, NextLayoutIntlayer, NextPageIntlayer } from './NextPage.js';
2
- import 'intlayer';
3
- import 'next';
4
- import 'react';
@@ -1,7 +0,0 @@
1
- import { FC } from 'react';
2
- import { IntlayerProviderProps } from 'react-intlayer';
3
-
4
- type IntlayerClientProviderProps = IntlayerProviderProps;
5
- declare const IntlayerClientProvider: FC<IntlayerProviderProps>;
6
-
7
- export { IntlayerClientProvider, type IntlayerClientProviderProps };
@@ -1,5 +0,0 @@
1
- export { IntlayerClientContext, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
- export { useLocale } from './useLocale.mjs';
3
- export { IntlayerClientProvider, IntlayerClientProviderProps } from './IntlayerClientProvider.mjs';
4
- import '@intlayer/config/client';
5
- import 'react';
@@ -1,11 +0,0 @@
1
- import { Locales } from '@intlayer/config/client';
2
-
3
- declare const useLocale: () => {
4
- setLocale: (locale: Locales) => void;
5
- locale: Locales;
6
- defaultLocale: Locales;
7
- availableLocales: Locales[];
8
- localeList: Locales[];
9
- };
10
-
11
- export { useLocale };
@@ -1,7 +0,0 @@
1
- import * as _intlayer_config_client from '@intlayer/config/client';
2
-
3
- declare const generateStaticParams: () => {
4
- locale: _intlayer_config_client.Locales;
5
- }[];
6
-
7
- export { generateStaticParams };
@@ -1,9 +0,0 @@
1
- export { IntlayerClientContext, IntlayerNode, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
- export { generateStaticParams } from './generateStaticParams.mjs';
3
- export { LocalParams, NextLayoutIntlayer, NextPageIntlayer } from './types/NextPage.mjs';
4
- export { useLocale } from './client/useLocale.mjs';
5
- export { IntlayerClientProvider, IntlayerClientProviderProps } from './client/IntlayerClientProvider.mjs';
6
- import '@intlayer/config/client';
7
- import 'intlayer';
8
- import 'next';
9
- import 'react';
@@ -1,2 +0,0 @@
1
- export { intlayerMiddleware } from './intlayerMiddleware.mjs';
2
- import 'next/server';
@@ -1,22 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server';
2
-
3
- /**
4
- * Middleware that handles the internationalization layer
5
- *
6
- * Usage:
7
- *
8
- * // ./src/middleware.ts
9
- *
10
- * ```ts
11
- * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';
12
- *
13
- * // applies this middleware only to files in the app directory
14
- * export const config = {
15
- * matcher: '/((?!api|static|.*\\..*|_next).*)',
16
- * };
17
- * ```
18
- *
19
- */
20
- declare const intlayerMiddleware: (request: NextRequest) => NextResponse;
21
-
22
- export { intlayerMiddleware };