next-intlayer 3.4.9 → 3.5.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 (79) hide show
  1. package/package.json +16 -16
  2. package/dist/cjs/client/IntlayerClientProvider.cjs +0 -36
  3. package/dist/cjs/client/IntlayerClientProvider.cjs.map +0 -1
  4. package/dist/cjs/client/index.cjs +0 -46
  5. package/dist/cjs/client/index.cjs.map +0 -1
  6. package/dist/cjs/client/useLocale.cjs +0 -101
  7. package/dist/cjs/client/useLocale.cjs.map +0 -1
  8. package/dist/cjs/client/useLocalePageRouter.cjs +0 -100
  9. package/dist/cjs/client/useLocalePageRouter.cjs.map +0 -1
  10. package/dist/cjs/generateStaticParams.cjs +0 -31
  11. package/dist/cjs/generateStaticParams.cjs.map +0 -1
  12. package/dist/cjs/index.cjs +0 -51
  13. package/dist/cjs/index.cjs.map +0 -1
  14. package/dist/cjs/middleware/index.cjs +0 -23
  15. package/dist/cjs/middleware/index.cjs.map +0 -1
  16. package/dist/cjs/middleware/intlayerMiddleware.cjs +0 -177
  17. package/dist/cjs/middleware/intlayerMiddleware.cjs.map +0 -1
  18. package/dist/cjs/middleware/localeDetector.cjs +0 -35
  19. package/dist/cjs/middleware/localeDetector.cjs.map +0 -1
  20. package/dist/cjs/server/index.cjs +0 -46
  21. package/dist/cjs/server/index.cjs.map +0 -1
  22. package/dist/cjs/server/withIntlayer.cjs +0 -84
  23. package/dist/cjs/server/withIntlayer.cjs.map +0 -1
  24. package/dist/cjs/types/NextPage.cjs +0 -17
  25. package/dist/cjs/types/NextPage.cjs.map +0 -1
  26. package/dist/cjs/types/index.cjs +0 -17
  27. package/dist/cjs/types/index.cjs.map +0 -1
  28. package/dist/esm/client/IntlayerClientProvider.mjs +0 -12
  29. package/dist/esm/client/IntlayerClientProvider.mjs.map +0 -1
  30. package/dist/esm/client/index.mjs +0 -23
  31. package/dist/esm/client/index.mjs.map +0 -1
  32. package/dist/esm/client/useLocale.mjs +0 -77
  33. package/dist/esm/client/useLocale.mjs.map +0 -1
  34. package/dist/esm/client/useLocalePageRouter.mjs +0 -76
  35. package/dist/esm/client/useLocalePageRouter.mjs.map +0 -1
  36. package/dist/esm/generateStaticParams.mjs +0 -7
  37. package/dist/esm/generateStaticParams.mjs.map +0 -1
  38. package/dist/esm/index.mjs +0 -29
  39. package/dist/esm/index.mjs.map +0 -1
  40. package/dist/esm/middleware/index.mjs +0 -2
  41. package/dist/esm/middleware/index.mjs.map +0 -1
  42. package/dist/esm/middleware/intlayerMiddleware.mjs +0 -155
  43. package/dist/esm/middleware/intlayerMiddleware.mjs.map +0 -1
  44. package/dist/esm/middleware/localeDetector.mjs +0 -11
  45. package/dist/esm/middleware/localeDetector.mjs.map +0 -1
  46. package/dist/esm/server/index.mjs +0 -23
  47. package/dist/esm/server/index.mjs.map +0 -1
  48. package/dist/esm/server/withIntlayer.mjs +0 -60
  49. package/dist/esm/server/withIntlayer.mjs.map +0 -1
  50. package/dist/esm/types/NextPage.mjs +0 -1
  51. package/dist/esm/types/NextPage.mjs.map +0 -1
  52. package/dist/esm/types/index.mjs +0 -1
  53. package/dist/esm/types/index.mjs.map +0 -1
  54. package/dist/types/client/IntlayerClientProvider.d.ts +0 -5
  55. package/dist/types/client/IntlayerClientProvider.d.ts.map +0 -1
  56. package/dist/types/client/index.d.ts +0 -5
  57. package/dist/types/client/index.d.ts.map +0 -1
  58. package/dist/types/client/useLocale.d.ts +0 -10
  59. package/dist/types/client/useLocale.d.ts.map +0 -1
  60. package/dist/types/client/useLocalePageRouter.d.ts +0 -10
  61. package/dist/types/client/useLocalePageRouter.d.ts.map +0 -1
  62. package/dist/types/generateStaticParams.d.ts +0 -4
  63. package/dist/types/generateStaticParams.d.ts.map +0 -1
  64. package/dist/types/index.d.ts +0 -5
  65. package/dist/types/index.d.ts.map +0 -1
  66. package/dist/types/middleware/index.d.ts +0 -2
  67. package/dist/types/middleware/index.d.ts.map +0 -1
  68. package/dist/types/middleware/intlayerMiddleware.d.ts +0 -26
  69. package/dist/types/middleware/intlayerMiddleware.d.ts.map +0 -1
  70. package/dist/types/middleware/localeDetector.d.ts +0 -9
  71. package/dist/types/middleware/localeDetector.d.ts.map +0 -1
  72. package/dist/types/server/index.d.ts +0 -3
  73. package/dist/types/server/index.d.ts.map +0 -1
  74. package/dist/types/server/withIntlayer.d.ts +0 -15
  75. package/dist/types/server/withIntlayer.d.ts.map +0 -1
  76. package/dist/types/types/NextPage.d.ts +0 -18
  77. package/dist/types/types/NextPage.d.ts.map +0 -1
  78. package/dist/types/types/index.d.ts +0 -2
  79. package/dist/types/types/index.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intlayer",
