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.
- package/dist/cjs/client/index.cjs +16 -22
- package/dist/cjs/client/index.d.ts +3 -10
- package/dist/cjs/client/useLocale.cjs +13 -20
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocale.d.ts +7 -7
- package/dist/cjs/generateStaticParams.cjs +8 -13
- package/dist/cjs/generateStaticParams.d.ts +2 -2
- package/dist/cjs/index.cjs +18 -24
- package/dist/cjs/index.d.ts +8 -15
- package/dist/cjs/middleware/index.cjs +9 -21
- package/dist/cjs/middleware/index.d.ts +2 -2
- package/dist/cjs/middleware/intlayerMiddleware.cjs +28 -86
- package/dist/cjs/middleware/intlayerMiddleware.d.ts +1 -1
- package/dist/cjs/middleware/localeDetector.cjs +20 -37
- package/dist/cjs/middleware/localeDetector.d.ts +2 -2
- package/dist/cjs/server/index.cjs +15 -20
- package/dist/cjs/server/index.d.ts +3 -10
- package/dist/cjs/server/withIntlayer.cjs +36 -48
- package/dist/cjs/server/withIntlayer.d.ts +3 -5
- package/dist/cjs/types/NextPage.cjs +4 -8
- package/dist/cjs/types/NextPage.d.ts +6 -6
- package/dist/cjs/types/index.cjs +4 -8
- package/dist/cjs/types/index.d.ts +4 -4
- package/dist/esm/client/index.d.mts +3 -10
- package/dist/esm/client/index.mjs +4 -4
- package/dist/esm/client/useLocale.d.mts +7 -7
- package/dist/esm/client/useLocale.mjs +12 -10
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/generateStaticParams.d.mts +2 -2
- package/dist/esm/generateStaticParams.mjs +4 -2
- package/dist/esm/index.d.mts +8 -15
- package/dist/esm/index.mjs +5 -5
- package/dist/esm/middleware/index.d.mts +2 -2
- package/dist/esm/middleware/index.mjs +2 -2
- package/dist/esm/middleware/intlayerMiddleware.d.mts +1 -1
- package/dist/esm/middleware/intlayerMiddleware.mjs +21 -66
- package/dist/esm/middleware/localeDetector.d.mts +2 -2
- package/dist/esm/middleware/localeDetector.mjs +5 -3
- package/dist/esm/server/index.d.mts +3 -10
- package/dist/esm/server/index.mjs +4 -4
- package/dist/esm/server/withIntlayer.d.mts +3 -5
- package/dist/esm/server/withIntlayer.mjs +32 -32
- package/dist/esm/types/NextPage.d.mts +6 -6
- package/dist/esm/types/NextPage.mjs +1 -1
- package/dist/esm/types/index.d.mts +4 -4
- package/dist/esm/types/index.mjs +1 -1
- package/package.json +9 -9
- package/src/client/useLocale.ts +6 -4
|
@@ -8,18 +8,14 @@ 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 (
|
|
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 server_exports = {};
|
|
24
20
|
__export(server_exports, {
|
|
25
21
|
LocaleServerContext: () => import_server.LocaleServerContext,
|
|
@@ -28,20 +24,19 @@ __export(server_exports, {
|
|
|
28
24
|
locale: () => import_server.locale,
|
|
29
25
|
useIntlayer: () => import_server.useIntlayer,
|
|
30
26
|
useTraduction: () => import_server.useTraduction,
|
|
31
|
-
withIntlayer: () => import_withIntlayer.withIntlayer
|
|
27
|
+
withIntlayer: () => import_withIntlayer.withIntlayer
|
|
32
28
|
});
|
|
33
29
|
module.exports = __toCommonJS(server_exports);
|
|
34
30
|
var import_server = require("react-intlayer/server");
|
|
35
|
-
var import_withIntlayer = require(
|
|
31
|
+
var import_withIntlayer = require('./withIntlayer.cjs');
|
|
36
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
-
0 &&
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=index.cjs.map
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
LocaleServerContext,
|
|
35
|
+
LocaleServerContextProvider,
|
|
36
|
+
getLocaleContent,
|
|
37
|
+
locale,
|
|
38
|
+
useIntlayer,
|
|
39
|
+
useTraduction,
|
|
40
|
+
withIntlayer
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
getLocaleContent,
|
|
5
|
-
locale,
|
|
6
|
-
useIntlayer,
|
|
7
|
-
useTraduction,
|
|
8
|
-
} from "react-intlayer/server";
|
|
9
|
-
export { withIntlayer } from "./withIntlayer.js";
|
|
10
|
-
import "next";
|
|
1
|
+
export { LocaleServerContext, LocaleServerContextProvider, getLocaleContent, locale, useIntlayer, useTraduction } from 'react-intlayer/server';
|
|
2
|
+
export { withIntlayer } from './withIntlayer.js';
|
|
3
|
+
import 'next';
|
|
@@ -8,69 +8,57 @@ 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 (
|
|
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 withIntlayer_exports = {};
|
|
24
20
|
__export(withIntlayer_exports, {
|
|
25
|
-
withIntlayer: () => withIntlayer
|
|
21
|
+
withIntlayer: () => withIntlayer
|
|
26
22
|
});
|
|
27
23
|
module.exports = __toCommonJS(withIntlayer_exports);
|
|
28
24
|
var import_path = require("path");
|
|
29
25
|
var import_config = require("@intlayer/config");
|
|
30
26
|
const intlayerConfig = (0, import_config.getConfiguration)({
|
|
31
|
-
verbose: true
|
|
27
|
+
verbose: true
|
|
32
28
|
});
|
|
33
29
|
const env = (0, import_config.formatEnvVariable)("NEXT_PUBLIC_INTLAYER_");
|
|
34
30
|
const { mainDir, baseDir } = intlayerConfig.content;
|
|
35
31
|
const mergeEnvVariable = (nextEnv = {}) => Object.assign({}, nextEnv, env);
|
|
36
|
-
const mergeStats = (nextStats = {}) =>
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
const mergeStats = (nextStats = {}) => Object.assign({}, nextStats, {
|
|
33
|
+
warnings: false
|
|
34
|
+
});
|
|
35
|
+
const withIntlayer = (_pluginOptions = {}) => (nextConfig = {}) => {
|
|
36
|
+
if (typeof nextConfig !== "object")
|
|
37
|
+
nextConfig = {};
|
|
38
|
+
return Object.assign({}, nextConfig, {
|
|
39
|
+
env: mergeEnvVariable(nextConfig.env),
|
|
40
|
+
stats: mergeStats(nextConfig.stats),
|
|
41
|
+
webpack: (config) => {
|
|
42
|
+
const dictionariesPath = (0, import_path.join)(mainDir, "dictionaries.cjs");
|
|
43
|
+
const relativeDictionariesPath = (0, import_path.relative)(baseDir, dictionariesPath);
|
|
44
|
+
config.externals.push({
|
|
45
|
+
esbuild: "esbuild",
|
|
46
|
+
module: "module",
|
|
47
|
+
fs: "fs"
|
|
48
|
+
});
|
|
49
|
+
config.resolve.alias["@intlayer/dictionaries-entry"] = (0, import_path.resolve)(
|
|
50
|
+
relativeDictionariesPath
|
|
51
|
+
);
|
|
52
|
+
config.module.rules.push({
|
|
53
|
+
test: /\.node$/,
|
|
54
|
+
loader: "node-loader"
|
|
55
|
+
});
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
39
58
|
});
|
|
40
|
-
|
|
41
|
-
(_pluginOptions = {}) =>
|
|
42
|
-
(nextConfig = {}) => {
|
|
43
|
-
if (typeof nextConfig !== "object") nextConfig = {};
|
|
44
|
-
return Object.assign({}, nextConfig, {
|
|
45
|
-
env: mergeEnvVariable(nextConfig.env),
|
|
46
|
-
stats: mergeStats(nextConfig.stats),
|
|
47
|
-
webpack: (config) => {
|
|
48
|
-
const dictionariesPath = (0, import_path.join)(
|
|
49
|
-
mainDir,
|
|
50
|
-
"dictionaries.cjs"
|
|
51
|
-
);
|
|
52
|
-
const relativeDictionariesPath = (0, import_path.relative)(
|
|
53
|
-
baseDir,
|
|
54
|
-
dictionariesPath
|
|
55
|
-
);
|
|
56
|
-
config.externals.push({
|
|
57
|
-
esbuild: "esbuild",
|
|
58
|
-
module: "module",
|
|
59
|
-
fs: "fs",
|
|
60
|
-
});
|
|
61
|
-
config.resolve.alias["@intlayer/dictionaries-entry"] = (0,
|
|
62
|
-
import_path.resolve)(relativeDictionariesPath);
|
|
63
|
-
config.module.rules.push({
|
|
64
|
-
test: /\.node$/,
|
|
65
|
-
loader: "node-loader",
|
|
66
|
-
});
|
|
67
|
-
return config;
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
};
|
|
59
|
+
};
|
|
71
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
-
0 &&
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//# sourceMappingURL=withIntlayer.cjs.map
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
withIntlayer
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=withIntlayer.cjs.map
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { NextConfig } from
|
|
1
|
+
import 'react-intlayer/server';
|
|
2
|
+
import { NextConfig } from 'next';
|
|
3
3
|
|
|
4
4
|
type PluginOptions = {};
|
|
5
|
-
declare const withIntlayer: (
|
|
6
|
-
_pluginOptions?: PluginOptions
|
|
7
|
-
) => (nextConfig?: Partial<NextConfig>) => Partial<NextConfig>;
|
|
5
|
+
declare const withIntlayer: (_pluginOptions?: PluginOptions) => (nextConfig?: Partial<NextConfig>) => Partial<NextConfig>;
|
|
8
6
|
|
|
9
7
|
export { withIntlayer };
|
|
@@ -4,18 +4,14 @@ 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 (
|
|
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 __toCommonJS = (mod) =>
|
|
18
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
15
|
var NextPage_exports = {};
|
|
20
16
|
module.exports = __toCommonJS(NextPage_exports);
|
|
21
|
-
//# sourceMappingURL=NextPage.cjs.map
|
|
17
|
+
//# sourceMappingURL=NextPage.cjs.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Locales } from
|
|
2
|
-
import { NextPage } from
|
|
3
|
-
import { PropsWithChildren } from
|
|
1
|
+
import { Locales } from 'intlayer';
|
|
2
|
+
import { NextPage } from 'next';
|
|
3
|
+
import { PropsWithChildren } from 'react';
|
|
4
4
|
|
|
5
5
|
type LocalParams = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
params: {
|
|
7
|
+
locale: Locales;
|
|
8
|
+
};
|
|
9
9
|
};
|
|
10
10
|
type NextPageIntlayer = NextPage<LocalParams>;
|
|
11
11
|
type NextLayoutIntlayer = NextPage<PropsWithChildren<LocalParams>>;
|
package/dist/cjs/types/index.cjs
CHANGED
|
@@ -4,18 +4,14 @@ 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 (
|
|
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 __toCommonJS = (mod) =>
|
|
18
|
-
__copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
15
|
var types_exports = {};
|
|
20
16
|
module.exports = __toCommonJS(types_exports);
|
|
21
|
-
//# sourceMappingURL=index.cjs.map
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { LocalParams, NextPageIntlayer } from
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
export { LocalParams, NextPageIntlayer } from './NextPage.js';
|
|
2
|
+
import 'intlayer';
|
|
3
|
+
import 'next';
|
|
4
|
+
import 'react';
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
getTranslation,
|
|
5
|
-
useIntlayer,
|
|
6
|
-
useLocaleCookie,
|
|
7
|
-
useTraduction,
|
|
8
|
-
} from "react-intlayer";
|
|
9
|
-
export { useLocale } from "./useLocale.mjs";
|
|
10
|
-
import "intlayer";
|
|
1
|
+
export { LocaleClientContext, LocaleClientContextProvider, getTranslation, useIntlayer, useLocaleCookie, useTraduction } from 'react-intlayer';
|
|
2
|
+
export { useLocale } from './useLocale.mjs';
|
|
3
|
+
import '@intlayer/config/client';
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
LocaleClientContext,
|
|
5
5
|
useIntlayer,
|
|
6
6
|
useTraduction,
|
|
7
|
-
useLocaleCookie
|
|
7
|
+
useLocaleCookie
|
|
8
8
|
} from "react-intlayer";
|
|
9
|
-
import { useLocale } from
|
|
9
|
+
import { useLocale } from './useLocale.mjs';
|
|
10
10
|
export {
|
|
11
11
|
LocaleClientContext,
|
|
12
12
|
LocaleClientContextProvider,
|
|
@@ -14,6 +14,6 @@ export {
|
|
|
14
14
|
useIntlayer,
|
|
15
15
|
useLocale,
|
|
16
16
|
useLocaleCookie,
|
|
17
|
-
useTraduction
|
|
17
|
+
useTraduction
|
|
18
18
|
};
|
|
19
|
-
//# sourceMappingURL=index.mjs.map
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Locales } from
|
|
1
|
+
import 'react-intlayer';
|
|
2
|
+
import { Locales } from '@intlayer/config/client';
|
|
3
3
|
|
|
4
4
|
declare const useLocale: () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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 };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
intlayerMiddlewareConfiguration
|
|
3
|
+
} from "@intlayer/config/client";
|
|
2
4
|
import { usePathname, useRouter } from "next/navigation.js";
|
|
3
5
|
import { useLocale as useReactLocale, useLocaleCookie } from "react-intlayer";
|
|
4
6
|
const { prefixDefault } = intlayerMiddlewareConfiguration;
|
|
@@ -10,19 +12,17 @@ const useLocale = () => {
|
|
|
10
12
|
const {
|
|
11
13
|
defaultLocale,
|
|
12
14
|
availableLocales,
|
|
13
|
-
locale: currentLocale
|
|
15
|
+
locale: currentLocale
|
|
14
16
|
} = reactLocaleHook;
|
|
15
17
|
const setLocale = (locale) => {
|
|
16
|
-
if (currentLocale === locale)
|
|
18
|
+
if (currentLocale.toString() === locale.toString())
|
|
19
|
+
return;
|
|
17
20
|
if (!availableLocales.includes(locale)) {
|
|
18
21
|
console.error(`Locale ${locale} is not available`);
|
|
19
22
|
return;
|
|
20
23
|
}
|
|
21
24
|
setLocaleCookie(locale);
|
|
22
|
-
const pathWithoutLocale =
|
|
23
|
-
!prefixDefault && currentLocale === defaultLocale
|
|
24
|
-
? pathname
|
|
25
|
-
: pathname.slice(`/${currentLocale}`.length) || "/";
|
|
25
|
+
const pathWithoutLocale = !prefixDefault && currentLocale.toString() === defaultLocale.toString() ? pathname : pathname.slice(`/${currentLocale}`.length) || "/";
|
|
26
26
|
if (!prefixDefault && locale === defaultLocale) {
|
|
27
27
|
return router.push(pathWithoutLocale);
|
|
28
28
|
}
|
|
@@ -30,8 +30,10 @@ const useLocale = () => {
|
|
|
30
30
|
};
|
|
31
31
|
return {
|
|
32
32
|
...reactLocaleHook,
|
|
33
|
-
setLocale
|
|
33
|
+
setLocale
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
export {
|
|
37
|
-
|
|
36
|
+
export {
|
|
37
|
+
useLocale
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { intlayerMiddlewareConfiguration
|
|
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,EAEE;AAAA,OACK;AACP,SAAS,aAAa,iBAAiB;AACvC,SAAS,aAAa,gBAAgB,uBAAuB;AAE7D,MAAM,EAAE,cAAc,IAAI;AAEnB,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,gBAAgB,IAAI,gBAAgB;AAC5C,QAAM,kBAAkB,eAAe;AACvC,QAAM,SAAS,UAAU;AACzB,QAAM,WAAW,YAAY;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":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as _intlayer_config_client from
|
|
1
|
+
import * as _intlayer_config_client from '@intlayer/config/client';
|
|
2
2
|
|
|
3
3
|
declare const generateStaticParams: () => {
|
|
4
|
-
|
|
4
|
+
locale: _intlayer_config_client.Locales;
|
|
5
5
|
}[];
|
|
6
6
|
|
|
7
7
|
export { generateStaticParams };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { intlayerIntlConfiguration } from "@intlayer/config/client";
|
|
2
2
|
const { locales } = intlayerIntlConfiguration;
|
|
3
3
|
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
4
|
-
export {
|
|
5
|
-
|
|
4
|
+
export {
|
|
5
|
+
generateStaticParams
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=generateStaticParams.mjs.map
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export { generateStaticParams } from "./generateStaticParams.mjs";
|
|
10
|
-
export { LocalParams, NextPageIntlayer } from "./types/NextPage.mjs";
|
|
11
|
-
export { useLocale } from "./client/useLocale.mjs";
|
|
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.mjs';
|
|
3
|
+
export { LocalParams, NextPageIntlayer } from './types/NextPage.mjs';
|
|
4
|
+
export { useLocale } from './client/useLocale.mjs';
|
|
5
|
+
import '@intlayer/config/client';
|
|
6
|
+
import 'intlayer';
|
|
7
|
+
import 'next';
|
|
8
|
+
import 'react';
|
package/dist/esm/index.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
LocaleClientContext,
|
|
5
5
|
useIntlayer,
|
|
6
6
|
useTraduction,
|
|
7
|
-
useLocaleCookie
|
|
7
|
+
useLocaleCookie
|
|
8
8
|
} from "react-intlayer";
|
|
9
|
-
import { generateStaticParams } from
|
|
10
|
-
import { useLocale } from
|
|
9
|
+
import { generateStaticParams } from './generateStaticParams.mjs';
|
|
10
|
+
import { useLocale } from './client/useLocale.mjs';
|
|
11
11
|
export {
|
|
12
12
|
LocaleClientContext,
|
|
13
13
|
LocaleClientContextProvider,
|
|
@@ -16,6 +16,6 @@ export {
|
|
|
16
16
|
useIntlayer,
|
|
17
17
|
useLocale,
|
|
18
18
|
useLocaleCookie,
|
|
19
|
-
useTraduction
|
|
19
|
+
useTraduction
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=index.mjs.map
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { intlayerMiddleware } from
|
|
2
|
-
import
|
|
1
|
+
export { intlayerMiddleware } from './intlayerMiddleware.mjs';
|
|
2
|
+
import 'next/server';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
export * from './intlayerMiddleware.mjs';
|
|
2
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { intlayerConfiguration } from "@intlayer/config/client";
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
|
-
import { localeDetector } from
|
|
3
|
+
import { localeDetector } from './localeDetector.mjs';
|
|
4
4
|
const { internationalization, middleware } = intlayerConfiguration;
|
|
5
5
|
const { locales, defaultLocale } = internationalization;
|
|
6
6
|
const {
|
|
@@ -9,7 +9,7 @@ const {
|
|
|
9
9
|
prefixDefault,
|
|
10
10
|
basePath,
|
|
11
11
|
serverSetCookie,
|
|
12
|
-
noPrefix
|
|
12
|
+
noPrefix
|
|
13
13
|
} = middleware;
|
|
14
14
|
const intlayerMiddleware = (request) => {
|
|
15
15
|
const pathname = request.nextUrl.pathname;
|
|
@@ -33,18 +33,14 @@ const intlayerMiddleware = (request) => {
|
|
|
33
33
|
);
|
|
34
34
|
};
|
|
35
35
|
const getCookieLocale = (request) => {
|
|
36
|
-
if (!cookieName)
|
|
36
|
+
if (!cookieName)
|
|
37
|
+
return void 0;
|
|
37
38
|
const cookieValue = request.cookies.get(cookieName)?.value;
|
|
38
39
|
if (cookieValue && locales.includes(cookieValue)) {
|
|
39
40
|
return cookieValue;
|
|
40
41
|
}
|
|
41
42
|
};
|
|
42
|
-
const handleNoPrefix = (
|
|
43
|
-
request,
|
|
44
|
-
cookieLocale,
|
|
45
|
-
pathname,
|
|
46
|
-
basePathTrailingSlash
|
|
47
|
-
) => {
|
|
43
|
+
const handleNoPrefix = (request, cookieLocale, pathname, basePathTrailingSlash) => {
|
|
48
44
|
const locale = cookieLocale ?? defaultLocale;
|
|
49
45
|
const newPath = constructPath(
|
|
50
46
|
locale,
|
|
@@ -54,17 +50,10 @@ const handleNoPrefix = (
|
|
|
54
50
|
);
|
|
55
51
|
return rewriteUrl(request, newPath, locale);
|
|
56
52
|
};
|
|
57
|
-
const getPathLocale = (pathname) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const handlePrefix = (
|
|
62
|
-
request,
|
|
63
|
-
cookieLocale,
|
|
64
|
-
pathLocale,
|
|
65
|
-
pathname,
|
|
66
|
-
basePathTrailingSlash
|
|
67
|
-
) => {
|
|
53
|
+
const getPathLocale = (pathname) => locales.find(
|
|
54
|
+
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
|
|
55
|
+
);
|
|
56
|
+
const handlePrefix = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
|
|
68
57
|
if (!pathLocale) {
|
|
69
58
|
return handleMissingPathLocale(
|
|
70
59
|
request,
|
|
@@ -81,12 +70,7 @@ const handlePrefix = (
|
|
|
81
70
|
basePathTrailingSlash
|
|
82
71
|
);
|
|
83
72
|
};
|
|
84
|
-
const handleMissingPathLocale = (
|
|
85
|
-
request,
|
|
86
|
-
cookieLocale,
|
|
87
|
-
pathname,
|
|
88
|
-
basePathTrailingSlash
|
|
89
|
-
) => {
|
|
73
|
+
const handleMissingPathLocale = (request, cookieLocale, pathname, basePathTrailingSlash) => {
|
|
90
74
|
let locale = cookieLocale ?? localeDetector?.(request) ?? defaultLocale;
|
|
91
75
|
if (!locales.includes(locale)) {
|
|
92
76
|
console.warn(
|
|
@@ -100,22 +84,10 @@ const handleMissingPathLocale = (
|
|
|
100
84
|
basePath,
|
|
101
85
|
basePathTrailingSlash
|
|
102
86
|
);
|
|
103
|
-
return prefixDefault || locale !== defaultLocale
|
|
104
|
-
? redirectUrl(request, newPath)
|
|
105
|
-
: rewriteUrl(request, newPath, locale);
|
|
87
|
+
return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
|
|
106
88
|
};
|
|
107
|
-
const handleExistingPathLocale = (
|
|
108
|
-
|
|
109
|
-
cookieLocale,
|
|
110
|
-
pathLocale,
|
|
111
|
-
pathname,
|
|
112
|
-
basePathTrailingSlash
|
|
113
|
-
) => {
|
|
114
|
-
if (
|
|
115
|
-
cookieLocale &&
|
|
116
|
-
cookieLocale !== pathLocale &&
|
|
117
|
-
serverSetCookie !== "always"
|
|
118
|
-
) {
|
|
89
|
+
const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, basePathTrailingSlash) => {
|
|
90
|
+
if (cookieLocale && cookieLocale !== pathLocale && serverSetCookie !== "always") {
|
|
119
91
|
const newPath = handleCookieLocaleMismatch(
|
|
120
92
|
request,
|
|
121
93
|
pathname,
|
|
@@ -133,14 +105,7 @@ const handleExistingPathLocale = (
|
|
|
133
105
|
basePathTrailingSlash
|
|
134
106
|
);
|
|
135
107
|
};
|
|
136
|
-
const handleCookieLocaleMismatch = (
|
|
137
|
-
request,
|
|
138
|
-
pathname,
|
|
139
|
-
pathLocale,
|
|
140
|
-
cookieLocale,
|
|
141
|
-
basePath2,
|
|
142
|
-
basePathTrailingSlash
|
|
143
|
-
) => {
|
|
108
|
+
const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale, basePath2, basePathTrailingSlash) => {
|
|
144
109
|
const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);
|
|
145
110
|
return constructPath(
|
|
146
111
|
cookieLocale,
|
|
@@ -150,12 +115,7 @@ const handleCookieLocaleMismatch = (
|
|
|
150
115
|
request.nextUrl.search
|
|
151
116
|
);
|
|
152
117
|
};
|
|
153
|
-
const handleDefaultLocaleRedirect = (
|
|
154
|
-
request,
|
|
155
|
-
pathLocale,
|
|
156
|
-
pathname,
|
|
157
|
-
basePathTrailingSlash
|
|
158
|
-
) => {
|
|
118
|
+
const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrailingSlash) => {
|
|
159
119
|
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
160
120
|
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
161
121
|
if (basePathTrailingSlash) {
|
|
@@ -168,13 +128,7 @@ const handleDefaultLocaleRedirect = (
|
|
|
168
128
|
}
|
|
169
129
|
return rewriteUrl(request, pathname, pathLocale);
|
|
170
130
|
};
|
|
171
|
-
const constructPath = (
|
|
172
|
-
locale,
|
|
173
|
-
path,
|
|
174
|
-
basePath2,
|
|
175
|
-
basePathTrailingSlash,
|
|
176
|
-
search
|
|
177
|
-
) => {
|
|
131
|
+
const constructPath = (locale, path, basePath2, basePathTrailingSlash, search) => {
|
|
178
132
|
let newPath = `${locale}${path}`;
|
|
179
133
|
newPath = `${basePath2}${basePathTrailingSlash ? "" : "/"}${newPath}`;
|
|
180
134
|
if (search) {
|
|
@@ -187,7 +141,8 @@ const rewriteUrl = (request, newPath, locale) => {
|
|
|
187
141
|
response.headers.set(headerName, locale);
|
|
188
142
|
return response;
|
|
189
143
|
};
|
|
190
|
-
const redirectUrl = (request, newPath) =>
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
144
|
+
const redirectUrl = (request, newPath) => NextResponse.redirect(new URL(newPath, request.url));
|
|
145
|
+
export {
|
|
146
|
+
intlayerMiddleware
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=intlayerMiddleware.mjs.map
|