next-intlayer 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/cjs/client/index.cjs +16 -22
  2. package/dist/cjs/client/index.d.ts +3 -10
  3. package/dist/cjs/client/useLocale.cjs +13 -20
  4. package/dist/cjs/client/useLocale.cjs.map +1 -1
  5. package/dist/cjs/client/useLocale.d.ts +7 -7
  6. package/dist/cjs/generateStaticParams.cjs +8 -13
  7. package/dist/cjs/generateStaticParams.d.ts +2 -2
  8. package/dist/cjs/index.cjs +18 -24
  9. package/dist/cjs/index.d.ts +8 -15
  10. package/dist/cjs/middleware/index.cjs +9 -21
  11. package/dist/cjs/middleware/index.d.ts +2 -2
  12. package/dist/cjs/middleware/intlayerMiddleware.cjs +28 -86
  13. package/dist/cjs/middleware/intlayerMiddleware.d.ts +1 -1
  14. package/dist/cjs/middleware/localeDetector.cjs +20 -37
  15. package/dist/cjs/middleware/localeDetector.d.ts +2 -2
  16. package/dist/cjs/server/index.cjs +15 -20
  17. package/dist/cjs/server/index.d.ts +3 -10
  18. package/dist/cjs/server/withIntlayer.cjs +36 -48
  19. package/dist/cjs/server/withIntlayer.d.ts +3 -5
  20. package/dist/cjs/types/NextPage.cjs +4 -8
  21. package/dist/cjs/types/NextPage.d.ts +6 -6
  22. package/dist/cjs/types/index.cjs +4 -8
  23. package/dist/cjs/types/index.d.ts +4 -4
  24. package/dist/esm/client/index.d.mts +3 -10
  25. package/dist/esm/client/index.mjs +4 -4
  26. package/dist/esm/client/useLocale.d.mts +7 -7
  27. package/dist/esm/client/useLocale.mjs +12 -10
  28. package/dist/esm/client/useLocale.mjs.map +1 -1
  29. package/dist/esm/generateStaticParams.d.mts +2 -2
  30. package/dist/esm/generateStaticParams.mjs +4 -2
  31. package/dist/esm/index.d.mts +8 -15
  32. package/dist/esm/index.mjs +5 -5
  33. package/dist/esm/middleware/index.d.mts +2 -2
  34. package/dist/esm/middleware/index.mjs +2 -2
  35. package/dist/esm/middleware/intlayerMiddleware.d.mts +1 -1
  36. package/dist/esm/middleware/intlayerMiddleware.mjs +21 -66
  37. package/dist/esm/middleware/localeDetector.d.mts +2 -2
  38. package/dist/esm/middleware/localeDetector.mjs +5 -3
  39. package/dist/esm/server/index.d.mts +3 -10
  40. package/dist/esm/server/index.mjs +4 -4
  41. package/dist/esm/server/withIntlayer.d.mts +3 -5
  42. package/dist/esm/server/withIntlayer.mjs +32 -32
  43. package/dist/esm/types/NextPage.d.mts +6 -6
  44. package/dist/esm/types/NextPage.mjs +1 -1
  45. package/dist/esm/types/index.d.mts +4 -4
  46. package/dist/esm/types/index.mjs +1 -1
  47. package/package.json +9 -9
  48. package/src/client/useLocale.ts +6 -4
@@ -8,41 +8,35 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var client_exports = {};
24
20
  __export(client_exports, {
25
21
  LocaleClientContext: () => import_react_intlayer.LocaleClientContext,
26
- LocaleClientContextProvider: () =>
27
- import_react_intlayer.LocaleClientContextProvider,
22
+ LocaleClientContextProvider: () => import_react_intlayer.LocaleClientContextProvider,
28
23
  getTranslation: () => import_react_intlayer.getTranslation,
29
24
  useIntlayer: () => import_react_intlayer.useIntlayer,
30
25
  useLocale: () => import_useLocale.useLocale,
31
26
  useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
32
- useTraduction: () => import_react_intlayer.useTraduction,
27
+ useTraduction: () => import_react_intlayer.useTraduction
33
28
  });
34
29
  module.exports = __toCommonJS(client_exports);
35
30
  var import_react_intlayer = require("react-intlayer");