3
- "version": "3.4.9",
3
+ "version": "3.5.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": [
@@ -72,12 +72,12 @@
72
72
  ],
73
73
  "dependencies": {
74
74
  "webpack": "^5.96.1",
75
- "@intlayer/config": "^3.4.9",
76
- "@intlayer/dictionaries-entry": "^3.4.9",
77
- "@intlayer/core": "^3.4.9",
78
- "react-intlayer": "^3.4.9",
79
- "@intlayer/chokidar": "^3.4.9",
80
- "@intlayer/webpack": "^3.4.9"
75
+ "@intlayer/config": "^3.5.0",
76
+ "@intlayer/core": "^3.5.0",
77
+ "@intlayer/webpack": "^3.5.0",
78
+ "@intlayer/dictionaries-entry": "^3.5.0",
79
+ "react-intlayer": "^3.5.0",
80
+ "@intlayer/chokidar": "^3.5.0"
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/ts-config": "^1.0.4",
92
+ "@utils/eslint-config": "^1.0.4",
93
93
  "@utils/ts-config-types": "^1.0.4",
94
+ "@utils/ts-config": "^1.0.4",
94
95
  "@utils/tsup-config": "^1.0.4",
95
- "@utils/eslint-config": "^1.0.4",
96
- "intlayer": "^3.4.9"
96
+ "intlayer": "^3.5.0"
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/config": "^3.4.9",
102
- "@intlayer/core": "^3.4.9",
103
- "@intlayer/webpack": "^3.4.9",
104
- "intlayer": "^3.4.9",
105
- "@intlayer/dictionaries-entry": "^3.4.9",
106
- "react-intlayer": "^3.4.9"
101
+ "@intlayer/config": "^3.5.0",
102
+ "@intlayer/dictionaries-entry": "^3.5.0",
103
+ "@intlayer/core": "^3.5.0",
104
+ "@intlayer/webpack": "^3.5.0",
105
+ "intlayer": "^3.5.0",
106
+ "react-intlayer": "^3.5.0"
107
107
  },
