next-intlayer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/client/index.cjs +48 -0
- package/dist/cjs/client/index.cjs.map +1 -0
- package/dist/cjs/client/index.d.ts +10 -0
- package/dist/cjs/client/useLocale.cjs +68 -0
- package/dist/cjs/client/useLocale.cjs.map +1 -0
- package/dist/cjs/client/useLocale.d.ts +12 -0
- package/dist/cjs/generateStaticParams.cjs +36 -0
- package/dist/cjs/generateStaticParams.cjs.map +1 -0
- package/dist/cjs/generateStaticParams.d.ts +7 -0
- package/dist/cjs/index.cjs +51 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +15 -0
- package/dist/cjs/middleware/index.cjs +35 -0
- package/dist/cjs/middleware/index.cjs.map +1 -0
- package/dist/cjs/middleware/index.d.ts +2 -0
- package/dist/cjs/middleware/intlayerMiddleware.cjs +230 -0
- package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -0
- package/dist/cjs/middleware/intlayerMiddleware.d.ts +5 -0
- package/dist/cjs/middleware/localeDetector.cjs +73 -0
- package/dist/cjs/middleware/localeDetector.cjs.map +1 -0
- package/dist/cjs/middleware/localeDetector.d.ts +6 -0
- package/dist/cjs/server/index.cjs +47 -0
- package/dist/cjs/server/index.cjs.map +1 -0
- package/dist/cjs/server/index.d.ts +10 -0
- package/dist/cjs/server/withIntlayer.cjs +76 -0
- package/dist/cjs/server/withIntlayer.cjs.map +1 -0
- package/dist/cjs/server/withIntlayer.d.ts +9 -0
- package/dist/cjs/types/NextPage.cjs +21 -0
- package/dist/cjs/types/NextPage.cjs.map +1 -0
- package/dist/cjs/types/NextPage.d.ts +13 -0
- package/dist/cjs/types/index.cjs +21 -0
- package/dist/cjs/types/index.cjs.map +1 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/esm/client/index.d.mts +10 -0
- package/dist/esm/client/index.mjs +19 -0
- package/dist/esm/client/index.mjs.map +1 -0
- package/dist/esm/client/useLocale.d.mts +12 -0
- package/dist/esm/client/useLocale.mjs +37 -0
- package/dist/esm/client/useLocale.mjs.map +1 -0
- package/dist/esm/generateStaticParams.d.mts +7 -0
- package/dist/esm/generateStaticParams.mjs +5 -0
- package/dist/esm/generateStaticParams.mjs.map +1 -0
- package/dist/esm/index.d.mts +15 -0
- package/dist/esm/index.mjs +21 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/middleware/index.d.mts +2 -0
- package/dist/esm/middleware/index.mjs +2 -0
- package/dist/esm/middleware/index.mjs.map +1 -0
- package/dist/esm/middleware/intlayerMiddleware.d.mts +5 -0
- package/dist/esm/middleware/intlayerMiddleware.mjs +193 -0
- package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -0
- package/dist/esm/middleware/localeDetector.d.mts +6 -0
- package/dist/esm/middleware/localeDetector.mjs +20 -0
- package/dist/esm/middleware/localeDetector.mjs.map +1 -0
- package/dist/esm/server/index.d.mts +10 -0
- package/dist/esm/server/index.mjs +19 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/dist/esm/server/withIntlayer.d.mts +9 -0
- package/dist/esm/server/withIntlayer.mjs +40 -0
- package/dist/esm/server/withIntlayer.mjs.map +1 -0
- package/dist/esm/types/NextPage.d.mts +13 -0
- package/dist/esm/types/NextPage.mjs +1 -0
- package/dist/esm/types/NextPage.mjs.map +1 -0
- package/dist/esm/types/index.d.mts +4 -0
- package/dist/esm/types/index.mjs +1 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/package.json +105 -0
- package/src/client/index.ts +9 -0
- package/src/client/useLocale.ts +46 -0
- package/src/generateStaticParams.ts +5 -0
- package/src/index.ts +11 -0
- package/src/middleware/index.ts +1 -0
- package/src/middleware/intlayerMiddleware.ts +215 -0
- package/src/middleware/localeDetector.ts +28 -0
- package/src/server/index.ts +9 -0
- package/src/server/withIntlayer.ts +61 -0
- package/src/types/NextPage.ts +10 -0
- package/src/types/index.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2021 Sébastien Vanvelthem
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var client_exports = {};
|
|
24
|
+
__export(client_exports, {
|
|
25
|
+
LocaleClientContext: () => import_react_intlayer.LocaleClientContext,
|
|
26
|
+
LocaleClientContextProvider: () =>
|
|
27
|
+
import_react_intlayer.LocaleClientContextProvider,
|
|
28
|
+
getTranslation: () => import_react_intlayer.getTranslation,
|
|
29
|
+
useIntlayer: () => import_react_intlayer.useIntlayer,
|
|
30
|
+
useLocale: () => import_useLocale.useLocale,
|
|
31
|
+
useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
|
|
32
|
+
useTraduction: () => import_react_intlayer.useTraduction,
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(client_exports);
|
|
35
|
+
var import_react_intlayer = require("react-intlayer");
|
|
36
|
+
var import_useLocale = require("./useLocale.cjs");
|
|
37
|
+
// 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/client/index.ts"],"sourcesContent":["export {\n getTranslation,\n LocaleClientContextProvider,\n LocaleClientContext,\n useIntlayer,\n useTraduction,\n useLocaleCookie,\n} from 'react-intlayer';\nexport { useLocale } from './useLocale';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAOO;AACP,uBAA0B;","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var useLocale_exports = {};
|
|
24
|
+
__export(useLocale_exports, {
|
|
25
|
+
useLocale: () => useLocale,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useLocale_exports);
|
|
28
|
+
var import_client = require("@intlayer/config/client");
|
|
29
|
+
var import_navigation = require("next/navigation.js");
|
|
30
|
+
var import_react_intlayer = require("react-intlayer");
|
|
31
|
+
const { prefixDefault } = import_client.intlayerMiddlewareConfiguration;
|
|
32
|
+
const useLocale = () => {
|
|
33
|
+
const { setLocaleCookie } = (0, import_react_intlayer.useLocaleCookie)();
|
|
34
|
+
const reactLocaleHook = (0, import_react_intlayer.useLocale)();
|
|
35
|
+
const router = (0, import_navigation.useRouter)();
|
|
36
|
+
const pathname = (0, import_navigation.usePathname)();
|
|
37
|
+
const {
|
|
38
|
+
defaultLocale,
|
|
39
|
+
availableLocales,
|
|
40
|
+
locale: currentLocale,
|
|
41
|
+
} = reactLocaleHook;
|
|
42
|
+
const setLocale = (locale) => {
|
|
43
|
+
if (currentLocale === locale) return;
|
|
44
|
+
if (!availableLocales.includes(locale)) {
|
|
45
|
+
console.error(`Locale ${locale} is not available`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setLocaleCookie(locale);
|
|
49
|
+
const pathWithoutLocale =
|
|
50
|
+
!prefixDefault && currentLocale === defaultLocale
|
|
51
|
+
? pathname
|
|
52
|
+
: pathname.slice(`/${currentLocale}`.length) || "/";
|
|
53
|
+
if (!prefixDefault && locale === defaultLocale) {
|
|
54
|
+
return router.push(pathWithoutLocale);
|
|
55
|
+
}
|
|
56
|
+
return router.push(`/${locale}${pathWithoutLocale}`);
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
...reactLocaleHook,
|
|
60
|
+
setLocale,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 &&
|
|
65
|
+
(module.exports = {
|
|
66
|
+
useLocale,
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -0,0 +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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "react-intlayer";
|
|
2
|
+
import { Locales } from "intlayer";
|
|
3
|
+
|
|
4
|
+
declare const useLocale: () => {
|
|
5
|
+
setLocale: (locale: Locales) => void;
|
|
6
|
+
locale: Locales;
|
|
7
|
+
defaultLocale: Locales;
|
|
8
|
+
availableLocales: Locales[];
|
|
9
|
+
localeList: Locales[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export { useLocale };
|
|
@@ -0,0 +1,36 @@
|
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var generateStaticParams_exports = {};
|
|
24
|
+
__export(generateStaticParams_exports, {
|
|
25
|
+
generateStaticParams: () => generateStaticParams,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(generateStaticParams_exports);
|
|
28
|
+
var import_client = require("@intlayer/config/client");
|
|
29
|
+
const { locales } = import_client.intlayerIntlConfiguration;
|
|
30
|
+
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 &&
|
|
33
|
+
(module.exports = {
|
|
34
|
+
generateStaticParams,
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=generateStaticParams.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import { intlayerIntlConfiguration } from '@intlayer/config/client';\n\nconst { locales } = intlayerIntlConfiguration;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAE1C,MAAM,EAAE,QAAQ,IAAI;AAEb,MAAM,uBAAuB,MAAM,QAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE;","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var src_exports = {};
|
|
24
|
+
__export(src_exports, {
|
|
25
|
+
LocaleClientContext: () => import_react_intlayer.LocaleClientContext,
|
|
26
|
+
LocaleClientContextProvider: () =>
|
|
27
|
+
import_react_intlayer.LocaleClientContextProvider,
|
|
28
|
+
generateStaticParams: () => import_generateStaticParams.generateStaticParams,
|
|
29
|
+
getTranslation: () => import_react_intlayer.getTranslation,
|
|
30
|
+
useIntlayer: () => import_react_intlayer.useIntlayer,
|
|
31
|
+
useLocale: () => import_useLocale.useLocale,
|
|
32
|
+
useLocaleCookie: () => import_react_intlayer.useLocaleCookie,
|
|
33
|
+
useTraduction: () => import_react_intlayer.useTraduction,
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_react_intlayer = require("react-intlayer");
|
|
37
|
+
var import_generateStaticParams = require("./generateStaticParams.cjs");
|
|
38
|
+
var import_useLocale = require("./client/useLocale.cjs");
|
|
39
|
+
// 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export {\n getTranslation,\n LocaleClientContextProvider,\n LocaleClientContext,\n useIntlayer,\n useTraduction,\n useLocaleCookie,\n} from 'react-intlayer';\nexport { generateStaticParams } from './generateStaticParams';\nexport type { LocalParams, NextPageIntlayer } from './types/index';\nexport { useLocale } from './client/useLocale';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAOO;AACP,kCAAqC;AAErC,uBAA0B;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
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";
|
|
@@ -0,0 +1,35 @@
|
|
|
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, {
|
|
11
|
+
get: () => from[key],
|
|
12
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
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);
|
|
23
|
+
var middleware_exports = {};
|
|
24
|
+
module.exports = __toCommonJS(middleware_exports);
|
|
25
|
+
__reExport(
|
|
26
|
+
middleware_exports,
|
|
27
|
+
require("./intlayerMiddleware.cjs"),
|
|
28
|
+
module.exports
|
|
29
|
+
);
|
|
30
|
+
// 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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/middleware/index.ts"],"sourcesContent":["export * from './intlayerMiddleware';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,+BAAc,iCAAd;","names":[]}
|
|
@@ -0,0 +1,230 @@
|
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) =>
|
|
22
|
+
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var intlayerMiddleware_exports = {};
|
|
24
|
+
__export(intlayerMiddleware_exports, {
|
|
25
|
+
intlayerMiddleware: () => intlayerMiddleware,
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(intlayerMiddleware_exports);
|
|
28
|
+
var import_client = require("@intlayer/config/client");
|
|
29
|
+
var import_server = require("next/server");
|
|
30
|
+
var import_localeDetector = require("./localeDetector.cjs");
|
|
31
|
+
const { internationalization, middleware } =
|
|
32
|
+
import_client.intlayerConfiguration;
|
|
33
|
+
const { locales, defaultLocale } = internationalization;
|
|
34
|
+
const {
|
|
35
|
+
headerName,
|
|
36
|
+
cookieName,
|
|
37
|
+
prefixDefault,
|
|
38
|
+
basePath,
|
|
39
|
+
serverSetCookie,
|
|
40
|
+
noPrefix,
|
|
41
|
+
} = middleware;
|
|
42
|
+
const intlayerMiddleware = (request) => {
|
|
43
|
+
const pathname = request.nextUrl.pathname;
|
|
44
|
+
const cookieLocale = getCookieLocale(request);
|
|
45
|
+
const basePathTrailingSlash = basePath.endsWith("/");
|
|
46
|
+
if (noPrefix) {
|
|
47
|
+
return handleNoPrefix(
|
|
48
|
+
request,
|
|
49
|
+
cookieLocale,
|
|
50
|
+
pathname,
|
|
51
|
+
basePathTrailingSlash
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const pathLocale = getPathLocale(pathname);
|
|
55
|
+
return handlePrefix(
|
|
56
|
+
request,
|
|
57
|
+
cookieLocale,
|
|
58
|
+
pathLocale,
|
|
59
|
+
pathname,
|
|
60
|
+
basePathTrailingSlash
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
const getCookieLocale = (request) => {
|
|
64
|
+
if (!cookieName) return void 0;
|
|
65
|
+
const cookieValue = request.cookies.get(cookieName)?.value;
|
|
66
|
+
if (cookieValue && locales.includes(cookieValue)) {
|
|
67
|
+
return cookieValue;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const handleNoPrefix = (
|
|
71
|
+
request,
|
|
72
|
+
cookieLocale,
|
|
73
|
+
pathname,
|
|
74
|
+
basePathTrailingSlash
|
|
75
|
+
) => {
|
|
76
|
+
const locale = cookieLocale ?? defaultLocale;
|
|
77
|
+
const newPath = constructPath(
|
|
78
|
+
locale,
|
|
79
|
+
pathname,
|
|
80
|
+
basePath,
|
|
81
|
+
basePathTrailingSlash
|
|
82
|
+
);
|
|
83
|
+
return rewriteUrl(request, newPath, locale);
|
|
84
|
+
};
|
|
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
|
+
) => {
|
|
96
|
+
if (!pathLocale) {
|
|
97
|
+
return handleMissingPathLocale(
|
|
98
|
+
request,
|
|
99
|
+
cookieLocale,
|
|
100
|
+
pathname,
|
|
101
|
+
basePathTrailingSlash
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return handleExistingPathLocale(
|
|
105
|
+
request,
|
|
106
|
+
cookieLocale,
|
|
107
|
+
pathLocale,
|
|
108
|
+
pathname,
|
|
109
|
+
basePathTrailingSlash
|
|
110
|
+
);
|
|
111
|
+
};
|
|
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;
|
|
122
|
+
if (!locales.includes(locale)) {
|
|
123
|
+
console.warn(
|
|
124
|
+
"The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale."
|
|
125
|
+
);
|
|
126
|
+
locale = defaultLocale;
|
|
127
|
+
}
|
|
128
|
+
const newPath = constructPath(
|
|
129
|
+
locale,
|
|
130
|
+
pathname,
|
|
131
|
+
basePath,
|
|
132
|
+
basePathTrailingSlash
|
|
133
|
+
);
|
|
134
|
+
return prefixDefault || locale !== defaultLocale
|
|
135
|
+
? redirectUrl(request, newPath)
|
|
136
|
+
: rewriteUrl(request, newPath, locale);
|
|
137
|
+
};
|
|
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
|
+
) {
|
|
150
|
+
const newPath = handleCookieLocaleMismatch(
|
|
151
|
+
request,
|
|
152
|
+
pathname,
|
|
153
|
+
pathLocale,
|
|
154
|
+
cookieLocale,
|
|
155
|
+
basePath,
|
|
156
|
+
basePathTrailingSlash
|
|
157
|
+
);
|
|
158
|
+
return redirectUrl(request, newPath);
|
|
159
|
+
}
|
|
160
|
+
return handleDefaultLocaleRedirect(
|
|
161
|
+
request,
|
|
162
|
+
pathLocale,
|
|
163
|
+
pathname,
|
|
164
|
+
basePathTrailingSlash
|
|
165
|
+
);
|
|
166
|
+
};
|
|
167
|
+
const handleCookieLocaleMismatch = (
|
|
168
|
+
request,
|
|
169
|
+
pathname,
|
|
170
|
+
pathLocale,
|
|
171
|
+
cookieLocale,
|
|
172
|
+
basePath2,
|
|
173
|
+
basePathTrailingSlash
|
|
174
|
+
) => {
|
|
175
|
+
const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
|
|
176
|
+
return constructPath(
|
|
177
|
+
cookieLocale,
|
|
178
|
+
newPath,
|
|
179
|
+
basePath2,
|
|
180
|
+
basePathTrailingSlash,
|
|
181
|
+
request.nextUrl.search
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
const handleDefaultLocaleRedirect = (
|
|
185
|
+
request,
|
|
186
|
+
pathLocale,
|
|
187
|
+
pathname,
|
|
188
|
+
basePathTrailingSlash
|
|
189
|
+
) => {
|
|
190
|
+
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
191
|
+
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
192
|
+
if (basePathTrailingSlash) {
|
|
193
|
+
pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
194
|
+
}
|
|
195
|
+
if (request.nextUrl.search) {
|
|
196
|
+
pathWithoutLocale += request.nextUrl.search;
|
|
197
|
+
}
|
|
198
|
+
return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);
|
|
199
|
+
}
|
|
200
|
+
return rewriteUrl(request, pathname, pathLocale);
|
|
201
|
+
};
|
|
202
|
+
const constructPath = (
|
|
203
|
+
locale,
|
|
204
|
+
path,
|
|
205
|
+
basePath2,
|
|
206
|
+
basePathTrailingSlash,
|
|
207
|
+
search
|
|
208
|
+
) => {
|
|
209
|
+
let newPath = `${locale}${path}`;
|
|
210
|
+
newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
|
|
211
|
+
if (search) {
|
|
212
|
+
newPath += search;
|
|
213
|
+
}
|
|
214
|
+
return newPath;
|
|
215
|
+
};
|
|
216
|
+
const rewriteUrl = (request, newPath, locale) => {
|
|
217
|
+
const response = import_server.NextResponse.rewrite(
|
|
218
|
+
new URL(newPath, request.url)
|
|
219
|
+
);
|
|
220
|
+
response.headers.set(headerName, locale);
|
|
221
|
+
return response;
|
|
222
|
+
};
|
|
223
|
+
const redirectUrl = (request, newPath) =>
|
|
224
|
+
import_server.NextResponse.redirect(new URL(newPath, request.url));
|
|
225
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
226
|
+
0 &&
|
|
227
|
+
(module.exports = {
|
|
228
|
+
intlayerMiddleware,
|
|
229
|
+
});
|
|
230
|
+
//# sourceMappingURL=intlayerMiddleware.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/middleware/intlayerMiddleware.ts"],"sourcesContent":["import { type Locales, intlayerConfiguration } from '@intlayer/config/client';\nimport { type NextRequest, NextResponse } from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, middleware } = intlayerConfiguration;\nconst { locales, defaultLocale } = internationalization;\nconst {\n headerName,\n cookieName,\n prefixDefault,\n basePath,\n serverSetCookie,\n noPrefix,\n} = middleware;\n\nexport const intlayerMiddleware = (request: NextRequest): NextResponse => {\n const pathname = request.nextUrl.pathname;\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (noPrefix) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\nconst getCookieLocale = (request: NextRequest): Locales | undefined => {\n if (!cookieName) return undefined;\n const cookieValue = request.cookies.get(cookieName)?.value as Locales;\n if (cookieValue && locales.includes(cookieValue)) {\n return cookieValue;\n }\n};\n\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash\n );\n return rewriteUrl(request, newPath, locale);\n};\n\nconst getPathLocale = (pathname: string): Locales | undefined =>\n locales.find(\n (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`\n );\n\nconst handlePrefix = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (!pathLocale) {\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\nconst handleMissingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;\n if (!locales.includes(locale)) {\n console.warn(\n 'The localeDetector callback must return a locale included in your locales array. Reverting to using defaultLocale.'\n );\n locale = defaultLocale;\n }\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash\n );\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\n};\n\nconst handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locales | undefined,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n cookieLocale &&\n cookieLocale !== pathLocale &&\n serverSetCookie !== 'always'\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n\n pathname: string,\n pathLocale: Locales,\n cookieLocale: Locales,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n request.nextUrl.search\n );\n};\n\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locales,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (!prefixDefault && pathLocale === defaultLocale) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n return rewriteUrl(request, pathname, pathLocale);\n};\n\nconst constructPath = (\n locale: Locales,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n let newPath = `${locale}${path}`;\n newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${newPath}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locales\n): NextResponse => {\n const response = NextResponse.rewrite(new URL(newPath, request.url));\n response.headers.set(headerName, locale);\n return response;\n};\n\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse =>\n NextResponse.redirect(new URL(newPath, request.url));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAoD;AACpD,oBAA+C;AAC/C,4BAA+B;AAE/B,MAAM,EAAE,sBAAsB,WAAW,IAAI;AAC7C,MAAM,EAAE,SAAS,cAAc,IAAI;AACnC,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI;AAEG,MAAM,qBAAqB,CAAC,YAAuC;AACxE,QAAM,WAAW,QAAQ,QAAQ;AACjC,QAAM,eAAe,gBAAgB,OAAO;AAC5C,QAAM,wBAAwB,SAAS,SAAS,GAAG;AAEnD,MAAI,UAAU;AACZ,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAa,cAAc,QAAQ;AACzC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,kBAAkB,CAAC,YAA8C;AACrE,MAAI,CAAC;AAAY,WAAO;AACxB,QAAM,cAAc,QAAQ,QAAQ,IAAI,UAAU,GAAG;AACrD,MAAI,eAAe,QAAQ,SAAS,WAAW,GAAG;AAChD,WAAO;AAAA,EACT;AACF;AAEA,MAAM,iBAAiB,CACrB,SACA,cACA,UACA,0BACiB;AACjB,QAAM,SAAS,gBAAgB;AAC/B,QAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,WAAW,SAAS,SAAS,MAAM;AAC5C;AAEA,MAAM,gBAAgB,CAAC,aACrB,QAAQ;AAAA,EACN,CAAC,WAAW,SAAS,WAAW,IAAI,MAAM,GAAG,KAAK,aAAa,IAAI,MAAM;AAC3E;AAEF,MAAM,eAAe,CACnB,SACA,cACA,YACA,UACA,0BACiB;AACjB,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,0BAA0B,CAC9B,SACA,cACA,UACA,0BACiB;AACjB,MAAI,SAAS,oBAAgB,wCAAiB,OAAO,KAAK;AAC1D,MAAI,CAAC,QAAQ,SAAS,MAAM,GAAG;AAC7B,YAAQ;AAAA,MACN;AAAA,IACF;AACA,aAAS;AAAA,EACX;AACA,QAAM,UAAU;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,iBAAiB,WAAW,gBAC/B,YAAY,SAAS,OAAO,IAC5B,WAAW,SAAS,SAAS,MAAM;AACzC;AAEA,MAAM,2BAA2B,CAC/B,SACA,cACA,YACA,UACA,0BACiB;AACjB,MACE,gBACA,iBAAiB,cACjB,oBAAoB,UACpB;AACA,UAAM,UAAU;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,WAAO,YAAY,SAAS,OAAO;AAAA,EACrC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,MAAM,6BAA6B,CACjC,SAEA,UACA,YACA,cACAA,WACA,0BACW;AACX,QAAM,UAAU,SAAS,QAAQ,IAAI,UAAU,IAAI,IAAI,YAAY,EAAE;AACrE,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACAA;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,EAClB;AACF;AAEA,MAAM,8BAA8B,CAClC,SACA,YACA,UACA,0BACiB;AACjB,MAAI,CAAC,iBAAiB,eAAe,eAAe;AAClD,QAAI,oBAAoB,SAAS,MAAM,IAAI,UAAU,GAAG,MAAM,KAAK;AAEnE,QAAI,uBAAuB;AACzB,0BAAoB,kBAAkB,MAAM,CAAC;AAAA,IAC/C;AAEA,QAAI,QAAQ,QAAQ,QAAQ;AAC1B,2BAAqB,QAAQ,QAAQ;AAAA,IACvC;AAEA,WAAO,WAAW,SAAS,GAAG,QAAQ,GAAG,iBAAiB,IAAI,UAAU;AAAA,EAC1E;AACA,SAAO,WAAW,SAAS,UAAU,UAAU;AACjD;AAEA,MAAM,gBAAgB,CACpB,QACA,MACAA,WACA,uBACA,WACW;AACX,MAAI,UAAU,GAAG,MAAM,GAAG,IAAI;AAC9B,YAAU,GAAGA,SAAQ,GAAG,wBAAwB,KAAK,GAAG,GAAG,OAAO;AAClE,MAAI,QAAQ;AACV,eAAW;AAAA,EACb;AACA,SAAO;AACT;AAEA,MAAM,aAAa,CACjB,SACA,SACA,WACiB;AACjB,QAAM,WAAW,2BAAa,QAAQ,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;AACnE,WAAS,QAAQ,IAAI,YAAY,MAAM;AACvC,SAAO;AACT;AAEA,MAAM,cAAc,CAAC,SAAsB,YACzC,2BAAa,SAAS,IAAI,IAAI,SAAS,QAAQ,GAAG,CAAC;","names":["basePath"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if ((from && typeof from === "object") || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
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
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
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);
|
|
38
|
+
var localeDetector_exports = {};
|
|
39
|
+
__export(localeDetector_exports, {
|
|
40
|
+
localeDetector: () => localeDetector,
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(localeDetector_exports);
|
|
43
|
+
var import_intl_localematcher = require("@formatjs/intl-localematcher");
|
|
44
|
+
var import_client = require("@intlayer/config/client");
|
|
45
|
+
var import_negotiator = __toESM(require("negotiator"));
|
|
46
|
+
const { locales, defaultLocale } = (0, import_client.getConfiguration)()
|
|
47
|
+
.internationalization;
|
|
48
|
+
const localeDetector = (request) => {
|
|
49
|
+
const negotiatorHeaders = {};
|
|
50
|
+
request.headers.forEach((value, key) => (negotiatorHeaders[key] = value));
|
|
51
|
+
const languages = new import_negotiator.default({
|
|
52
|
+
headers: negotiatorHeaders,
|
|
53
|
+
}).languages();
|
|
54
|
+
try {
|
|
55
|
+
return (0, import_intl_localematcher.match)(
|
|
56
|
+
languages,
|
|
57
|
+
locales,
|
|
58
|
+
defaultLocale
|
|
59
|
+
);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.warn(
|
|
62
|
+
`No valid locales in accept-language header: ${languages.join(", ")}`
|
|
63
|
+
);
|
|
64
|
+
console.warn(`Reverting to using defaultLocale: ${defaultLocale}`);
|
|
65
|
+
return defaultLocale;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 &&
|
|
70
|
+
(module.exports = {
|
|
71
|
+
localeDetector,
|
|
72
|
+
});
|
|
73
|
+
//# sourceMappingURL=localeDetector.cjs.map
|