36
- var import_useLocale = require("./useLocale.cjs");
31
+ var import_useLocale = require('./useLocale.cjs');
37
32
  // Annotate the CommonJS export names for ESM import in node:
38
- 0 &&
39
- (module.exports = {
40
- LocaleClientContext,
41
- LocaleClientContextProvider,
42
- getTranslation,
43
- useIntlayer,
44
- useLocale,
45
- useLocaleCookie,
46
- useTraduction,
47
- });
48
- //# sourceMappingURL=index.cjs.map
33
+ 0 && (module.exports = {
34
+ LocaleClientContext,
35
+ LocaleClientContextProvider,
36
+ getTranslation,
37
+ useIntlayer,
38
+ useLocale,
39
+ useLocaleCookie,
40
+ useTraduction
41
+ });
42
+ //# sourceMappingURL=index.cjs.map
@@ -1,10 +1,3 @@
1
- export {
2
- LocaleClientContext,
3
- LocaleClientContextProvider,
4
- getTranslation,
5
- useIntlayer,
6
- useLocaleCookie,
7
- useTraduction,
8
- } from "react-intlayer";
9
- export { useLocale } from "./useLocale.js";
10
- import "intlayer";
1
+ export { LocaleClientContext, LocaleClientContextProvider, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
+ export { useLocale } from './useLocale.js';
3
+ import '@intlayer/config/client';
@@ -8,21 +8,17 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var useLocale_exports = {};
24
20
  __export(useLocale_exports, {
25
- useLocale: () => useLocale,
21
+ useLocale: () => useLocale
26
22
  });
27
23
  module.exports = __toCommonJS(useLocale_exports);
28
24
  var import_client = require("@intlayer/config/client");
@@ -37,19 +33,17 @@ const useLocale = () => {
37
33
  const {
38
34
  defaultLocale,
39
35
  availableLocales,
40
- locale: currentLocale,
36
+ locale: currentLocale
41
37
  } = reactLocaleHook;
42
38
  const setLocale = (locale) => {
43
- if (currentLocale === locale) return;
39
+ if (currentLocale.toString() === locale.toString())
40
+ return;
44
41
  if (!availableLocales.includes(locale)) {
45
42
  console.error(`Locale ${locale} is not available`);
46
43
  return;
47
44
  }
48
45
  setLocaleCookie(locale);
49
- const pathWithoutLocale =
50
- !prefixDefault && currentLocale === defaultLocale
51
- ? pathname
52
- : pathname.slice(`/${currentLocale}`.length) || "/";
46
+ const pathWithoutLocale = !prefixDefault && currentLocale.toString() === defaultLocale.toString() ? pathname : pathname.slice(`/${currentLocale}`.length) || "/";
53
47
  if (!prefixDefault && locale === defaultLocale) {
54
48
  return router.push(pathWithoutLocale);
55
49
  }
@@ -57,12 +51,11 @@ const useLocale = () => {
57
51
  };
58
52
  return {
59
53
  ...reactLocaleHook,
60
- setLocale,
54
+ setLocale
61
55
  };
62
56
  };
63
57
  // Annotate the CommonJS export names for ESM import in node:
64
- 0 &&
65
- (module.exports = {
66
- useLocale,
67
- });
68
- //# sourceMappingURL=useLocale.cjs.map
58
+ 0 && (module.exports = {
59
+ useLocale
60
+ });
61
+ //# sourceMappingURL=useLocale.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { intlayerMiddlewareConfiguration } from '@intlayer/config/client';\nimport type { Locales } from 'intlayer';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useLocale as useReactLocale, useLocaleCookie } from 'react-intlayer';\n\nconst { prefixDefault } = intlayerMiddlewareConfiguration;\n\nexport const useLocale = () => {\n const { setLocaleCookie } = useLocaleCookie();\n const reactLocaleHook = useReactLocale();\n const router = useRouter();\n const pathname = usePathname();\n\n const {\n defaultLocale,\n availableLocales,\n locale: currentLocale,\n } = reactLocaleHook;\n\n const setLocale = (locale: Locales) => {\n if (currentLocale === locale) return;\n\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleCookie(locale);\n\n const pathWithoutLocale =\n !prefixDefault && currentLocale === defaultLocale\n ? pathname\n : pathname.slice(`/${currentLocale}`.length) || '/';\n\n if (!prefixDefault && locale === defaultLocale) {\n return router.push(pathWithoutLocale);\n }\n\n return router.push(`/${locale}${pathWithoutLocale}`);\n };\n\n return {\n ...reactLocaleHook,\n setLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAgD;AAEhD,wBAAuC;AACvC,4BAA6D;AAE7D,MAAM,EAAE,cAAc,IAAI;AAEnB,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,gBAAgB,QAAI,uCAAgB;AAC5C,QAAM,sBAAkB,sBAAAA,WAAe;AACvC,QAAM,aAAS,6BAAU;AACzB,QAAM,eAAW,+BAAY;AAE7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,EACV,IAAI;AAEJ,QAAM,YAAY,CAAC,WAAoB;AACrC,QAAI,kBAAkB;AAAQ;AAE9B,QAAI,CAAC,iBAAiB,SAAS,MAAM,GAAG;AACtC,cAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,IACF;AAEA,oBAAgB,MAAM;AAEtB,UAAM,oBACJ,CAAC,iBAAiB,kBAAkB,gBAChC,WACA,SAAS,MAAM,IAAI,aAAa,GAAG,MAAM,KAAK;AAEpD,QAAI,CAAC,iBAAiB,WAAW,eAAe;AAC9C,aAAO,OAAO,KAAK,iBAAiB;AAAA,IACtC;AAEA,WAAO,OAAO,KAAK,IAAI,MAAM,GAAG,iBAAiB,EAAE;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":["useReactLocale"]}
1
+ {"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import {\n type Locales,\n intlayerMiddlewareConfiguration,\n} from '@intlayer/config/client';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useLocale as useReactLocale, useLocaleCookie } from 'react-intlayer';\n\nconst { prefixDefault } = intlayerMiddlewareConfiguration;\n\nexport const useLocale = () => {\n const { setLocaleCookie } = useLocaleCookie();\n const reactLocaleHook = useReactLocale();\n const router = useRouter();\n const pathname = usePathname();\n\n const {\n defaultLocale,\n availableLocales,\n locale: currentLocale,\n } = reactLocaleHook;\n\n const setLocale = (locale: Locales) => {\n if (currentLocale.toString() === locale.toString()) return;\n\n if (!availableLocales.includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleCookie(locale);\n\n const pathWithoutLocale =\n !prefixDefault && currentLocale.toString() === defaultLocale.toString()\n ? pathname\n : pathname.slice(`/${currentLocale}`.length) || '/';\n\n if (!prefixDefault && locale === defaultLocale) {\n return router.push(pathWithoutLocale);\n }\n\n return router.push(`/${locale}${pathWithoutLocale}`);\n };\n\n return {\n ...reactLocaleHook,\n setLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAGO;AACP,wBAAuC;AACvC,4BAA6D;AAE7D,MAAM,EAAE,cAAc,IAAI;AAEnB,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,gBAAgB,QAAI,uCAAgB;AAC5C,QAAM,sBAAkB,sBAAAA,WAAe;AACvC,QAAM,aAAS,6BAAU;AACzB,QAAM,eAAW,+BAAY;AAE7B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,EACV,IAAI;AAEJ,QAAM,YAAY,CAAC,WAAoB;AACrC,QAAI,cAAc,SAAS,MAAM,OAAO,SAAS;AAAG;AAEpD,QAAI,CAAC,iBAAiB,SAAS,MAAM,GAAG;AACtC,cAAQ,MAAM,UAAU,MAAM,mBAAmB;AACjD;AAAA,IACF;AAEA,oBAAgB,MAAM;AAEtB,UAAM,oBACJ,CAAC,iBAAiB,cAAc,SAAS,MAAM,cAAc,SAAS,IAClE,WACA,SAAS,MAAM,IAAI,aAAa,GAAG,MAAM,KAAK;AAEpD,QAAI,CAAC,iBAAiB,WAAW,eAAe;AAC9C,aAAO,OAAO,KAAK,iBAAiB;AAAA,IACtC;AAEA,WAAO,OAAO,KAAK,IAAI,MAAM,GAAG,iBAAiB,EAAE;AAAA,EACrD;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":["useReactLocale"]}
@@ -1,12 +1,12 @@
1
- import "react-intlayer";
2
- import { Locales } from "intlayer";
1
+ import 'react-intlayer';
2
+ import { Locales } from '@intlayer/config/client';
3
3
 
4
4
  declare const useLocale: () => {
5
- setLocale: (locale: Locales) => void;
6
- locale: Locales;
7
- defaultLocale: Locales;
8
- availableLocales: Locales[];
9
- localeList: Locales[];
5
+ setLocale: (locale: Locales) => void;
6
+ locale: Locales;
7
+ defaultLocale: Locales;
8
+ availableLocales: Locales[];
9
+ localeList: Locales[];
10
10
  };
11
11
 
12
12
  export { useLocale };
@@ -8,29 +8,24 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var generateStaticParams_exports = {};
24
20
  __export(generateStaticParams_exports, {
25
- generateStaticParams: () => generateStaticParams,
21
+ generateStaticParams: () => generateStaticParams
26
22
  });
27
23
  module.exports = __toCommonJS(generateStaticParams_exports);
28
24
  var import_client = require("@intlayer/config/client");
29
25
  const { locales } = import_client.intlayerIntlConfiguration;
30
26
  const generateStaticParams = () => locales.map((locale) => ({ locale }));
31
27
  // Annotate the CommonJS export names for ESM import in node:
32
- 0 &&
33
- (module.exports = {
34
- generateStaticParams,
35
- });
36
- //# sourceMappingURL=generateStaticParams.cjs.map
28
+ 0 && (module.exports = {
29
+ generateStaticParams
30
+ });
31
+ //# sourceMappingURL=generateStaticParams.cjs.map
@@ -1,7 +1,7 @@
1
- import * as _intlayer_config_client from "@intlayer/config/client";
1
+ import * as _intlayer_config_client from '@intlayer/config/client';
2
2
 
3
3
  declare const generateStaticParams: () => {
4
- locale: _intlayer_config_client.Locales;
4
+ locale: _intlayer_config_client.Locales;
5
5
  }[];
6
6
 
7
7
  export { generateStaticParams };
@@ -8,44 +8,38 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var src_exports = {};
24
20
  __export(src_exports, {
25
21
  LocaleClientContext: () => import_react_intlayer.LocaleClientContext,
26
- LocaleClientContextProvider: () =>
27
- import_react_intlayer.LocaleClientContextProvider,
22
+ LocaleClientContextProvider: () => import_react_intlayer.LocaleClientContextProvider,
28
23
  generateStaticParams: () => import_generateStaticParams.generateStaticParams,
29
24
  getTranslation: () => import_react_intlayer.getTranslation,
30
25
  useIntlayer: () => import_react_intlayer.useIntlayer,
31
26
  useLocale: () => import_useLocale.useLocale,
32
27
  useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
33
- useTraduction: () => import_react_intlayer.useTraduction,
28
+ useTraduction: () => import_react_intlayer.useTraduction
34
29
  });
35
30
  module.exports = __toCommonJS(src_exports);
36
31
  var import_react_intlayer = require("react-intlayer");
37
- var import_generateStaticParams = require("./generateStaticParams.cjs");
38
- var import_useLocale = require("./client/useLocale.cjs");
32
+ var import_generateStaticParams = require('./generateStaticParams.cjs');
33
+ var import_useLocale = require('./client/useLocale.cjs');
39
34
  // Annotate the CommonJS export names for ESM import in node:
40
- 0 &&
41
- (module.exports = {
42
- LocaleClientContext,
43
- LocaleClientContextProvider,
44
- generateStaticParams,
45
- getTranslation,
46
- useIntlayer,
47
- useLocale,
48
- useLocaleCookie,
49
- useTraduction,
50
- });
51
- //# sourceMappingURL=index.cjs.map
35
+ 0 && (module.exports = {
36
+ LocaleClientContext,
37
+ LocaleClientContextProvider,
38
+ generateStaticParams,
39
+ getTranslation,
40
+ useIntlayer,
41
+ useLocale,
42
+ useLocaleCookie,
43
+ useTraduction
44
+ });
45
+ //# sourceMappingURL=index.cjs.map
@@ -1,15 +1,8 @@
1
- export {
2
- LocaleClientContext,
3
- LocaleClientContextProvider,
4
- getTranslation,
5
- useIntlayer,
6
- useLocaleCookie,
7
- useTraduction,
8
- } from "react-intlayer";
9
- export { generateStaticParams } from "./generateStaticParams.js";
10
- export { LocalParams, NextPageIntlayer } from "./types/NextPage.js";
11
- export { useLocale } from "./client/useLocale.js";
12
- import "@intlayer/config/client";
13
- import "intlayer";
14
- import "next";
15
- import "react";
1
+ export { LocaleClientContext, LocaleClientContextProvider, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
2
+ export { generateStaticParams } from './generateStaticParams.js';
3
+ export { LocalParams, NextPageIntlayer } from './types/NextPage.js';
4
+ export { useLocale } from './client/useLocale.js';
5
+ import '@intlayer/config/client';
6
+ import 'intlayer';
7
+ import 'next';
8
+ import 'react';
@@ -4,32 +4,20 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __copyProps = (to, from, except, desc) => {
7
- if ((from && typeof from === "object") || typeof from === "function") {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
8
  for (let key of __getOwnPropNames(from))
9
9
  if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, {
11
- get: () => from[key],
12
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
13
- });
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
11
  }
15
12
  return to;
16
13
  };
17
- var __reExport = (target, mod, secondTarget) => (
18
- __copyProps(target, mod, "default"),
19
- secondTarget && __copyProps(secondTarget, mod, "default")
20
- );
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
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);
23
16
  var middleware_exports = {};
24
17
  module.exports = __toCommonJS(middleware_exports);
25
- __reExport(
26
- middleware_exports,
27
- require("./intlayerMiddleware.cjs"),
28
- module.exports
29
- );
18
+ __reExport(middleware_exports, require('./intlayerMiddleware.cjs'), module.exports);
30
19
  // Annotate the CommonJS export names for ESM import in node:
31
- 0 &&
32
- (module.exports = {
33
- ...require("./intlayerMiddleware.cjs"),
34
- });
35
- //# sourceMappingURL=index.cjs.map
20
+ 0 && (module.exports = {
21
+ ...require('./intlayerMiddleware.cjs')
22
+ });
23
+ //# sourceMappingURL=index.cjs.map
@@ -1,2 +1,2 @@
1
- export { intlayerMiddleware } from "./intlayerMiddleware.js";
2
- import "next/server";
1
+ export { intlayerMiddleware } from './intlayerMiddleware.js';
2
+ import 'next/server';
@@ -8,28 +8,23 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if ((from && typeof from === "object") || typeof from === "function") {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
17
- });
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
19
16
  return to;