108
108
  "engines": {
109
109
  "node": ">=14.18"
@@ -1,36 +0,0 @@
1
- "use strict";
2
- "use client";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var IntlayerClientProvider_exports = {};
21
- __export(IntlayerClientProvider_exports, {
22
- IntlayerClientProvider: () => IntlayerClientProvider
23
- });
24
- module.exports = __toCommonJS(IntlayerClientProvider_exports);
25
- var import_jsx_runtime = require("react/jsx-runtime");
26
- var import_react_intlayer = require("react-intlayer");
27
- var import_useLocale = require('./useLocale.cjs');
28
- const IntlayerClientProvider = (props) => {
29
- const { setLocale } = (0, import_useLocale.useLocale)();
30
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_intlayer.IntlayerProvider, { setLocale, ...props });
31
- };
32
- // Annotate the CommonJS export names for ESM import in node:
33
- 0 && (module.exports = {
34
- IntlayerClientProvider
35
- });
36
- //# sourceMappingURL=IntlayerClientProvider.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUS;AAPT,4BAA6D;AAC7D,uBAA0B;AAInB,MAAM,yBAAoD,CAAC,UAAU;AAC1E,QAAM,EAAE,UAAU,QAAI,4BAAU;AAChC,SAAO,4CAAC,0CAAiB,WAAuB,GAAG,OAAO;AAC5D;","names":[]}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var client_exports = {};
20
- __export(client_exports, {
21
- IntlayerClientContext: () => import_react_intlayer.IntlayerClientContext,
22
- IntlayerClientProvider: () => import_IntlayerClientProvider.IntlayerClientProvider,
23
- getTranslation: () => import_react_intlayer.getTranslation,
24
- useIntlayer: () => import_react_intlayer.useIntlayer,
25
- useLocale: () => import_useLocale.useLocale,
26
- useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
27
- useLocalePageRouter: () => import_useLocalePageRouter.useLocalePageRouter,
28
- useTraduction: () => import_react_intlayer.useTraduction
29
- });
30
- module.exports = __toCommonJS(client_exports);
31
- var import_react_intlayer = require("react-intlayer");
32
- var import_useLocale = require('./useLocale.cjs');
33
- var import_useLocalePageRouter = require('./useLocalePageRouter.cjs');
34
- var import_IntlayerClientProvider = require('./IntlayerClientProvider.cjs');
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- IntlayerClientContext,
38
- IntlayerClientProvider,
39
- getTranslation,
40
- useIntlayer,
41
- useLocale,
42
- useLocaleCookie,
43
- useLocalePageRouter,
44
- useTraduction
45
- });
46
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n getTranslation,\n IntlayerClientContext,\n useIntlayer,\n useTraduction,\n useLocaleCookie,\n} from 'react-intlayer';\nexport { useLocale } from './useLocale';\nexport { useLocalePageRouter } from './useLocalePageRouter';\nexport {\n IntlayerClientProvider,\n type IntlayerClientProviderProps,\n} from './IntlayerClientProvider';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAMO;AACP,uBAA0B;AAC1B,iCAAoC;AACpC,oCAGO;","names":[]}
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var useLocale_exports = {};
20
- __export(useLocale_exports, {
21
- useLocale: () => useLocale
22
- });
23
- module.exports = __toCommonJS(useLocale_exports);
24
- var import_client = require("@intlayer/config/client");
25
- var import_navigation = require("next/navigation.js");
26
- var import_react = require("react");
27
- var import_react_intlayer = require("react-intlayer");
28
- const useLocale = () => {
29
- const {
30
- /**
31
- * Prefix default prefix the default locale to the path as other locales.
32
- *
33
- * Example with prefixDefault = true and defaultLocale = 'en':
34
- * path = /en/dashboard or /fr/dashboard
35
- *
36
- * Example with prefixDefault = false and defaultLocale = 'en':
37
- * path = /dashboard or /fr/dashboard
38
- *
39
- */
40
- prefixDefault
41
- } = (0, import_client.getConfiguration)().middleware;
42
- const { setLocaleCookie } = (0, import_react_intlayer.useLocaleCookie)();
43
- const reactLocaleHook = (0, import_react_intlayer.useLocaleBase)();
44
- const { push, refresh } = (0, import_navigation.useRouter)();
45
- const pathname = (0, import_navigation.usePathname)();
46
- const {
47
- defaultLocale,
48
- availableLocales,
49
- locale: currentLocale,
50
- setLocale: setLocaleState
51
- } = reactLocaleHook;
52
- const getPathWithoutLocale = () => {
53
- if (
54
- // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path
55
- !prefixDefault && currentLocale.toString() === defaultLocale.toString()
56
- ) {
57
- return pathname;
58
- }
59
- const slicedPath = pathname.slice(`/${currentLocale}`.length);
60
- if (slicedPath) {
61
- return slicedPath;
62
- }
63
- return "/";
64
- };
65
- const pathWithoutLocale = getPathWithoutLocale();
66
- const setLocale = (0, import_react.useCallback)(
67
- (locale) => {
68
- if (!availableLocales.includes(locale)) {
69
- console.error(`Locale ${locale} is not available`);
70
- return;
71
- }
72
- setLocaleCookie(locale);
73
- setLocaleState(locale);
74
- if (!prefixDefault && locale.toString() === defaultLocale.toString()) {
75
- push(pathWithoutLocale);
76
- } else {
77
- push(`/${locale}${pathWithoutLocale}`);
78
- }
79
- return refresh();
80
- },
81
- [
82
- currentLocale,
83
- availableLocales,
84
- setLocaleCookie,
85
- setLocaleState,
86
- prefixDefault,
87
- defaultLocale,
88
- pathWithoutLocale
89
- ]
90
- );
91
- return {
92
- ...reactLocaleHook,
93
- setLocale,
94
- pathWithoutLocale
95
- };
96
- };
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- useLocale
100
- });
101
- //# sourceMappingURL=useLocale.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport { useLocaleCookie, useLocaleBase } from 'react-intlayer';\n\nexport const useLocale = () => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { setLocaleCookie } = useLocaleCookie();\n const reactLocaleHook = useLocaleBase();\n const { push, refresh } = useRouter();\n const pathname = usePathname();\n\n const {\n defaultLocale,\n availableLocales,\n locale: currentLocale,\n setLocale: setLocaleState,\n } = reactLocaleHook;\n\n const getPathWithoutLocale = () => {\n if (\n // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path\n !prefixDefault &&\n currentLocale.toString() === defaultLocale.toString()\n ) {\n return pathname;\n }\n\n const slicedPath = pathname.slice(`/${currentLocale}`.length);\n\n // If the path without locale is not empty, we return it\n if (slicedPath) {\n return slicedPath;\n }\n\n // If the path without locale is empty, we return the root path\n return '/';\n };\n\n const pathWithoutLocale = getPathWithoutLocale();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleCookie(locale);\n setLocaleState(locale);\n\n if (!prefixDefault && locale.toString() === defaultLocale.toString()) {\n push(pathWithoutLocale);\n } else {\n push(`/${locale}${pathWithoutLocale}`);\n }\n\n return refresh();\n },\n [\n currentLocale,\n availableLocales,\n setLocaleCookie,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n pathWithoutLocale,\n ]\n );\n\n return {\n ...reactLocaleHook,\n setLocale,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,wBAAuC;AACvC,mBAA4B;AAC5B,4BAA+C;AAExC,MAAM,YAAY,MAAM;AAC7B,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,QAAI,gCAAiB,EAAE;AACvB,QAAM,EAAE,gBAAgB,QAAI,uCAAgB;AAC5C,QAAM,sBAAkB,qCAAc;AACtC,QAAM,EAAE,MAAM,QAAQ,QAAI,6BAAU;AACpC,QAAM,eAAW,+BAAY;AAE7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,WAAW;AAAA,EACb,IAAI;AAEJ,QAAM,uBAAuB,MAAM;AACjC;AAAA;AAAA,MAEE,CAAC,iBACD,cAAc,SAAS,MAAM,cAAc,SAAS;AAAA,MACpD;AACA,aAAO;AAAA,IACT;AAEA,UAAM,aAAa,SAAS,MAAM,IAAI,aAAa,GAAG,MAAM;AAG5D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAGA,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB,qBAAqB;AAE/C,QAAM,gBAAY;AAAA,IAChB,CAAC,WAAoB;AACnB,UAAI,CAAC,iBAAiB,SAAS,MAAM,GAAG;AACtC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,sBAAgB,MAAM;AACtB,qBAAe,MAAM;AAErB,UAAI,CAAC,iBAAiB,OAAO,SAAS,MAAM,cAAc,SAAS,GAAG;AACpE,aAAK,iBAAiB;AAAA,MACxB,OAAO;AACL,aAAK,IAAI,MAAM,GAAG,iBAAiB,EAAE;AAAA,MACvC;AAEA,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var useLocalePageRouter_exports = {};
20
- __export(useLocalePageRouter_exports, {
21
- useLocalePageRouter: () => useLocalePageRouter
22
- });
23
- module.exports = __toCommonJS(useLocalePageRouter_exports);
24
- var import_client = require("@intlayer/config/client");
25
- var import_router = require("next/router.js");
26
- var import_react = require("react");
27
- var import_react_intlayer = require("react-intlayer");
28
- const useLocalePageRouter = () => {
29
- const {
30
- /**
31
- * Prefix default prefix the default locale to the path as other locales.
32
- *
33
- * Example with prefixDefault = true and defaultLocale = 'en':
34
- * path = /en/dashboard or /fr/dashboard
35
- *
36
- * Example with prefixDefault = false and defaultLocale = 'en':
37
- * path = /dashboard or /fr/dashboard
38
- *
39
- */
40
- prefixDefault
41
- } = (0, import_client.getConfiguration)().middleware;
42
- const { setLocaleCookie } = (0, import_react_intlayer.useLocaleCookie)();
43
- const reactLocaleHook = (0, import_react_intlayer.useLocaleBase)();
44
- const { push, pathname, reload } = (0, import_router.useRouter)();
45
- const {
46
- defaultLocale,
47
- availableLocales,
48
- locale: currentLocale,
49
- setLocale: setLocaleState
50
- } = reactLocaleHook;
51
- const getPathWithoutLocale = () => {
52
- if (
53
- // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path
54
- !prefixDefault && currentLocale.toString() === defaultLocale.toString()
55
- ) {
56
- return pathname;
57
- }
58
- const slicedPath = pathname.slice(`/${currentLocale}`.length);
59
- if (slicedPath) {
60
- return slicedPath;
61
- }
62
- return "/";
63
- };
64
- const pathWithoutLocale = getPathWithoutLocale();
65
- const setLocale = (0, import_react.useCallback)(
66
- (locale) => {
67
- if (!availableLocales.includes(locale)) {
68
- console.error(`Locale ${locale} is not available`);
69
- return;
70
- }
71
- setLocaleCookie(locale);
72
- setLocaleState(locale);
73
- if (!prefixDefault && locale.toString() === defaultLocale.toString()) {
74
- push(pathWithoutLocale);
75
- } else {
76
- push(`/${locale}${pathWithoutLocale}`);
77
- }
78
- return reload();
79
- },
80
- [
81
- currentLocale,
82
- availableLocales,
83
- setLocaleCookie,
84
- setLocaleState,
85
- prefixDefault,
86
- defaultLocale,
87
- pathWithoutLocale
88
- ]
89
- );
90
- return {
91
- ...reactLocaleHook,
92
- setLocale,
93
- pathWithoutLocale
94
- };
95
- };
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {
98
- useLocalePageRouter
99
- });
100
- //# sourceMappingURL=useLocalePageRouter.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["import { type Locales, getConfiguration } from '@intlayer/config/client';\nimport { useRouter } from 'next/router.js';\nimport { useCallback } from 'react';\nimport { useLocaleCookie, useLocaleBase } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const {\n /**\n * Prefix default prefix the default locale to the path as other locales.\n *\n * Example with prefixDefault = true and defaultLocale = 'en':\n * path = /en/dashboard or /fr/dashboard\n *\n * Example with prefixDefault = false and defaultLocale = 'en':\n * path = /dashboard or /fr/dashboard\n *\n */\n prefixDefault,\n } = getConfiguration().middleware;\n const { setLocaleCookie } = useLocaleCookie();\n const reactLocaleHook = useLocaleBase();\n const { push, pathname, reload } = useRouter();\n\n const {\n defaultLocale,\n availableLocales,\n locale: currentLocale,\n setLocale: setLocaleState,\n } = reactLocaleHook;\n\n const getPathWithoutLocale = () => {\n if (\n // If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path\n !prefixDefault &&\n currentLocale.toString() === defaultLocale.toString()\n ) {\n return pathname;\n }\n\n const slicedPath = pathname.slice(`/${currentLocale}`.length);\n\n // If the path without locale is not empty, we return it\n if (slicedPath) {\n return slicedPath;\n }\n\n // If the path without locale is empty, we return the root path\n return '/';\n };\n\n const pathWithoutLocale = getPathWithoutLocale();\n\n const setLocale = useCallback(\n (locale: Locales) => {\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleCookie(locale);\n setLocaleState(locale);\n\n if (!prefixDefault && locale.toString() === defaultLocale.toString()) {\n push(pathWithoutLocale);\n } else {\n push(`/${locale}${pathWithoutLocale}`);\n }\n\n return reload();\n },\n [\n currentLocale,\n availableLocales,\n setLocaleCookie,\n setLocaleState,\n prefixDefault,\n defaultLocale,\n pathWithoutLocale,\n ]\n );\n\n return {\n ...reactLocaleHook,\n setLocale,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,oBAA0B;AAC1B,mBAA4B;AAC5B,4BAA+C;AAExC,MAAM,sBAAsB,MAAM;AACvC,QAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWJ;AAAA,EACF,QAAI,gCAAiB,EAAE;AACvB,QAAM,EAAE,gBAAgB,QAAI,uCAAgB;AAC5C,QAAM,sBAAkB,qCAAc;AACtC,QAAM,EAAE,MAAM,UAAU,OAAO,QAAI,yBAAU;AAE7C,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR,WAAW;AAAA,EACb,IAAI;AAEJ,QAAM,uBAAuB,MAAM;AACjC;AAAA;AAAA,MAEE,CAAC,iBACD,cAAc,SAAS,MAAM,cAAc,SAAS;AAAA,MACpD;AACA,aAAO;AAAA,IACT;AAEA,UAAM,aAAa,SAAS,MAAM,IAAI,aAAa,GAAG,MAAM;AAG5D,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAGA,WAAO;AAAA,EACT;AAEA,QAAM,oBAAoB,qBAAqB;AAE/C,QAAM,gBAAY;AAAA,IAChB,CAAC,WAAoB;AACnB,UAAI,CAAC,iBAAiB,SAAS,MAAM,GAAG;AACtC,gBAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,MACF;AAEA,sBAAgB,MAAM;AACtB,qBAAe,MAAM;AAErB,UAAI,CAAC,iBAAiB,OAAO,SAAS,MAAM,cAAc,SAAS,GAAG;AACpE,aAAK,iBAAiB;AAAA,MACxB,OAAO;AACL,aAAK,IAAI,MAAM,GAAG,iBAAiB,EAAE;AAAA,MACvC;AAEA,aAAO,OAAO;AAAA,IAChB;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var generateStaticParams_exports = {};
20
- __export(generateStaticParams_exports, {
21
- generateStaticParams: () => generateStaticParams
22
- });
23
- module.exports = __toCommonJS(generateStaticParams_exports);
24
- var import_client = require("@intlayer/config/client");
25
- const { locales } = (0, import_client.getConfiguration)().internationalization;
26
- const generateStaticParams = () => locales.map((locale) => ({ locale }));
27
- // Annotate the CommonJS export names for ESM import in node:
28
- 0 && (module.exports = {
29
- generateStaticParams
30
- });
31
- //# sourceMappingURL=generateStaticParams.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import { getConfiguration } from '@intlayer/config/client';\n\nconst { locales } = getConfiguration().internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAiC;AAEjC,MAAM,EAAE,QAAQ,QAAI,gCAAiB,EAAE;AAEhC,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var src_exports = {};
20
- __export(src_exports, {
21
- IntlayerClientContext: () => import_react_intlayer.IntlayerClientContext,
22
- IntlayerClientProvider: () => import_client.IntlayerClientProvider,
23
- generateStaticParams: () => import_generateStaticParams.generateStaticParams,
24
- getTranslation: () => import_react_intlayer.getTranslation,
25
- t: () => import_react_intlayer.t,
26
- useDictionary: () => import_react_intlayer.useDictionary,
27
- useIntlayer: () => import_react_intlayer.useIntlayer,
28
- useLocale: () => import_client.useLocale,
29
- useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
30
- useLocalePageRouter: () => import_client.useLocalePageRouter,
31
- useTraduction: () => import_react_intlayer.useTraduction
32
- });
33
- module.exports = __toCommonJS(src_exports);
34
- var import_react_intlayer = require("react-intlayer");
35
- var import_generateStaticParams = require('./generateStaticParams.cjs');
36
- var import_client = require('./client/index.cjs');
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- IntlayerClientContext,
40
- IntlayerClientProvider,
41
- generateStaticParams,
42
- getTranslation,
43
- t,
44
- useDictionary,
45
- useIntlayer,
46
- useLocale,
47
- useLocaleCookie,
48
- useLocalePageRouter,
49
- useTraduction
50
- });
51
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
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 NextLayoutIntlayer,\n LocalPromiseParams,\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;AASrC,oBAKO;","names":[]}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var middleware_exports = {};
17
- module.exports = __toCommonJS(middleware_exports);
18
- __reExport(middleware_exports, require('./intlayerMiddleware.cjs'), module.exports);
19
- // Annotate the CommonJS export names for ESM import in node:
20
- 0 && (module.exports = {
21
- ...require('./intlayerMiddleware.cjs')
22
- });
23
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/middleware/index.ts"],"sourcesContent":["export * from './intlayerMiddleware';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,iCAAd;","names":[]}
@@ -1,177 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var intlayerMiddleware_exports = {};
20
- __export(intlayerMiddleware_exports, {
21
- intlayerMiddleware: () => intlayerMiddleware
22
- });
23
- module.exports = __toCommonJS(intlayerMiddleware_exports);
24
- var import_client = require("@intlayer/config/client");
25
- var import_server = require("next/server");
26
- var import_localeDetector = require('./localeDetector.cjs');
27
- const { internationalization, middleware } = (0, import_client.getConfiguration)();
28
- const { locales, defaultLocale } = internationalization;
29
- const {
30
- headerName,
31
- cookieName,
32
- prefixDefault,
33
- basePath,
34
- serverSetCookie,
35
- noPrefix
36
- } = middleware;
37
- const intlayerMiddleware = (request, _event, _response) => {
38
- const pathname = request.nextUrl.pathname;
39
- const cookieLocale = getCookieLocale(request);
40
- const basePathTrailingSlash = basePath.endsWith("/");
41
- if (noPrefix) {
42
- return handleNoPrefix(
43
- request,
44
- cookieLocale,
45
- pathname,
46
- basePathTrailingSlash
47
- );
48
- }
49
- const pathLocale = getPathLocale(pathname);
50
- return handlePrefix(
51
- request,
52
- cookieLocale,
53
- pathLocale,
54
- pathname,
55
- basePathTrailingSlash
56
- );
57
- };
58
- const getCookieLocale = (request) => {
59
- if (!cookieName) return void 0;
60
- const cookieValue = request.cookies.get(cookieName)?.value;
61
- if (cookieValue && locales.includes(cookieValue)) {
62
- return cookieValue;
63
- }
64
- };
65
- const handleNoPrefix = (request, cookieLocale, pathname, basePathTrailingSlash) => {
66
- const locale = cookieLocale ?? defaultLocale;
67
- const newPath = constructPath(
68
- locale,
69
- pathname,
70
- basePath,
71
- basePathTrailingSlash
72
- );
73
- return rewriteUrl(request, newPath, locale);
74
- };
75
- const getPathLocale = (pathname) => locales.find(
76
- (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
77
- );
78
- const handlePrefix = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
79
- if (!pathLocale) {
80
- return handleMissingPathLocale(
81
- request,
82
- cookieLocale,
83
- pathname,
84
- basePathTrailingSlash
85
- );
86
- }
87
- return handleExistingPathLocale(
88
- request,
89
- cookieLocale,
90
- pathLocale,
91
- pathname,
92
- basePathTrailingSlash
93
- );
94
- };
95
- const handleMissingPathLocale = (request, cookieLocale, pathname, basePathTrailingSlash) => {
96
- let locale = cookieLocale ?? (0, import_localeDetector.localeDetector)?.(request) ?? defaultLocale;
97
- if (!locales.includes(locale)) {
98
- console.warn(
99
- "The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale."
100
- );
101
- locale = defaultLocale;
102
- }
103
- const newPath = constructPath(
104
- locale,
105
- pathname,
106
- basePath,
107
- basePathTrailingSlash
108
- );
109
- return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
110
- };
111
- const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
112
- if (
113
- // If the cookie locale is set and differs from the locale in the URL, and server should not always set cookie
114
- cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always"
115
- ) {
116
- const newPath = handleCookieLocaleMismatch(
117
- request,
118
- pathname,
119
- pathLocale,
120
- cookieLocale,
121
- basePath,
122
- basePathTrailingSlash
123
- );
124
- return redirectUrl(request, newPath);
125
- }
126
- return handleDefaultLocaleRedirect(
127
- request,
128
- pathLocale,
129
- pathname,
130
- basePathTrailingSlash
131
- );
132
- };
133
- const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath2, basePathTrailingSlash) => {
134
- const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
135
- return constructPath(
136
- cookieLocale,
137
- newPath,
138
- basePath2,
139
- basePathTrailingSlash,
140
- request.nextUrl.search
141
- );
142
- };
143
- const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrailingSlash) => {
144
- if (
145
- // If default locale should not be prefixed and the pathLocale is the defaultLocale
146
- !prefixDefault && pathLocale === defaultLocale
147
- ) {
148
- let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
149
- if (basePathTrailingSlash) {
150
- pathWithoutLocale = pathWithoutLocale.slice(1);
151
- }
152
- if (request.nextUrl.search) {
153
- pathWithoutLocale += request.nextUrl.search;
154
- }
155
- return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);
156
- }
157
- return rewriteUrl(request, pathname, pathLocale);
158
- };
159
- const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) => {
160
- let newPath = `${locale}${path}`;
161
- newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
162
- if (search) {
163
- newPath += search;
164
- }
165
- return newPath;
166
- };
167
- const rewriteUrl = (request, newPath, locale) => {
168
- const response = import_server.NextResponse.rewrite(new URL(newPath, request.url));
169
- response.headers.set(headerName, locale);
170
- return response;
171
- };
172
- const redirectUrl = (request, newPath) => import_server.NextResponse.redirect(new URL(newPath, request.url));
173
- // Annotate the CommonJS export names for ESM import in node:
174
- 0 && (module.exports = {
175
- intlayerMiddleware
176
- });
177
- //# sourceMappingURL=intlayerMiddleware.cjs.map