next-intlayer 6.1.6 → 7.0.0-canary.2

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 (144) hide show
  1. package/dist/cjs/_virtual/rolldown_runtime.cjs +25 -0
  2. package/dist/cjs/client/IntlayerClientProvider.cjs +19 -33
  3. package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
  4. package/dist/cjs/client/format/index.cjs +50 -41
  5. package/dist/cjs/client/index.cjs +7 -35
  6. package/dist/cjs/client/useLocale.cjs +39 -54
  7. package/dist/cjs/client/useLocale.cjs.map +1 -1
  8. package/dist/cjs/client/useLocalePageRouter.cjs +26 -52
  9. package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
  10. package/dist/cjs/generateStaticParams.cjs +9 -39
  11. package/dist/cjs/generateStaticParams.cjs.map +1 -1
  12. package/dist/cjs/index.cjs +102 -57
  13. package/dist/cjs/middleware/index.cjs +7 -27
  14. package/dist/cjs/middleware/intlayerMiddleware.cjs +206 -188
  15. package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -1
  16. package/dist/cjs/middleware/localeDetector.cjs +18 -32
  17. package/dist/cjs/middleware/localeDetector.cjs.map +1 -1
  18. package/dist/cjs/middleware/multipleMiddlewares.cjs +55 -67
  19. package/dist/cjs/middleware/multipleMiddlewares.cjs.map +1 -1
  20. package/dist/cjs/proxy/index.cjs +9 -0
  21. package/dist/cjs/proxy/intlayerProxy.cjs +252 -0
  22. package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -0
  23. package/dist/cjs/proxy/localeDetector.cjs +21 -0
  24. package/dist/cjs/proxy/localeDetector.cjs.map +1 -0
  25. package/dist/cjs/proxy/multipleProxies.cjs +60 -0
  26. package/dist/cjs/proxy/multipleProxies.cjs.map +1 -0
  27. package/dist/cjs/proxy/multipleProxy.cjs +60 -0
  28. package/dist/cjs/proxy/multipleProxy.cjs.map +1 -0
  29. package/dist/cjs/server/compareVersion.cjs +35 -54
  30. package/dist/cjs/server/compareVersion.cjs.map +1 -1
  31. package/dist/cjs/server/format/index.cjs +50 -41
  32. package/dist/cjs/server/getLocale.cjs +31 -53
  33. package/dist/cjs/server/getLocale.cjs.map +1 -1
  34. package/dist/cjs/server/index.cjs +69 -53
  35. package/dist/cjs/server/withIntlayer.cjs +181 -247
  36. package/dist/cjs/server/withIntlayer.cjs.map +1 -1
  37. package/dist/cjs/types/NextPage.cjs +0 -17
  38. package/dist/cjs/types/index.cjs +0 -17
  39. package/dist/esm/client/IntlayerClientProvider.mjs +15 -8
  40. package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
  41. package/dist/esm/client/format/index.mjs +3 -21
  42. package/dist/esm/client/index.mjs +3 -9
  43. package/dist/esm/client/useLocale.mjs +31 -27
  44. package/dist/esm/client/useLocale.mjs.map +1 -1
  45. package/dist/esm/client/useLocalePageRouter.mjs +19 -26
  46. package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
  47. package/dist/esm/generateStaticParams.mjs +5 -3
  48. package/dist/esm/generateStaticParams.mjs.map +1 -1
  49. package/dist/esm/index.mjs +6 -34
  50. package/dist/esm/middleware/index.mjs +5 -4
  51. package/dist/esm/middleware/intlayerMiddleware.mjs +201 -155
  52. package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -1
  53. package/dist/esm/middleware/localeDetector.mjs +16 -8
  54. package/dist/esm/middleware/localeDetector.mjs.map +1 -1
  55. package/dist/esm/middleware/multipleMiddlewares.mjs +53 -45
  56. package/dist/esm/middleware/multipleMiddlewares.mjs.map +1 -1
  57. package/dist/esm/proxy/index.mjs +5 -0
  58. package/dist/esm/proxy/intlayerProxy.mjs +247 -0
  59. package/dist/esm/proxy/intlayerProxy.mjs.map +1 -0
  60. package/dist/esm/proxy/localeDetector.mjs +19 -0
  61. package/dist/esm/proxy/localeDetector.mjs.map +1 -0
  62. package/dist/esm/proxy/multipleProxies.mjs +57 -0
  63. package/dist/esm/proxy/multipleProxies.mjs.map +1 -0
  64. package/dist/esm/proxy/multipleProxy.mjs +57 -0
  65. package/dist/esm/proxy/multipleProxy.mjs.map +1 -0
  66. package/dist/esm/server/compareVersion.mjs +34 -30
  67. package/dist/esm/server/compareVersion.mjs.map +1 -1
  68. package/dist/esm/server/format/index.mjs +3 -21
  69. package/dist/esm/server/getLocale.mjs +23 -17
  70. package/dist/esm/server/getLocale.mjs.map +1 -1
  71. package/dist/esm/server/index.mjs +4 -28
  72. package/dist/esm/server/withIntlayer.mjs +166 -214
  73. package/dist/esm/server/withIntlayer.mjs.map +1 -1
  74. package/dist/esm/types/NextPage.mjs +0 -1
  75. package/dist/esm/types/index.mjs +0 -1
  76. package/dist/types/client/IntlayerClientProvider.d.ts +8 -4
  77. package/dist/types/client/IntlayerClientProvider.d.ts.map +1 -1
  78. package/dist/types/client/format/index.d.ts +2 -2
  79. package/dist/types/client/index.d.ts +4 -4
  80. package/dist/types/client/useLocale.d.ts +17 -7
  81. package/dist/types/client/useLocale.d.ts.map +1 -1
  82. package/dist/types/client/useLocalePageRouter.d.ts +12 -7
  83. package/dist/types/client/useLocalePageRouter.d.ts.map +1 -1
  84. package/dist/types/generateStaticParams.d.ts +7 -2
  85. package/dist/types/generateStaticParams.d.ts.map +1 -1
  86. package/dist/types/index.d.ts +7 -5
  87. package/dist/types/middleware/index.d.ts +4 -4
  88. package/dist/types/middleware/intlayerMiddleware.d.ts +7 -2
  89. package/dist/types/middleware/intlayerMiddleware.d.ts.map +1 -1
  90. package/dist/types/middleware/localeDetector.d.ts +8 -3
  91. package/dist/types/middleware/localeDetector.d.ts.map +1 -1
  92. package/dist/types/middleware/multipleMiddlewares.d.ts +7 -2
  93. package/dist/types/middleware/multipleMiddlewares.d.ts.map +1 -1
  94. package/dist/types/proxy/index.d.ts +4 -0
  95. package/dist/types/proxy/intlayerProxy.d.ts +55 -0
  96. package/dist/types/proxy/intlayerProxy.d.ts.map +1 -0
  97. package/dist/types/proxy/localeDetector.d.ts +14 -0
  98. package/dist/types/proxy/localeDetector.d.ts.map +1 -0
  99. package/dist/types/proxy/multipleProxies.d.ts +34 -0
  100. package/dist/types/proxy/multipleProxies.d.ts.map +1 -0
  101. package/dist/types/proxy/multipleProxy.d.ts +34 -0
  102. package/dist/types/proxy/multipleProxy.d.ts.map +1 -0
  103. package/dist/types/server/compareVersion.d.ts +4 -1
  104. package/dist/types/server/compareVersion.d.ts.map +1 -1
  105. package/dist/types/server/format/index.d.ts +2 -2
  106. package/dist/types/server/getLocale.d.ts +6 -2
  107. package/dist/types/server/getLocale.d.ts.map +1 -1
  108. package/dist/types/server/index.d.ts +4 -4
  109. package/dist/types/server/withIntlayer.d.ts +25 -3
  110. package/dist/types/server/withIntlayer.d.ts.map +1 -1
  111. package/dist/types/types/NextPage.d.ts +21 -17
  112. package/dist/types/types/NextPage.d.ts.map +1 -1
  113. package/dist/types/types/index.d.ts +2 -2
  114. package/package.json +48 -50
  115. package/LICENSE +0 -202
  116. package/dist/cjs/client/format/index.cjs.map +0 -1
  117. package/dist/cjs/client/index.cjs.map +0 -1
  118. package/dist/cjs/index.cjs.map +0 -1
  119. package/dist/cjs/middleware/index.cjs.map +0 -1
  120. package/dist/cjs/server/format/index.cjs.map +0 -1
  121. package/dist/cjs/server/getNextVertion.cjs +0 -39
  122. package/dist/cjs/server/getNextVertion.cjs.map +0 -1
  123. package/dist/cjs/server/index.cjs.map +0 -1
  124. package/dist/cjs/types/NextPage.cjs.map +0 -1
  125. package/dist/cjs/types/index.cjs.map +0 -1
  126. package/dist/esm/client/format/index.mjs.map +0 -1
  127. package/dist/esm/client/index.mjs.map +0 -1
  128. package/dist/esm/index.mjs.map +0 -1
  129. package/dist/esm/middleware/index.mjs.map +0 -1
  130. package/dist/esm/server/format/index.mjs.map +0 -1
  131. package/dist/esm/server/getNextVertion.mjs +0 -15
  132. package/dist/esm/server/getNextVertion.mjs.map +0 -1
  133. package/dist/esm/server/index.mjs.map +0 -1
  134. package/dist/esm/types/NextPage.mjs.map +0 -1
  135. package/dist/esm/types/index.mjs.map +0 -1
  136. package/dist/types/client/format/index.d.ts.map +0 -1
  137. package/dist/types/client/index.d.ts.map +0 -1
  138. package/dist/types/index.d.ts.map +0 -1
  139. package/dist/types/middleware/index.d.ts.map +0 -1
  140. package/dist/types/server/format/index.d.ts.map +0 -1
  141. package/dist/types/server/getNextVertion.d.ts +0 -2
  142. package/dist/types/server/getNextVertion.d.ts.map +0 -1
  143. package/dist/types/server/index.d.ts.map +0 -1
  144. package/dist/types/types/index.d.ts.map +0 -1