20
17
  };
21
- var __toCommonJS = (mod) =>
22
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
19
  var intlayerMiddleware_exports = {};
24
20
  __export(intlayerMiddleware_exports, {
25
- intlayerMiddleware: () => intlayerMiddleware,
21
+ intlayerMiddleware: () => intlayerMiddleware
26
22
  });
27
23
  module.exports = __toCommonJS(intlayerMiddleware_exports);
28
24
  var import_client = require("@intlayer/config/client");
29
25
  var import_server = require("next/server");
30
- var import_localeDetector = require("./localeDetector.cjs");
31
- const { internationalization, middleware } =
32
- import_client.intlayerConfiguration;
26
+ var import_localeDetector = require('./localeDetector.cjs');
27
+ const { internationalization, middleware } = import_client.intlayerConfiguration;
33
28
  const { locales, defaultLocale } = internationalization;
34
29
  const {
35
30
  headerName,
@@ -37,7 +32,7 @@ const {
37
32
  prefixDefault,
38
33
  basePath,
39
34
  serverSetCookie,
40
- noPrefix,
35
+ noPrefix
41
36
  } = middleware;
42
37
  const intlayerMiddleware = (request) => {
43
38
  const pathname = request.nextUrl.pathname;
@@ -61,18 +56,14 @@ const intlayerMiddleware = (request) => {
61
56
  );
62
57
  };
63
58
  const getCookieLocale = (request) => {
64
- if (!cookieName) return void 0;
59
+ if (!cookieName)
60
+ return void 0;
65
61
  const cookieValue = request.cookies.get(cookieName)?.value;
66
62
  if (cookieValue && locales.includes(cookieValue)) {
67
63
  return cookieValue;
68
64
  }
69
65
  };
70
- const handleNoPrefix = (
71
- request,
72
- cookieLocale,
73
- pathname,
74
- basePathTrailingSlash
75
- ) => {
66
+ const handleNoPrefix = (request, cookieLocale, pathname, basePathTrailingSlash) => {
76
67
  const locale = cookieLocale ?? defaultLocale;
77
68
  const newPath = constructPath(
78
69
  locale,
@@ -82,17 +73,10 @@ const handleNoPrefix = (
82
73
  );
83
74
  return rewriteUrl(request, newPath, locale);
84
75
  };
85
- const getPathLocale = (pathname) =>
86
- locales.find(
87
- (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
88
- );
89
- const handlePrefix = (
90
- request,
91
- cookieLocale,
92
- pathLocale,
93
- pathname,
94
- basePathTrailingSlash
95
- ) => {
76
+ const getPathLocale = (pathname) => locales.find(
77
+ (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
78
+ );
79
+ const handlePrefix = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
96
80
  if (!pathLocale) {
97
81
  return handleMissingPathLocale(
98
82
  request,
@@ -109,16 +93,8 @@ const handlePrefix = (
109
93
  basePathTrailingSlash
110
94
  );
111
95
  };
112
- const handleMissingPathLocale = (
113
- request,
114
- cookieLocale,
115
- pathname,
116
- basePathTrailingSlash
117
- ) => {
118
- let locale =
119
- cookieLocale ??
120
- (0, import_localeDetector.localeDetector)?.(request) ??
121
- defaultLocale;
96
+ const handleMissingPathLocale = (request, cookieLocale, pathname, basePathTrailingSlash) => {
97
+ let locale = cookieLocale ?? (0, import_localeDetector.localeDetector)?.(request) ?? defaultLocale;
122
98
  if (!locales.includes(locale)) {
123
99
  console.warn(
124
100
  "The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale."
@@ -131,22 +107,10 @@ const handleMissingPathLocale = (
131
107
  basePath,
132
108
  basePathTrailingSlash
133
109
  );
134
- return prefixDefault || locale !== defaultLocale
135
- ? redirectUrl(request, newPath)
136
- : rewriteUrl(request, newPath, locale);
110
+ return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
137
111
  };
138
- const handleExistingPathLocale = (
139
- request,
140
- cookieLocale,
141
- pathLocale,
142
- pathname,
143
- basePathTrailingSlash
144
- ) => {
145
- if (
146
- cookieLocale &&
147
- cookieLocale !== pathLocale &&
148
- serverSetCookie !== "always"
149
- ) {
112
+ const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
113
+ if (cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always") {
150
114
  const newPath = handleCookieLocaleMismatch(
151
115
  request,
152
116
  pathname,
@@ -164,14 +128,7 @@ const handleExistingPathLocale = (
164
128
  basePathTrailingSlash
165
129
  );
166
130
  };
167
- const handleCookieLocaleMismatch = (
168
- request,
169
- pathname,
170
- pathLocale,
171
- cookieLocale,
172
- basePath2,
173
- basePathTrailingSlash
174
- ) => {
131
+ const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath2, basePathTrailingSlash) => {
175
132
  const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
176
133
  return constructPath(
177
134
  cookieLocale,
@@ -181,12 +138,7 @@ const handleCookieLocaleMismatch = (
181
138
  request.nextUrl.search
182
139
  );
183
140
  };
184
- const handleDefaultLocaleRedirect = (
185
- request,
186
- pathLocale,
187
- pathname,
188
- basePathTrailingSlash
189
- ) => {
141
+ const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrailingSlash) => {
190
142
  if (!prefixDefault && pathLocale === defaultLocale) {
191
143
  let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
192
144
  if (basePathTrailingSlash) {
@@ -199,13 +151,7 @@ const handleDefaultLocaleRedirect = (
199
151
  }
200
152
  return rewriteUrl(request, pathname, pathLocale);
201
153
  };
202
- const constructPath = (
203
- locale,
204
- path,
205
- basePath2,
206
- basePathTrailingSlash,
207
- search
208
- ) => {
154
+ const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) => {
209
155
  let newPath = `${locale}${path}`;
210
156
  newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
211
157
  if (search) {
@@ -214,17 +160,13 @@ const constructPath = (
214
160
  return newPath;
215
161
  };
216
162
  const rewriteUrl = (request, newPath, locale) => {
217
- const response = import_server.NextResponse.rewrite(
218
- new URL(newPath, request.url)
219
- );
163
+ const response = import_server.NextResponse.rewrite(new URL(newPath, request.url));
220
164
  response.headers.set(headerName, locale);
221
165
  return response;
222
166
  };
223
- const redirectUrl = (request, newPath) =>
224
- import_server.NextResponse.redirect(new URL(newPath, request.url));
167
+ const redirectUrl = (request, newPath) => import_server.NextResponse.redirect(new URL(newPath, request.url));
225
168
  // Annotate the CommonJS export names for ESM import in node:
226
- 0 &&
227
- (module.exports = {
228
- intlayerMiddleware,
229
- });
230
- //# sourceMappingURL=intlayerMiddleware.cjs.map
169
+ 0 && (module.exports = {
170
+ intlayerMiddleware
171
+ });
172
+ //# sourceMappingURL=intlayerMiddleware.cjs.map
@@ -1,4 +1,4 @@
1
- import { NextRequest, NextResponse } from "next/server";
1
+ import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
3
  declare const intlayerMiddleware: (request: NextRequest) => NextResponse;
4
4
 
@@ -10,53 +10,37 @@ var __export = (target, all) => {
10
10
  __defProp(target, name, { get: all[name], enumerable: true });
11
11
  };
12
12
  var __copyProps = (to, from, except, desc) => {
13
- if ((from && typeof from === "object") || typeof from === "function") {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
14
  for (let key of __getOwnPropNames(from))
15
15
  if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, {
17
- get: () => from[key],
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
19
- });
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
17
  }
21
18
  return to;
22
19
  };
23
- var __toESM = (mod, isNodeMode, target) => (
24
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
25
- __copyProps(
26
- // If the importer is in node compatibility mode or this is not an ESM
27
- // file that has been converted to a CommonJS file using a Babel-
28
- // compatible transform (i.e. "__esModule" has not been set), then set
29
- // "default" to the CommonJS "module.exports" for node compatibility.
30
- isNodeMode || !mod || !mod.__esModule
31
- ? __defProp(target, "default", { value: mod, enumerable: true })
32
- : target,
33
- mod
34
- )
35
- );
36
- var __toCommonJS = (mod) =>
37
- __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
29
  var localeDetector_exports = {};
39
30
  __export(localeDetector_exports, {
40
- localeDetector: () => localeDetector,
31
+ localeDetector: () => localeDetector
41
32
  });
42
33
  module.exports = __toCommonJS(localeDetector_exports);
43
34
  var import_intl_localematcher = require("@formatjs/intl-localematcher");
44
35
  var import_client = require("@intlayer/config/client");
45
36
  var import_negotiator = __toESM(require("negotiator"));
46
- const { locales, defaultLocale } = (0, import_client.getConfiguration)()
47
- .internationalization;
37
+ const { locales, defaultLocale } = (0, import_client.getConfiguration)().internationalization;
48
38
  const localeDetector = (request) => {
49
39
  const negotiatorHeaders = {};
50
- request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));
51
- const languages = new import_negotiator.default({
52
- headers: negotiatorHeaders,
53
- }).languages();
40
+ request.headers.forEach((value, key) => negotiatorHeaders[key] = value);
41
+ const languages = new import_negotiator.default({ headers: negotiatorHeaders }).languages();
54
42
  try {
55
- return (0, import_intl_localematcher.match)(
56
- languages,
57
- locales,
58
- defaultLocale
59
- );
43
+ return (0, import_intl_localematcher.match)(languages, locales, defaultLocale);
60
44
  } catch (e) {
61
45
  console.warn(
62
46
  `No valid locales in accept-language header: ${languages.join(", ")}`
@@ -66,8 +50,7 @@ const localeDetector = (request) => {
66
50
  }
67
51
  };
68
52
  // Annotate the CommonJS export names for ESM import in node:
69
- 0 &&
70
- (module.exports = {
71
- localeDetector,
72
- });
73
- //# sourceMappingURL=localeDetector.cjs.map
53
+ 0 && (module.exports = {
54
+ localeDetector
55
+ });
56
+ //# sourceMappingURL=localeDetector.cjs.map