next-intlayer 3.5.2 → 3.5.3
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/useLocale.cjs +9 -58
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +10 -59
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts +5 -5
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/package.json +16 -16
|
@@ -21,76 +21,27 @@ __export(useLocale_exports, {
|
|
|
21
21
|
useLocale: () => useLocale
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(useLocale_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_core = require("@intlayer/core");
|
|
25
25
|
var import_navigation = require("next/navigation.js");
|
|
26
26
|
var import_react = require("react");
|
|
27
27
|
var import_react_intlayer = require("react-intlayer");
|
|
28
28
|
const useLocale = () => {
|
|
29
|
-
const {
|
|
30
|
-
/**
|
|
31
|
-
* Prefix default prefix the default locale to the path as other locales.
|
|
32
|
-
*
|
|
33
|
-
* Example with prefixDefault = true and defaultLocale = 'en':
|
|
34
|
-
* path = /en/dashboard or /fr/dashboard
|
|
35
|
-
*
|
|
36
|
-
* Example with prefixDefault = false and defaultLocale = 'en':
|
|
37
|
-
* path = /dashboard or /fr/dashboard
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
prefixDefault
|
|
41
|
-
} = (0, import_client.getConfiguration)().middleware;
|
|
42
|
-
const { setLocaleCookie } = (0, import_react_intlayer.useLocaleCookie)();
|
|
43
|
-
const reactLocaleHook = (0, import_react_intlayer.useLocaleBase)();
|
|
44
29
|
const { push, refresh } = (0, import_navigation.useRouter)();
|
|
45
30
|
const pathname = (0, import_navigation.usePathname)();
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
availableLocales,
|
|
49
|
-
locale: currentLocale,
|
|
50
|
-
setLocale: setLocaleState
|
|
51
|
-
} = reactLocaleHook;
|
|
52
|
-
const getPathWithoutLocale = () => {
|
|
53
|
-
if (
|
|
54
|
-
// If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path
|
|
55
|
-
!prefixDefault && currentLocale.toString() === defaultLocale.toString()
|
|
56
|
-
) {
|
|
57
|
-
return pathname;
|
|
58
|
-
}
|
|
59
|
-
const slicedPath = pathname.slice(`/${currentLocale}`.length);
|
|
60
|
-
if (slicedPath) {
|
|
61
|
-
return slicedPath;
|
|
62
|
-
}
|
|
63
|
-
return "/";
|
|
64
|
-
};
|
|
65
|
-
const pathWithoutLocale = getPathWithoutLocale();
|
|
66
|
-
const setLocale = (0, import_react.useCallback)(
|
|
31
|
+
const pathWithoutLocale = (0, import_core.getPathWithoutLocale)(pathname);
|
|
32
|
+
const redirectionFunction = (0, import_react.useCallback)(
|
|
67
33
|
(locale) => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
setLocaleCookie(locale);
|
|
73
|
-
setLocaleState(locale);
|
|
74
|
-
if (!prefixDefault && locale.toString() === defaultLocale.toString()) {
|
|
75
|
-
push(pathWithoutLocale);
|
|
76
|
-
} else {
|
|
77
|
-
push(`/${locale}${pathWithoutLocale}`);
|
|
78
|
-
}
|
|
34
|
+
const pathWithLocale = (0, import_core.getLocalizedUrl)(location.pathname, locale);
|
|
35
|
+
push(pathWithLocale);
|
|
79
36
|
return refresh();
|
|
80
37
|
},
|
|
81
|
-
[
|
|
82
|
-
currentLocale,
|
|
83
|
-
availableLocales,
|
|
84
|
-
setLocaleCookie,
|
|
85
|
-
setLocaleState,
|
|
86
|
-
prefixDefault,
|
|
87
|
-
defaultLocale,
|
|
88
|
-
pathWithoutLocale
|
|
89
|
-
]
|
|
38
|
+
[refresh]
|
|
90
39
|
);
|
|
40
|
+
const reactLocaleHook = (0, import_react_intlayer.useLocale)({
|
|
41
|
+
onLocaleChange: redirectionFunction
|
|
42
|
+
});
|
|
91
43
|
return {
|
|
92
44
|
...reactLocaleHook,
|
|
93
|
-
setLocale,
|
|
94
45
|
pathWithoutLocale
|
|
95
46
|
};
|
|
96
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocale = () => {\n const { push, refresh } = useRouter();\n const pathname = usePathname();\n const pathWithoutLocale = getPathWithoutLocale(pathname);\n\n const redirectionFunction = useCallback(\n (locale: Locales) => {\n const pathWithLocale = getLocalizedUrl(location.pathname, locale);\n\n push(pathWithLocale);\n\n return refresh();\n },\n [refresh]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAsD;AACtD,wBAAuC;AACvC,mBAA4B;AAC5B,4BAA4C;AAErC,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,MAAM,QAAQ,QAAI,6BAAU;AACpC,QAAM,eAAW,+BAAY;AAC7B,QAAM,wBAAoB,kCAAqB,QAAQ;AAEvD,QAAM,0BAAsB;AAAA,IAC1B,CAAC,WAAoB;AACnB,YAAM,qBAAiB,6BAAgB,SAAS,UAAU,MAAM;AAEhE,WAAK,cAAc;AAEnB,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,sBAAkB,sBAAAA,WAAe;AAAA,IACrC,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":["useLocaleReact"]}
|
|
@@ -1,73 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core";
|
|
2
2
|
import { usePathname, useRouter } from "next/navigation.js";
|
|
3
3
|
import { useCallback } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { useLocale as useLocaleReact } from "react-intlayer";
|
|
5
5
|
const useLocale = () => {
|
|
6
|
-
const {
|
|
7
|
-
/**
|
|
8
|
-
* Prefix default prefix the default locale to the path as other locales.
|
|
9
|
-
*
|
|
10
|
-
* Example with prefixDefault = true and defaultLocale = 'en':
|
|
11
|
-
* path = /en/dashboard or /fr/dashboard
|
|
12
|
-
*
|
|
13
|
-
* Example with prefixDefault = false and defaultLocale = 'en':
|
|
14
|
-
* path = /dashboard or /fr/dashboard
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
prefixDefault
|
|
18
|
-
} = getConfiguration().middleware;
|
|
19
|
-
const { setLocaleCookie } = useLocaleCookie();
|
|
20
|
-
const reactLocaleHook = useLocaleBase();
|
|
21
6
|
const { push, refresh } = useRouter();
|
|
22
7
|
const pathname = usePathname();
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
availableLocales,
|
|
26
|
-
locale: currentLocale,
|
|
27
|
-
setLocale: setLocaleState
|
|
28
|
-
} = reactLocaleHook;
|
|
29
|
-
const getPathWithoutLocale = () => {
|
|
30
|
-
if (
|
|
31
|
-
// If the locale is the default one and the prefixDefault is false, we don't need to add the locale to the path
|
|
32
|
-
!prefixDefault && currentLocale.toString() === defaultLocale.toString()
|
|
33
|
-
) {
|
|
34
|
-
return pathname;
|
|
35
|
-
}
|
|
36
|
-
const slicedPath = pathname.slice(`/${currentLocale}`.length);
|
|
37
|
-
if (slicedPath) {
|
|
38
|
-
return slicedPath;
|
|
39
|
-
}
|
|
40
|
-
return "/";
|
|
41
|
-
};
|
|
42
|
-
const pathWithoutLocale = getPathWithoutLocale();
|
|
43
|
-
const setLocale = useCallback(
|
|
8
|
+
const pathWithoutLocale = getPathWithoutLocale(pathname);
|
|
9
|
+
const redirectionFunction = useCallback(
|
|
44
10
|
(locale) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
setLocaleCookie(locale);
|
|
50
|
-
setLocaleState(locale);
|
|
51
|
-
if (!prefixDefault && locale.toString() === defaultLocale.toString()) {
|
|
52
|
-
push(pathWithoutLocale);
|
|
53
|
-
} else {
|
|
54
|
-
push(`/${locale}${pathWithoutLocale}`);
|
|
55
|
-
}
|
|
11
|
+
const pathWithLocale = getLocalizedUrl(location.pathname, locale);
|
|
12
|
+
push(pathWithLocale);
|
|
56
13
|
return refresh();
|
|
57
14
|
},
|
|
58
|
-
[
|
|
59
|
-
currentLocale,
|
|
60
|
-
availableLocales,
|
|
61
|
-
setLocaleCookie,
|
|
62
|
-
setLocaleState,
|
|
63
|
-
prefixDefault,
|
|
64
|
-
defaultLocale,
|
|
65
|
-
pathWithoutLocale
|
|
66
|
-
]
|
|
15
|
+
[refresh]
|
|
67
16
|
);
|
|
17
|
+
const reactLocaleHook = useLocaleReact({
|
|
18
|
+
onLocaleChange: redirectionFunction
|
|
19
|
+
});
|
|
68
20
|
return {
|
|
69
21
|
...reactLocaleHook,
|
|
70
|
-
setLocale,
|
|
71
22
|
pathWithoutLocale
|
|
72
23
|
};
|
|
73
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales
|
|
1
|
+
{"version":3,"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { type Locales } from '@intlayer/config/client';\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocale = () => {\n const { push, refresh } = useRouter();\n const pathname = usePathname();\n const pathWithoutLocale = getPathWithoutLocale(pathname);\n\n const redirectionFunction = useCallback(\n (locale: Locales) => {\n const pathWithLocale = getLocalizedUrl(location.pathname, locale);\n\n push(pathWithLocale);\n\n return refresh();\n },\n [refresh]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"AACA,SAAS,iBAAiB,4BAA4B;AACtD,SAAS,aAAa,iBAAiB;AACvC,SAAS,mBAAmB;AAC5B,SAAS,aAAa,sBAAsB;AAErC,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,MAAM,QAAQ,IAAI,UAAU;AACpC,QAAM,WAAW,YAAY;AAC7B,QAAM,oBAAoB,qBAAqB,QAAQ;AAEvD,QAAM,sBAAsB;AAAA,IAC1B,CAAC,WAAoB;AACnB,YAAM,iBAAiB,gBAAgB,SAAS,UAAU,MAAM;AAEhE,WAAK,cAAc;AAEnB,aAAO,QAAQ;AAAA,IACjB;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,QAAM,kBAAkB,eAAe;AAAA,IACrC,gBAAgB;AAAA,EAClB,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Locales } from '@intlayer/config/client';
|
|
2
2
|
export declare const useLocale: () => {
|
|
3
|
-
setLocale: (locale: Locales) => void;
|
|
4
3
|
pathWithoutLocale: string;
|
|
5
|
-
locale:
|
|
6
|
-
defaultLocale:
|
|
7
|
-
availableLocales:
|
|
8
|
-
localeList:
|
|
4
|
+
locale: Locales;
|
|
5
|
+
defaultLocale: Locales;
|
|
6
|
+
availableLocales: Locales[];
|
|
7
|
+
localeList: Locales[];
|
|
8
|
+
setLocale: (locale: Locales) => void;
|
|
9
9
|
};
|
|
10
10
|
//# sourceMappingURL=useLocale.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","sourceRoot":"","sources":["../../../src/client/useLocale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMvD,eAAO,MAAM,SAAS;;;;;;;CAwBrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Internationalisation tool for Next.js applications. Declare your multilingual contant in the same lever than your component. Powered by TypeScript, declaration files.",
|
|
6
6
|
"keywords": [
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
],
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"webpack": "^5.96.1",
|
|
75
|
-
"@intlayer/
|
|
76
|
-
"@intlayer/
|
|
77
|
-
"
|
|
78
|
-
"@intlayer/
|
|
79
|
-
"
|
|
80
|
-
"@intlayer/webpack": "^3.5.
|
|
75
|
+
"@intlayer/chokidar": "^3.5.3",
|
|
76
|
+
"@intlayer/config": "^3.5.3",
|
|
77
|
+
"@intlayer/core": "^3.5.3",
|
|
78
|
+
"@intlayer/dictionaries-entry": "^3.5.3",
|
|
79
|
+
"react-intlayer": "^3.5.3",
|
|
80
|
+
"@intlayer/webpack": "^3.5.3"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@types/node": "^22.10.1",
|
|
@@ -89,21 +89,21 @@
|
|
|
89
89
|
"tsc-alias": "^1.8.10",
|
|
90
90
|
"tsup": "^8.3.5",
|
|
91
91
|
"typescript": "^5.7.2",
|
|
92
|
-
"@utils/ts-config": "^1.0.4",
|
|
93
92
|
"@utils/eslint-config": "^1.0.4",
|
|
94
|
-
"@utils/
|
|
93
|
+
"@utils/ts-config": "^1.0.4",
|
|
95
94
|
"@utils/ts-config-types": "^1.0.4",
|
|
96
|
-
"
|
|
95
|
+
"@utils/tsup-config": "^1.0.4",
|
|
96
|
+
"intlayer": "^3.5.3"
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"next": ">=14.0.0 <16.0.0",
|
|
100
100
|
"react": ">=16.0.0 <19.0.0",
|
|
101
|
-
"@intlayer/config": "^3.5.
|
|
102
|
-
"@intlayer/core": "^3.5.
|
|
103
|
-
"intlayer": "^3.5.
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
101
|
+
"@intlayer/config": "^3.5.3",
|
|
102
|
+
"@intlayer/core": "^3.5.3",
|
|
103
|
+
"@intlayer/dictionaries-entry": "^3.5.3",
|
|
104
|
+
"react-intlayer": "^3.5.3",
|
|
105
|
+
"@intlayer/webpack": "^3.5.3",
|
|
106
|
+
"intlayer": "^3.5.3"
|
|
107
107
|
},
|
|
108
108
|
"engines": {
|
|
109
109
|
"node": ">=14.18"
|