@@ -1,32 +1,36 @@
1
- "use client";
1
+ 'use client';
2
+
3
+
4
+ import { useLocale as useLocale$1 } from "react-intlayer";
2
5
  import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core";
3
6
  import { usePathname, useRouter } from "next/navigation.js";
4
7
  import { useCallback, useMemo } from "react";
5
- import { useLocale as useLocaleReact } from "react-intlayer";
6
- const useLocale = () => {
7
- const { push, refresh } = useRouter();
8
- const pathname = usePathname();
9
- const pathWithoutLocale = useMemo(
10
- () => getPathWithoutLocale(pathname),
11
- [pathname]
12
- );
13
- const redirectionFunction = useCallback(
14
- (locale) => {
15
- const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
16
- push(pathWithLocale);
17
- return refresh();
18
- },
19
- [refresh, pathWithoutLocale]
20
- );
21
- const reactLocaleHook = useLocaleReact({
22
- onLocaleChange: redirectionFunction
23
- });
24
- return {
25
- ...reactLocaleHook,
26
- pathWithoutLocale
27
- };
28
- };
29
- export {
30
- useLocale
8
+
9
+ //#region src/client/useLocale.ts
10
+ const useLocale = ({ onChange } = {}) => {
11
+ const { replace, push } = useRouter();
12
+ const pathname = usePathname();
13
+ const pathWithoutLocale = useMemo(() => getPathWithoutLocale(pathname), [pathname]);
14
+ return {
15
+ ...useLocale$1({ onLocaleChange: useCallback((locale) => {
16
+ if (!onChange) return;
17
+ if (typeof onChange === "function") {
18
+ onChange(locale);
19
+ return;
20
+ }
21
+ const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
22
+ if (onChange === "replace") replace(pathWithLocale);
23
+ if (onChange === "push") push(pathWithLocale);
24
+ }, [
25
+ replace,
26
+ push,
27
+ pathWithoutLocale,
28
+ onChange
29
+ ]) }),
30
+ pathWithoutLocale
31
+ };
31
32
  };
33
+
34
+ //#endregion
35
+ export { useLocale };
32
36
  //# sourceMappingURL=useLocale.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { type LocalesValues } from '@intlayer/config/client';\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocale = () => {\n const { push, refresh } = useRouter();\n const pathname = usePathname();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return refresh();\n },\n [refresh, pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";AAGA,SAAS,iBAAiB,4BAA4B;AACtD,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,sBAAsB;AAErC,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,MAAM,QAAQ,IAAI,UAAU;AACpC,QAAM,WAAW,YAAY;AAC7B,QAAM,oBAAoB;AAAA,IACxB,MAAM,qBAAqB,QAAQ;AAAA,IACnC,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,sBAAsB;AAAA,IAC1B,CAAC,WAA0B;AACzB,YAAM,iBAAiB,gBAAgB,mBAAmB,MAAM;AAEhE,WAAK,cAAc;AAEnB,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,CAAC,SAAS,iBAAiB;AAAA,EAC7B;AAEA,QAAM,kBAAkB,eAAe;AAAA,IACrC,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathname = usePathname();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAYA,MAAa,aAAa,EAAE,aAA6B,EAAE,KAAK;CAC9D,MAAM,EAAE,SAAS,SAAS,WAAW;CACrC,MAAM,WAAW,aAAa;CAC9B,MAAM,oBAAoB,cAClB,qBAAqB,SAAS,EACpC,CAAC,SAAS,CACX;AA2BD,QAAO;EACL,GALsBA,YAAe,EACrC,gBAtB0B,aACzB,WAA0B;AACzB,OAAI,CAAC,SAAU;AAEf,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS,OAAO;AAChB;;GAGF,MAAM,iBAAiB,gBAAgB,mBAAmB,OAAO;AAEjE,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAC7C,EAIA,CAAC;EAIA;EACD"}
@@ -1,31 +1,24 @@
1
- "use client";
1
+ 'use client';
2
+
3
+
4
+ import { useLocale } from "react-intlayer";
2
5
  import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core";
3
- import { useRouter } from "next/router.js";
4
6
  import { useCallback, useMemo } from "react";
5
- import { useLocale as useLocaleReact } from "react-intlayer";
7
+ import { useRouter } from "next/router.js";
8
+
9
+ //#region src/client/useLocalePageRouter.ts
6
10
  const useLocalePageRouter = () => {
7
- const { push, pathname, reload } = useRouter();
8
- const pathWithoutLocale = useMemo(
9
- () => getPathWithoutLocale(pathname),
10
- [pathname]
11
- );
12
- const redirectionFunction = useCallback(
13
- (locale) => {
14
- const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
15
- push(pathWithLocale);
16
- return reload();
17
- },
18
- [pathWithoutLocale]
19
- );
20
- const reactLocaleHook = useLocaleReact({
21
- onLocaleChange: redirectionFunction
22
- });
23
- return {
24
- ...reactLocaleHook,
25
- pathWithoutLocale
26
- };
27
- };
28
- export {
29
- useLocalePageRouter
11
+ const { push, pathname, reload } = useRouter();
12
+ const pathWithoutLocale = useMemo(() => getPathWithoutLocale(pathname), [pathname]);
13
+ return {
14
+ ...useLocale({ onLocaleChange: useCallback((locale) => {
15
+ push(getLocalizedUrl(pathWithoutLocale, locale));
16
+ return reload();
17
+ }, [pathWithoutLocale]) }),
18
+ pathWithoutLocale
19
+ };
30
20
  };
21
+
22
+ //#endregion
23
+ export { useLocalePageRouter };
31
24
  //# sourceMappingURL=useLocalePageRouter.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { LocalesValues } from '@intlayer/config/client';\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";AAGA,SAAS,iBAAiB,4BAA4B;AACtD,SAAS,iBAAiB;AAC1B,SAAS,aAAa,eAAe;AACrC,SAAS,aAAa,sBAAsB;AAErC,MAAM,sBAAsB,MAAM;AACvC,QAAM,EAAE,MAAM,UAAU,OAAO,IAAI,UAAU;AAC7C,QAAM,oBAAoB;AAAA,IACxB,MAAM,qBAAqB,QAAQ;AAAA,IACnC,CAAC,QAAQ;AAAA,EACX;AAEA,QAAM,sBAAsB;AAAA,IAC1B,CAAC,WAA0B;AACzB,YAAM,iBAAiB,gBAAgB,mBAAmB,MAAM;AAEhE,WAAK,cAAc;AAEnB,aAAO,OAAO;AAAA,IAChB;AAAA,IACA,CAAC,iBAAiB;AAAA,EACpB;AAEA,QAAM,kBAAkB,eAAe;AAAA,IACrC,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,WAAW,WAAW;CAC9C,MAAM,oBAAoB,cAClB,qBAAqB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,GALsBA,UAAe,EACrC,gBAZ0B,aACzB,WAA0B;AAGzB,QAFuB,gBAAgB,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}
@@ -1,7 +1,9 @@
1
1
  import configuration from "@intlayer/config/built";
2
+
3
+ //#region src/generateStaticParams.ts
2
4
  const { locales } = configuration.internationalization;
3
5
  const generateStaticParams = () => locales.map((locale) => ({ locale }));
4
- export {
5
- generateStaticParams
6
- };
6
+
7
+ //#endregion
8
+ export { generateStaticParams };
7
9
  //# sourceMappingURL=generateStaticParams.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,MAAM,EAAE,QAAQ,IAAI,cAAc;AAE3B,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
1
+ {"version":3,"file":"generateStaticParams.mjs","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;AAEA,MAAM,EAAE,YAAY,cAAc;AAElC,MAAa,6BAA6B,QAAQ,KAAK,YAAY,EAAE,QAAQ,EAAE"}
@@ -1,35 +1,7 @@
1
- import {
2
- IntlayerClientContext,
3
- MarkdownProvider,
4
- t,
5
- useDictionary,
6
- useDictionaryAsync,
7
- useDictionaryDynamic,
8
- useI18n,
9
- useIntlayer,
10
- useLoadDynamic,
11
- useLocaleCookie
12
- } from "react-intlayer";
13
- import {
14
- IntlayerClientProvider,
15
- useLocale,
16
- useLocalePageRouter
17
- } from "./client/index.mjs";
18
1
  import { generateStaticParams } from "./generateStaticParams.mjs";
19
- export {
20
- IntlayerClientContext,
21
- IntlayerClientProvider,
22
- MarkdownProvider,
23
- generateStaticParams,
24
- t,
25
- useDictionary,
26
- useDictionaryAsync,
27
- useDictionaryDynamic,
28
- useI18n,
29
- useIntlayer,
30
- useLoadDynamic,
31
- useLocale,
32
- useLocaleCookie,
33
- useLocalePageRouter
34
- };
35
- //# sourceMappingURL=index.mjs.map
2
+ import { useLocale } from "./client/useLocale.mjs";
3
+ import { IntlayerClientProvider } from "./client/IntlayerClientProvider.mjs";
4
+ import { useLocalePageRouter } from "./client/useLocalePageRouter.mjs";
5
+ import { IntlayerClientContext, MarkdownProvider, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useLoadDynamic, useLocaleCookie, useLocaleStorage } from "react-intlayer";
6
+
7
+ export { IntlayerClientContext, IntlayerClientProvider, MarkdownProvider, generateStaticParams, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useLoadDynamic, useLocale, useLocaleCookie, useLocalePageRouter, useLocaleStorage };
@@ -1,4 +1,5 @@
1
- export * from "./intlayerMiddleware.mjs";
2
- export * from "./localeDetector.mjs";
3
- export * from "./multipleMiddlewares.mjs";
4
- //# sourceMappingURL=index.mjs.map
1
+ import { localeDetector } from "./localeDetector.mjs";
2
+ import { intlayerMiddleware } from "./intlayerMiddleware.mjs";
3
+ import { multipleMiddlewares } from "./multipleMiddlewares.mjs";
4
+
5
+ export { intlayerMiddleware, localeDetector, multipleMiddlewares };
@@ -1,177 +1,223 @@
1
+ import { localeDetector as localeDetector$1 } from "./localeDetector.mjs";
1
2
  import configuration from "@intlayer/config/built";
2
- import {
3
- NextResponse
4
- } from "next/server";
5
- import { localeDetector } from "./localeDetector.mjs";
6
- const { internationalization, middleware } = configuration;
7
- const { locales, defaultLocale } = internationalization;
8
- const {
9
- headerName,
10
- cookieName,
11
- prefixDefault,
12
- basePath,
13
- serverSetCookie,
14
- noPrefix,
15
- detectLocaleOnPrefetchNoPrefix
16
- } = middleware;
3
+ import { getLocaleFromStorage } from "@intlayer/core";
4
+ import { NextResponse } from "next/server";
5
+
6
+ //#region src/middleware/intlayerMiddleware.ts
7
+ const { internationalization, routing } = configuration ?? {};
8
+ const { locales, defaultLocale } = internationalization ?? {};
9
+ const { headerName, basePath, detectLocaleOnPrefetchNoPrefix, mode } = routing ?? {};
10
+ const noPrefix = mode === "no-prefix" || mode === "search-params";
11
+ const prefixDefault = mode === "prefix-all";
12
+ /**
13
+ * Detects if the request is a prefetch request from Next.js.
14
+ *
15
+ * Next.js prefetch requests can be identified by several headers:
16
+ * - purpose: 'prefetch' (standard prefetch header)
17
+ * - next-router-prefetch: '1' (Next.js router prefetch)
18
+ * - next-url: present (Next.js internal navigation)
19
+ *
20
+ * During prefetch, we should ignore cookie-based locale detection
21
+ * to prevent unwanted redirects when users are switching locales.
22
+ *
23
+ * @param request - The incoming Next.js request object.
24
+ * @returns - True if the request is a prefetch request, false otherwise.
25
+ */
17
26
  const isPrefetchRequest = (request) => {
18
- const purpose = request.headers.get("purpose");
19
- const nextRouterPrefetch = request.headers.get("next-router-prefetch");
20
- const nextUrl = request.headers.get("next-url");
21
- const xNextjsData = request.headers.get("x-nextjs-data");
22
- return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
27
+ const purpose = request.headers.get("purpose");
28
+ const nextRouterPrefetch = request.headers.get("next-router-prefetch");
29
+ const nextUrl = request.headers.get("next-url");
30
+ const xNextjsData = request.headers.get("x-nextjs-data");
31
+ return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
23
32
  };
24
- const intlayerMiddleware = (request, _event, _response) => {
25
- const pathname = request.nextUrl.pathname;
26
- const cookieLocale = getCookieLocale(request);
27
- const basePathTrailingSlash = basePath.endsWith("/");
28
- if (noPrefix) {
29
- return handleNoPrefix(
30
- request,
31
- cookieLocale,
32
- pathname,
33
- basePathTrailingSlash
34
- );
35
- }
36
- const pathLocale = getPathLocale(pathname);
37
- return handlePrefix(
38
- request,
39
- cookieLocale,
40
- pathLocale,
41
- pathname,
42
- basePathTrailingSlash
43
- );
33
+ const appendLocaleSearchIfNeeded = (search, locale) => {
34
+ if (mode !== "search-params") return search;
35
+ const params = new URLSearchParams(search ?? "");
36
+ params.set("locale", locale);
37
+ return `?${params.toString()}`;
44
38
  };
45
- const getCookieLocale = (request) => {
46
- if (!cookieName) return void 0;
47
- const cookieValue = request.cookies.get(cookieName)?.value;
48
- if (cookieValue && locales.includes(cookieValue)) {
49
- return cookieValue;
50
- }
39
+ /**
40
+ * Middleware that handles the internationalization layer
41
+ *
42
+ * Usage:
43
+ *
44
+ * ```ts
45
+ * // ./src/middleware.ts
46
+ *
47
+ * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';
48
+ *
49
+ * // applies this middleware only to files in the app directory
50
+ * export const config = {
51
+ * matcher: '/((?!api|static|.*\\..*|_next).*)',
52
+ * };
53
+ * ```
54
+ *
55
+ * Main middleware function for handling internationalization.
56
+ *
57
+ * @param request - The incoming Next.js request object.
58
+ * @param event - The Next.js fetch event (optional).
59
+ * @param response - The Next.js response object (optional).
60
+ * @returns - The response to be returned to the client.
61
+ */
62
+ const intlayerMiddleware = (request, _event, _response) => {
63
+ const pathname = request.nextUrl.pathname;
64
+ const cookieLocale = getCookieLocale(request);
65
+ const basePathTrailingSlash = basePath.endsWith("/");
66
+ if (noPrefix) return handleNoPrefix(request, cookieLocale, pathname, basePathTrailingSlash);
67
+ return handlePrefix(request, cookieLocale, getPathLocale(pathname), pathname, basePathTrailingSlash);
51
68
  };
69
+ /**
70
+ * Retrieves the locale from the request cookies if available and valid.
71
+ *
72
+ * @param request - The incoming Next.js request object.
73
+ * @returns - The locale found in the cookies, or undefined if not found or invalid.
74
+ */
75
+ const getCookieLocale = (request) => getLocaleFromStorage({ getCookie: (name) => request.cookies.get(name)?.value ?? null });
76
+ /**
77
+ * Handles the case where URLs do not have locale prefixes.
78
+ *
79
+ * @param request - The incoming Next.js request object.
80
+ * @param cookieLocale - The locale from the cookie.
81
+ * @param pathname - The pathname from the request URL.
82
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
83
+ * @returns - The rewritten response with the locale applied.
84
+ */
52
85
  const handleNoPrefix = (request, cookieLocale, pathname, basePathTrailingSlash) => {
53
- const locale = cookieLocale ?? defaultLocale;
54
- const newPath = constructPath(
55
- locale,
56
- pathname,
57
- basePath,
58
- basePathTrailingSlash,
59
- request.nextUrl.search
60
- );
61
- return rewriteUrl(request, newPath, locale);
86
+ const locale = cookieLocale ?? defaultLocale;
87
+ return rewriteUrl(request, constructPath(locale, pathname, basePath, basePathTrailingSlash, appendLocaleSearchIfNeeded(request.nextUrl.search, locale)), locale);
62
88
  };
63
- const getPathLocale = (pathname) => locales.find(
64
- (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
65
- );
89
+ /**
90
+ * Extracts the locale from the URL pathname if present.
91
+ *
92
+ * @param pathname - The pathname from the request URL.
93
+ * @returns - The locale found in the pathname, or undefined if not found.
94
+ */
95
+ const getPathLocale = (pathname) => locales.find((locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`);
96
+ /**
97
+ * Handles the case where URLs have locale prefixes.
98
+ *
99
+ * @param request - The incoming Next.js request object.
100
+ * @param cookieLocale - The locale from the cookie.
101
+ * @param pathLocale - The locale extracted from the pathname.
102
+ * @param pathname - The pathname from the request URL.
103
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
104
+ * @returns - The response to be returned to the client.
105
+ */
66
106
  const handlePrefix = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
67
- if (!pathLocale) {
68
- const isPrefetch = isPrefetchRequest(request);
69
- if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {
70
- return handleMissingPathLocale(
71
- request,
72
- defaultLocale,
73
- pathname,
74
- basePathTrailingSlash
75
- );
76
- }
77
- return handleMissingPathLocale(
78
- request,
79
- cookieLocale,
80
- pathname,
81
- basePathTrailingSlash
82
- );
83
- }
84
- return handleExistingPathLocale(
85
- request,
86
- cookieLocale,
87
- pathLocale,
88
- pathname,
89
- basePathTrailingSlash
90
- );
107
+ if (!pathLocale) {
108
+ if (isPrefetchRequest(request) && !detectLocaleOnPrefetchNoPrefix) return handleMissingPathLocale(request, defaultLocale, pathname, basePathTrailingSlash);
109
+ return handleMissingPathLocale(request, cookieLocale, pathname, basePathTrailingSlash);
110
+ }
111
+ return handleExistingPathLocale(request, cookieLocale, pathLocale, pathname, basePathTrailingSlash);
91
112
  };
113
+ /**
114
+ * Handles requests where the locale is missing from the URL pathname.
115
+ *
116
+ * @param request - The incoming Next.js request object.
117
+ * @param cookieLocale - The locale from the cookie.
118
+ * @param pathname - The pathname from the request URL.
119
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
120
+ * @returns - The response to be returned to the client.
121
+ */
92
122
  const handleMissingPathLocale = (request, cookieLocale, pathname, basePathTrailingSlash) => {
93
- let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;
94
- if (!locales.includes(locale)) {
95
- locale = defaultLocale;
96
- }
97
- const newPath = constructPath(
98
- locale,
99
- pathname,
100
- basePath,
101
- basePathTrailingSlash,
102
- request.nextUrl.search
103
- );
104
- return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
123
+ let locale = cookieLocale ?? localeDetector$1?.(request) ?? defaultLocale;
124
+ if (!locales.includes(locale)) locale = defaultLocale;
125
+ const newPath = constructPath(locale, pathname, basePath, basePathTrailingSlash, appendLocaleSearchIfNeeded(request.nextUrl.search, locale));
126
+ return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
105
127
  };
128
+ /**
129
+ * Handles requests where the locale exists in the URL pathname.
130
+ *
131
+ * @param request - The incoming Next.js request object.
132
+ * @param cookieLocale - The locale from the cookie.
133
+ * @param pathLocale - The locale extracted from the pathname.
134
+ * @param pathname - The pathname from the request URL.
135
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
136
+ * @returns - The response to be returned to the client.
137
+ */
106
138
  const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
107
- if (
108
- // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie
109
- cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always"
110
- ) {
111
- const newPath = handleCookieLocaleMismatch(
112
- request,
113
- pathname,
114
- pathLocale,
115
- cookieLocale,
116
- basePath,
117
- basePathTrailingSlash
118
- );
119
- return redirectUrl(request, newPath);
120
- }
121
- return handleDefaultLocaleRedirect(
122
- request,
123
- pathLocale,
124
- pathname,
125
- basePathTrailingSlash
126
- );
139
+ if (cookieLocale && cookieLocale !== pathLocale) return redirectUrl(request, handleCookieLocaleMismatch(request, pathname, pathLocale, cookieLocale, basePath, basePathTrailingSlash));
140
+ return handleDefaultLocaleRedirect(request, pathLocale, pathname, basePathTrailingSlash);
127
141
  };
128
- const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath2, basePathTrailingSlash) => {
129
- const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
130
- return constructPath(
131
- cookieLocale,
132
- newPath,
133
- basePath2,
134
- basePathTrailingSlash,
135
- request.nextUrl.search
136
- );
142
+ /**
143
+ * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.
144
+ *
145
+ * @param request - The incoming Next.js request object.
146
+ * @param pathname - The pathname from the request URL.
147
+ * @param pathLocale - The locale extracted from the pathname.
148
+ * @param cookieLocale - The locale from the cookie.
149
+ * @param basePath - The base path of the application.
150
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
151
+ * @returns - The new URL path with the correct locale.
152
+ */
153
+ const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath$1, basePathTrailingSlash) => {
154
+ return constructPath(cookieLocale, pathname.replace(`/${pathLocale}`, `/${cookieLocale}`), basePath$1, basePathTrailingSlash, appendLocaleSearchIfNeeded(request.nextUrl.search, cookieLocale));
137
155
  };
156
+ /**
157
+ * Handles redirection when the default locale is used and prefixing is not required.
158
+ *
159
+ * @param request - The incoming Next.js request object.
160
+ * @param pathLocale - The locale extracted from the pathname.
161
+ * @param pathname - The pathname from the request URL.
162
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
163
+ * @returns - The rewritten response without the locale prefix.
164
+ */
138
165
  const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrailingSlash) => {
139
- if (
140
- // If default locale should not be prefixed and the pathLocale is the defaultLocale
141
- !prefixDefault && pathLocale === defaultLocale
142
- ) {
143
- let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? "/";
144
- if (basePathTrailingSlash) {
145
- pathWithoutLocale = pathWithoutLocale.slice(1);
146
- }
147
- if (request.nextUrl.search) {
148
- pathWithoutLocale += request.nextUrl.search;
149
- }
150
- return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);
151
- }
152
- return rewriteUrl(request, pathname, pathLocale);
166
+ if (!prefixDefault && pathLocale === defaultLocale) {
167
+ let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? "/";
168
+ if (basePathTrailingSlash) pathWithoutLocale = pathWithoutLocale.slice(1);
169
+ const searchWithLocale$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
170
+ if (searchWithLocale$1) pathWithoutLocale += searchWithLocale$1;
171
+ else if (request.nextUrl.search) pathWithoutLocale += request.nextUrl.search;
172
+ return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);
173
+ }
174
+ const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
175
+ return rewriteUrl(request, searchWithLocale ? `${pathname}${searchWithLocale}` : pathname, pathLocale);
153
176
  };
154
- const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) => {
155
- let newPath = `${locale}${path}`;
156
- newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
157
- if (search) {
158
- newPath += search;
159
- }
160
- return newPath;
177
+ /**
178
+ * Constructs a new path by combining the locale, path, basePath, and search parameters.
179
+ *
180
+ * @param locale - The locale to include in the path.
181
+ * @param path - The original path from the request.
182
+ * @param basePath - The base path of the application.
183
+ * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
184
+ * @param [search] - The query string from the request URL (optional).
185
+ * @returns - The constructed new path.
186
+ */
187
+ const constructPath = (locale, path, basePath$1, basePathTrailingSlash, search) => {
188
+ const pathWithLocalePrefix = mode === "search-params" ? path : `${locale}${path}`;
189
+ let newPath = `${basePath$1}${basePathTrailingSlash ? "" : "/"}${pathWithLocalePrefix}`;
190
+ if (search) newPath += search;
191
+ return newPath;
161
192
  };
193
+ /**
194
+ * Rewrites the URL to the new path and sets the locale header.
195
+ *
196
+ * @param request - The incoming Next.js request object.
197
+ * @param newPath - The new path to rewrite to.
198
+ * @param locale - The locale to set in the response header.
199
+ * @returns - The rewritten response.
200
+ */
162
201
  const rewriteUrl = (request, newPath, locale) => {
163
- const search = request.nextUrl.search;
164
- const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
165
- const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));
166
- response.headers.set(headerName, locale);
167
- return response;
202
+ const search = request.nextUrl.search;
203
+ const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
204
+ const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));
205
+ response.headers.set(headerName, locale);
206
+ return response;
168
207
  };
208
+ /**
209
+ * Redirects the request to the new path.
210
+ *
211
+ * @param request - The incoming Next.js request object.
212
+ * @param newPath - The new path to redirect to.
213
+ * @returns - The redirect response.
214
+ */
169
215
  const redirectUrl = (request, newPath) => {
170
- const search = request.nextUrl.search;
171
- const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
172
- return NextResponse.redirect(new URL(pathWithSearch, request.url));
173
- };
174
- export {
175
- intlayerMiddleware
216
+ const search = request.nextUrl.search;
217
+ const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
218
+ return NextResponse.redirect(new URL(pathWithSearch, request.url));
176
219
  };
220
+
221
+ //#endregion
222
+ export { intlayerMiddleware };
177
223
  //# sourceMappingURL=intlayerMiddleware.mjs.map