next-intl 2.17.5 → 2.18.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.
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
type IntlNavigateOptions = {
|
|
2
|
+
locale?: string;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
3
6
|
* will automatically localize the `href` parameters it receives.
|
|
@@ -12,13 +15,17 @@
|
|
|
12
15
|
*
|
|
13
16
|
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
14
17
|
* router.push('/about');
|
|
18
|
+
*
|
|
19
|
+
* // Optionally, you can switch the locale by passing the second argument
|
|
20
|
+
* router.push('/about', {locale: 'de'});
|
|
15
21
|
* ```
|
|
16
22
|
*/
|
|
17
23
|
export default function useRouter(): {
|
|
18
|
-
push(href: string, options?: import("next/dist/shared/lib/app-router-context").NavigateOptions | undefined): void;
|
|
19
|
-
replace(href: string, options?: import("next/dist/shared/lib/app-router-context").NavigateOptions | undefined): void;
|
|
20
|
-
prefetch(href: string, options?: import("next/dist/shared/lib/app-router-context").PrefetchOptions | undefined): void;
|
|
24
|
+
push(href: string, options?: (import("next/dist/shared/lib/app-router-context").NavigateOptions & IntlNavigateOptions) | undefined): void;
|
|
25
|
+
replace(href: string, options?: (import("next/dist/shared/lib/app-router-context").NavigateOptions & IntlNavigateOptions) | undefined): void;
|
|
26
|
+
prefetch(href: string, options?: (import("next/dist/shared/lib/app-router-context").PrefetchOptions & IntlNavigateOptions) | undefined): void;
|
|
21
27
|
back(): void;
|
|
22
28
|
forward(): void;
|
|
23
29
|
refresh(): void;
|
|
24
30
|
};
|
|
31
|
+
export {};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
type IntlNavigateOptions = {
|
|
2
|
+
locale?: string;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
3
6
|
* will automatically localize the `href` parameters it receives.
|
|
@@ -12,13 +15,17 @@
|
|
|
12
15
|
*
|
|
13
16
|
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
14
17
|
* router.push('/about');
|
|
18
|
+
*
|
|
19
|
+
* // Optionally, you can switch the locale by passing the second argument
|
|
20
|
+
* router.push('/about', {locale: 'de'});
|
|
15
21
|
* ```
|
|
16
22
|
*/
|
|
17
23
|
export default function useRouter(): {
|
|
18
|
-
push(href: string, options?: import("next/dist/shared/lib/app-router-context").NavigateOptions | undefined): void;
|
|
19
|
-
replace(href: string, options?: import("next/dist/shared/lib/app-router-context").NavigateOptions | undefined): void;
|
|
20
|
-
prefetch(href: string, options?: import("next/dist/shared/lib/app-router-context").PrefetchOptions | undefined): void;
|
|
24
|
+
push(href: string, options?: (import("next/dist/shared/lib/app-router-context").NavigateOptions & IntlNavigateOptions) | undefined): void;
|
|
25
|
+
replace(href: string, options?: (import("next/dist/shared/lib/app-router-context").NavigateOptions & IntlNavigateOptions) | undefined): void;
|
|
26
|
+
prefetch(href: string, options?: (import("next/dist/shared/lib/app-router-context").PrefetchOptions & IntlNavigateOptions) | undefined): void;
|
|
21
27
|
back(): void;
|
|
22
28
|
forward(): void;
|
|
23
29
|
refresh(): void;
|
|
24
30
|
};
|
|
31
|
+
export {};
|
|
@@ -16,25 +16,44 @@ import useClientLocale from './useClientLocale';
|
|
|
16
16
|
*
|
|
17
17
|
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
18
18
|
* router.push('/about');
|
|
19
|
+
*
|
|
20
|
+
* // Optionally, you can switch the locale by passing the second argument
|
|
21
|
+
* router.push('/about', {locale: 'de'});
|
|
19
22
|
* ```
|
|
20
23
|
*/
|
|
21
24
|
export default function useRouter() {
|
|
22
25
|
const router = useNextRouter();
|
|
23
26
|
const locale = useClientLocale();
|
|
24
27
|
return useMemo(() => {
|
|
25
|
-
function localize(href) {
|
|
26
|
-
return localizeHref(href, locale, locale, window.location.pathname);
|
|
28
|
+
function localize(href, nextLocale) {
|
|
29
|
+
return localizeHref(href, nextLocale || locale, locale, window.location.pathname);
|
|
27
30
|
}
|
|
28
31
|
return {
|
|
29
32
|
...router,
|
|
30
|
-
push(
|
|
31
|
-
|
|
33
|
+
push(href, options) {
|
|
34
|
+
const { locale: nextLocale, ...rest } = options || {};
|
|
35
|
+
const args = [localize(href, nextLocale)];
|
|
36
|
+
if (Object.keys(rest).length > 0) {
|
|
37
|
+
args.push(rest);
|
|
38
|
+
}
|
|
39
|
+
return router.push(...args);
|
|
32
40
|
},
|
|
33
|
-
replace(
|
|
34
|
-
|
|
41
|
+
replace(href, options) {
|
|
42
|
+
const { locale: nextLocale, ...rest } = options || {};
|
|
43
|
+
const args = [localize(href, nextLocale)];
|
|
44
|
+
if (Object.keys(rest).length > 0) {
|
|
45
|
+
args.push(rest);
|
|
46
|
+
}
|
|
47
|
+
return router.replace(...args);
|
|
35
48
|
},
|
|
36
|
-
prefetch(
|
|
37
|
-
|
|
49
|
+
prefetch(href, options) {
|
|
50
|
+
const { locale: nextLocale, ...rest } = options || {};
|
|
51
|
+
const args = [localize(href, nextLocale)];
|
|
52
|
+
if (Object.keys(rest).length > 0) {
|
|
53
|
+
// @ts-expect-error TypeScript thinks `rest` can be an empty object
|
|
54
|
+
args.push(rest);
|
|
55
|
+
}
|
|
56
|
+
return router.prefetch(...args);
|
|
38
57
|
}
|
|
39
58
|
};
|
|
40
59
|
}, [locale, router]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouter.js","sourceRoot":"","sources":["../../../src/client/useRouter.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,IAAI,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,eAAe,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useR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Q,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;gBACjC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;oBAChC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACjB;gBACD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;YACjC,CAAC;YAED,QAAQ,CACN,IAAY,EACZ,OAAqE;gBAErE,MAAM,EAAC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAC,GAAG,OAAO,IAAI,EAAE,CAAC;gBACpD,MAAM,IAAI,GAGN,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;gBACjC,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;oBAChC,mEAAmE;oBACnE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACjB;gBACD,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;YAClC,CAAC;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.18.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "A minimal, but complete solution for internationalization in Next.js apps.",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
69
69
|
"negotiator": "^0.6.3",
|
|
70
|
-
"use-intl": "^2.
|
|
70
|
+
"use-intl": "^2.18.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"react": "^18.2.0",
|
|
88
88
|
"react-dom": "^18.2.0",
|
|
89
89
|
"size-limit": "^8.2.6",
|
|
90
|
-
"typescript": "^
|
|
90
|
+
"typescript": "^5.0.0",
|
|
91
91
|
"vitest": "^0.32.2"
|
|
92
92
|
},
|
|
93
93
|
"size-limit": [
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"engines": {
|
|
104
104
|
"node": ">=10"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "023d23a7a71f5594d8a457c09ea988b56b248239"
|
|
107
107
|
}
|
package/src/client/useRouter.tsx
CHANGED
|
@@ -3,6 +3,10 @@ import {useMemo} from 'react';
|
|
|
3
3
|
import {localizeHref} from '../shared/utils';
|
|
4
4
|
import useClientLocale from './useClientLocale';
|
|
5
5
|
|
|
6
|
+
type IntlNavigateOptions = {
|
|
7
|
+
locale?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
8
12
|
* will automatically localize the `href` parameters it receives.
|
|
@@ -17,6 +21,9 @@ import useClientLocale from './useClientLocale';
|
|
|
17
21
|
*
|
|
18
22
|
* // When the user is on `/en`, the router will navigate to `/en/about`
|
|
19
23
|
* router.push('/about');
|
|
24
|
+
*
|
|
25
|
+
* // Optionally, you can switch the locale by passing the second argument
|
|
26
|
+
* router.push('/about', {locale: 'de'});
|
|
20
27
|
* ```
|
|
21
28
|
*/
|
|
22
29
|
export default function useRouter() {
|
|
@@ -24,20 +31,61 @@ export default function useRouter() {
|
|
|
24
31
|
const locale = useClientLocale();
|
|
25
32
|
|
|
26
33
|
return useMemo(() => {
|
|
27
|
-
function localize(href: string) {
|
|
28
|
-
return localizeHref(
|
|
34
|
+
function localize(href: string, nextLocale?: string) {
|
|
35
|
+
return localizeHref(
|
|
36
|
+
href,
|
|
37
|
+
nextLocale || locale,
|
|
38
|
+
locale,
|
|
39
|
+
window.location.pathname
|
|
40
|
+
);
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
return {
|
|
32
44
|
...router,
|
|
33
|
-
push(
|
|
34
|
-
|
|
45
|
+
push(
|
|
46
|
+
href: string,
|
|
47
|
+
options?: Parameters<typeof router.push>[1] & IntlNavigateOptions
|
|
48
|
+
) {
|
|
49
|
+
const {locale: nextLocale, ...rest} = options || {};
|
|
50
|
+
const args: [
|
|
51
|
+
href: string,
|
|
52
|
+
options?: Parameters<typeof router.push>[1]
|
|
53
|
+
] = [localize(href, nextLocale)];
|
|
54
|
+
if (Object.keys(rest).length > 0) {
|
|
55
|
+
args.push(rest);
|
|
56
|
+
}
|
|
57
|
+
return router.push(...args);
|
|
35
58
|
},
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
|
|
60
|
+
replace(
|
|
61
|
+
href: string,
|
|
62
|
+
options?: Parameters<typeof router.replace>[1] & IntlNavigateOptions
|
|
63
|
+
) {
|
|
64
|
+
const {locale: nextLocale, ...rest} = options || {};
|
|
65
|
+
const args: [
|
|
66
|
+
href: string,
|
|
67
|
+
options?: Parameters<typeof router.replace>[1]
|
|
68
|
+
] = [localize(href, nextLocale)];
|
|
69
|
+
if (Object.keys(rest).length > 0) {
|
|
70
|
+
args.push(rest);
|
|
71
|
+
}
|
|
72
|
+
return router.replace(...args);
|
|
38
73
|
},
|
|
39
|
-
|
|
40
|
-
|
|
74
|
+
|
|
75
|
+
prefetch(
|
|
76
|
+
href: string,
|
|
77
|
+
options?: Parameters<typeof router.prefetch>[1] & IntlNavigateOptions
|
|
78
|
+
) {
|
|
79
|
+
const {locale: nextLocale, ...rest} = options || {};
|
|
80
|
+
const args: [
|
|
81
|
+
href: string,
|
|
82
|
+
options?: Parameters<typeof router.prefetch>[1]
|
|
83
|
+
] = [localize(href, nextLocale)];
|
|
84
|
+
if (Object.keys(rest).length > 0) {
|
|
85
|
+
// @ts-expect-error TypeScript thinks `rest` can be an empty object
|
|
86
|
+
args.push(rest);
|
|
87
|
+
}
|
|
88
|
+
return router.prefetch(...args);
|
|
41
89
|
}
|
|
42
90
|
};
|
|
43
91
|
}, [locale, router]);
|