next-intl 3.4.4 → 3.5.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/dist/development/middleware/middleware.js +2 -3
- package/dist/development/navigation/react-client/ClientLink.js +0 -1
- package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/development/navigation/react-client/useBaseRouter.js +16 -29
- package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/development/navigation/shared/BaseLink.js +8 -0
- package/dist/development/navigation/shared/syncLocaleCookie.js +29 -0
- package/dist/development/shared/constants.js +4 -0
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/navigation/react-client/ClientLink.js +1 -1
- package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/shared/BaseLink.js +1 -1
- package/dist/esm/navigation/shared/syncLocaleCookie.js +1 -0
- package/dist/esm/shared/constants.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/navigation/react-client/ClientLink.js +1 -1
- package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/shared/BaseLink.js +1 -1
- package/dist/production/navigation/shared/syncLocaleCookie.js +1 -0
- package/dist/production/shared/constants.js +1 -1
- package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +2 -2
- package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +3 -3
- package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +2 -2
- package/dist/types/src/navigation/shared/syncLocaleCookie.d.ts +6 -0
- package/dist/types/src/shared/constants.d.ts +3 -0
- package/package.json +7 -7
|
@@ -136,11 +136,10 @@ function createMiddleware(config) {
|
|
|
136
136
|
if (hasOutdatedCookie) {
|
|
137
137
|
response.cookies.set(constants.COOKIE_LOCALE_NAME, locale, {
|
|
138
138
|
path: request.nextUrl.basePath || undefined,
|
|
139
|
-
sameSite:
|
|
140
|
-
maxAge:
|
|
139
|
+
sameSite: constants.COOKIE_SAME_SITE,
|
|
140
|
+
maxAge: constants.COOKIE_MAX_AGE
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
|
-
|
|
144
143
|
if (configWithDefaults.localePrefix !== 'never' && configWithDefaults.alternateLinks && configWithDefaults.locales.length > 1) {
|
|
145
144
|
var _configWithDefaults$p;
|
|
146
145
|
response.headers.set('Link', getAlternateLinksHeaderValue.default({
|
|
@@ -20,7 +20,6 @@ function ClientLink(_ref, ref) {
|
|
|
20
20
|
const linkLocale = locale || defaultLocale;
|
|
21
21
|
return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
|
|
22
22
|
ref: ref,
|
|
23
|
-
hrefLang: linkLocale,
|
|
24
23
|
locale: linkLocale
|
|
25
24
|
}, rest));
|
|
26
25
|
}
|
|
@@ -17,7 +17,7 @@ function createSharedPathnamesNavigation(opts) {
|
|
|
17
17
|
function Link(props, ref) {
|
|
18
18
|
return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
|
|
19
19
|
ref: ref,
|
|
20
|
-
localePrefix: opts.localePrefix
|
|
20
|
+
localePrefix: opts === null || opts === void 0 ? void 0 : opts.localePrefix
|
|
21
21
|
}, props));
|
|
22
22
|
}
|
|
23
23
|
const LinkWithRef = /*#__PURE__*/React.forwardRef(Link);
|
|
@@ -6,6 +6,7 @@ var navigation = require('next/navigation');
|
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var useLocale = require('../../react-client/useLocale.js');
|
|
8
8
|
var utils = require('../../shared/utils.js');
|
|
9
|
+
var syncLocaleCookie = require('../shared/syncLocaleCookie.js');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Returns a wrapped instance of `useRouter` from `next/navigation` that
|
|
@@ -29,48 +30,34 @@ var utils = require('../../shared/utils.js');
|
|
|
29
30
|
function useBaseRouter() {
|
|
30
31
|
const router = navigation.useRouter();
|
|
31
32
|
const locale = useLocale.default();
|
|
33
|
+
const pathname = navigation.usePathname();
|
|
32
34
|
return React.useMemo(() => {
|
|
33
35
|
function localize(href, nextLocale) {
|
|
34
36
|
return utils.localizeHref(href, nextLocale || locale, locale, window.location.pathname);
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
push(href, options) {
|
|
39
|
-
const {
|
|
40
|
-
locale: nextLocale,
|
|
41
|
-
...rest
|
|
42
|
-
} = options || {};
|
|
43
|
-
const args = [localize(href, nextLocale)];
|
|
44
|
-
if (Object.keys(rest).length > 0) {
|
|
45
|
-
args.push(rest);
|
|
46
|
-
}
|
|
47
|
-
return router.push(...args);
|
|
48
|
-
},
|
|
49
|
-
replace(href, options) {
|
|
50
|
-
const {
|
|
51
|
-
locale: nextLocale,
|
|
52
|
-
...rest
|
|
53
|
-
} = options || {};
|
|
54
|
-
const args = [localize(href, nextLocale)];
|
|
55
|
-
if (Object.keys(rest).length > 0) {
|
|
56
|
-
args.push(rest);
|
|
57
|
-
}
|
|
58
|
-
return router.replace(...args);
|
|
59
|
-
},
|
|
60
|
-
prefetch(href, options) {
|
|
38
|
+
function createHandler(fn) {
|
|
39
|
+
return function handler(href, options) {
|
|
61
40
|
const {
|
|
62
41
|
locale: nextLocale,
|
|
63
42
|
...rest
|
|
64
43
|
} = options || {};
|
|
44
|
+
syncLocaleCookie.default(pathname, locale, nextLocale);
|
|
65
45
|
const args = [localize(href, nextLocale)];
|
|
66
46
|
if (Object.keys(rest).length > 0) {
|
|
67
|
-
// @ts-expect-error TypeScript thinks `rest` can be an empty object
|
|
68
47
|
args.push(rest);
|
|
69
48
|
}
|
|
70
|
-
|
|
71
|
-
|
|
49
|
+
|
|
50
|
+
// @ts-expect-error -- This is ok
|
|
51
|
+
return fn(...args);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...router,
|
|
56
|
+
push: createHandler(router.push),
|
|
57
|
+
replace: createHandler(router.replace),
|
|
58
|
+
prefetch: createHandler(router.prefetch)
|
|
72
59
|
};
|
|
73
|
-
}, [locale, router]);
|
|
60
|
+
}, [locale, pathname, router]);
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
exports.default = useBaseRouter;
|
|
@@ -19,7 +19,7 @@ function createSharedPathnamesNavigation(opts) {
|
|
|
19
19
|
}
|
|
20
20
|
function Link(props) {
|
|
21
21
|
return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
|
|
22
|
-
localePrefix: opts.localePrefix
|
|
22
|
+
localePrefix: opts === null || opts === void 0 ? void 0 : opts.localePrefix
|
|
23
23
|
}, props));
|
|
24
24
|
}
|
|
25
25
|
function redirect(pathname) {
|
|
@@ -9,6 +9,7 @@ var navigation = require('next/navigation');
|
|
|
9
9
|
var React = require('react');
|
|
10
10
|
var useLocale = require('../../react-client/useLocale.js');
|
|
11
11
|
var utils = require('../../shared/utils.js');
|
|
12
|
+
var syncLocaleCookie = require('./syncLocaleCookie.js');
|
|
12
13
|
|
|
13
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
|
|
@@ -20,6 +21,7 @@ function BaseLink(_ref, ref) {
|
|
|
20
21
|
href,
|
|
21
22
|
locale,
|
|
22
23
|
localePrefix,
|
|
24
|
+
onClick,
|
|
23
25
|
prefetch,
|
|
24
26
|
...rest
|
|
25
27
|
} = _ref;
|
|
@@ -40,6 +42,10 @@ function BaseLink(_ref, ref) {
|
|
|
40
42
|
// render, which would potentially be wrong. The final href is
|
|
41
43
|
// determined in the effect below.
|
|
42
44
|
utils.prefixHref(href, locale) : href);
|
|
45
|
+
function onLinkClick(event) {
|
|
46
|
+
syncLocaleCookie.default(pathname, defaultLocale, locale);
|
|
47
|
+
if (onClick) onClick(event);
|
|
48
|
+
}
|
|
43
49
|
React.useEffect(() => {
|
|
44
50
|
if (!pathname || localePrefix === 'never') return;
|
|
45
51
|
setLocalizedHref(utils.localizeHref(href, locale, defaultLocale, pathname !== null && pathname !== void 0 ? pathname : undefined));
|
|
@@ -53,6 +59,8 @@ function BaseLink(_ref, ref) {
|
|
|
53
59
|
return /*#__PURE__*/React__default.default.createElement(NextLink__default.default, _rollupPluginBabelHelpers.extends({
|
|
54
60
|
ref: ref,
|
|
55
61
|
href: localizedHref,
|
|
62
|
+
hrefLang: isChangingLocale ? locale : undefined,
|
|
63
|
+
onClick: onLinkClick,
|
|
56
64
|
prefetch: prefetch
|
|
57
65
|
}, rest));
|
|
58
66
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var constants = require('../../shared/constants.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* We have to keep the cookie value in sync as Next.js might
|
|
9
|
+
* skip a request to the server due to its router cache.
|
|
10
|
+
* See https://github.com/amannn/next-intl/issues/786.
|
|
11
|
+
*/
|
|
12
|
+
function syncLocaleCookie(pathname, locale, nextLocale) {
|
|
13
|
+
const isSwitchingLocale = nextLocale !== locale;
|
|
14
|
+
if (!isSwitchingLocale ||
|
|
15
|
+
// Theoretical case, we always have a pathname in a real app,
|
|
16
|
+
// only not when running e.g. in a simulated test environment
|
|
17
|
+
!pathname) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const basePath = window.location.pathname.replace(pathname, '');
|
|
21
|
+
const hasBasePath = basePath !== '';
|
|
22
|
+
const path = hasBasePath ? basePath : '/';
|
|
23
|
+
|
|
24
|
+
// Note that writing to `document.cookie` doesn't overwrite all
|
|
25
|
+
// cookies, but only the ones referenced via the name here.
|
|
26
|
+
document.cookie = "".concat(constants.COOKIE_LOCALE_NAME, "=").concat(nextLocale, "; path=").concat(path, "; max-age=").concat(constants.COOKIE_MAX_AGE, "; sameSite=").concat(constants.COOKIE_SAME_SITE);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.default = syncLocaleCookie;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
// Reuse the legacy cookie name
|
|
6
6
|
// https://nextjs.org/docs/advanced-features/i18n-routing#leveraging-the-next_locale-cookie
|
|
7
7
|
const COOKIE_LOCALE_NAME = 'NEXT_LOCALE';
|
|
8
|
+
const COOKIE_MAX_AGE = 31536000; // 1 year
|
|
9
|
+
const COOKIE_SAME_SITE = 'strict';
|
|
8
10
|
|
|
9
11
|
// Should take precedence over the cookie
|
|
10
12
|
const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';
|
|
@@ -13,5 +15,7 @@ const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';
|
|
|
13
15
|
const LOCALE_SEGMENT_NAME = 'locale';
|
|
14
16
|
|
|
15
17
|
exports.COOKIE_LOCALE_NAME = COOKIE_LOCALE_NAME;
|
|
18
|
+
exports.COOKIE_MAX_AGE = COOKIE_MAX_AGE;
|
|
19
|
+
exports.COOKIE_SAME_SITE = COOKIE_SAME_SITE;
|
|
16
20
|
exports.HEADER_LOCALE_NAME = HEADER_LOCALE_NAME;
|
|
17
21
|
exports.LOCALE_SEGMENT_NAME = LOCALE_SEGMENT_NAME;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,HEADER_LOCALE_NAME as
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,COOKIE_SAME_SITE as a,COOKIE_MAX_AGE as n,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as o}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getKnownLocaleFromPathname as d,getInternalTemplate as f,formatTemplatePathname as u,getPathWithSearch as m,getBestMatchingDomain as h,applyBasePath as p}from"./utils.js";function v(v){const x=function(e){var t,a,n;return{...e,alternateLinks:null===(t=e.alternateLinks)||void 0===t||t,localePrefix:null!==(a=e.localePrefix)&&void 0!==a?a:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var P,U;const{domain:L,locale:g}=s(x,v.headers,v.cookies,v.nextUrl.pathname),k=x.localeDetection&&(null===(P=v.cookies.get(t))||void 0===P?void 0:P.value)!==g,w=L?L.defaultLocale===g:g===x.defaultLocale,b=(null===(U=x.domains)||void 0===U?void 0:U.filter((e=>i(g,e))))||[],j=null!=x.domains&&!L;function y(t){const a=new URL(t,v.url);return v.nextUrl.basePath&&(a.pathname=p(a.pathname,v.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(v.headers);return e.set(l,g),{request:{headers:e}}}())}function D(t,a){const n=new URL(t,v.url);if(b.length>0&&!a){const e=h(L,g,b);e&&(a=e.domain,e.defaultLocale===g&&"as-needed"===x.localePrefix&&n.pathname.startsWith("/".concat(g))&&(n.pathname=c(n.pathname,x.locales)))}var l;a&&(n.protocol=null!==(l=v.headers.get("x-forwarded-proto"))&&void 0!==l?l:v.nextUrl.protocol,n.port="",n.host=a);return v.nextUrl.basePath&&(n.pathname=p(n.pathname,v.nextUrl.basePath)),e.redirect(n.toString())}const q=c(v.nextUrl.pathname,x.locales),A=d(v.nextUrl.pathname,x.locales),H=null!=A;let R,S,z=v.nextUrl.pathname;if(x.pathnames){let e;if([e=g,S]=f(x.pathnames,q),S){const t=x.pathnames[S],a="string"==typeof t?t:t[g];if(o(a,q))z=u(q,a,S,A);else{const n=x.defaultLocale===g||(null==L?void 0:L.defaultLocale)===g;R=D(m(u(q,"string"==typeof t?t:t[e],a,A||!n?g:void 0),v.nextUrl.search))}}}if(!R)if("/"===z){const e=m("/".concat(g),v.nextUrl.search);R="never"===x.localePrefix||w&&"as-needed"===x.localePrefix?y(e):D(e)}else{const e=m(z,v.nextUrl.search);if(H){const t=m(q,v.nextUrl.search);if("never"===x.localePrefix)R=D(t);else if(A===g)if(w&&"as-needed"===x.localePrefix)R=D(t);else if(x.domains){const a=h(L,A,b);R=(null==L?void 0:L.domain)===(null==a?void 0:a.domain)||j?y(e):D(t,null==a?void 0:a.domain)}else R=y(e);else R=D("/".concat(g).concat(t))}else R="never"===x.localePrefix||w&&("as-needed"===x.localePrefix||x.domains)?y("/".concat(g).concat(e)):D("/".concat(g).concat(e))}var V;(k&&R.cookies.set(t,g,{path:v.nextUrl.basePath||void 0,sameSite:a,maxAge:n}),"never"!==x.localePrefix&&x.alternateLinks&&x.locales.length>1)&&R.headers.set("Link",r({config:x,localizedPathnames:null!=S?null===(V=x.pathnames)||void 0===V?void 0:V[S]:void 0,request:v,resolvedLocale:g}));return R}}export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import l from"../../react-client/useLocale.js";import a from"../shared/BaseLink.js";function o(t,o){let{locale:s,...i}=t;const n=l(),c=s||n;return r.createElement(a,e({ref:o,locale:c},i))}const s=t(o);s.displayName="ClientLink";var i=s;export{i as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"./ClientLink.js";import o from"./clientRedirect.js";import i from"./useBasePathname.js";import a from"./useBaseRouter.js";function u(u){function
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as t}from"react";import n from"./ClientLink.js";import o from"./clientRedirect.js";import i from"./useBasePathname.js";import a from"./useBaseRouter.js";function u(u){function l(t,o){return r.createElement(n,e({ref:o,localePrefix:null==u?void 0:u.localePrefix},t))}const m=t(l);return m.displayName="Link",{Link:m,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return o({...u,pathname:e},...t)},usePathname:function(){return i()},useRouter:a}}export{u as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRouter as e}from"next/navigation";import{useMemo as
|
|
1
|
+
import{useRouter as t,usePathname as e}from"next/navigation";import{useMemo as r}from"react";import o from"../../react-client/useLocale.js";import{localizeHref as n}from"../../shared/utils.js";import c from"../shared/syncLocaleCookie.js";function a(){const a=t(),i=o(),s=e();return r((()=>{function t(t,e){return n(t,e||i,i,window.location.pathname)}function e(e){return function(r,o){const{locale:n,...a}=o||{};c(s,i,n);const u=[t(r,n)];return Object.keys(a).length>0&&u.push(a),e(...u)}}return{...a,push:e(a.push),replace:e(a.replace),prefetch:e(a.prefetch)}}),[i,s,a])}export{a as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"./ServerLink.js";import o from"./serverRedirect.js";function n(n){function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){return r.createElement(t,e({localePrefix:n.localePrefix},o))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),u=1;u<r;u++)t[u-1]=arguments[u];return o({...n,pathname:e},...t)},usePathname:u("usePathname"),useRouter:u("useRouter")}}export{n as default};
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"react";import t from"./ServerLink.js";import o from"./serverRedirect.js";function n(n){function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(o){return r.createElement(t,e({localePrefix:null==n?void 0:n.localePrefix},o))},redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),u=1;u<r;u++)t[u-1]=arguments[u];return o({...n,pathname:e},...t)},usePathname:u("usePathname"),useRouter:u("useRouter")}}export{n as default};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as
|
|
2
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r from"next/link";import{usePathname as o}from"next/navigation";import t,{forwardRef as n,useState as l,useEffect as i}from"react";import c from"../../react-client/useLocale.js";import{isLocalHref as a,prefixHref as p,localizeHref as s}from"../../shared/utils.js";import f from"./syncLocaleCookie.js";function m(n,m){let{href:u,locale:h,localePrefix:d,onClick:v,prefetch:k,...x}=n;const L=o(),g=c(),j=h!==g,[C,y]=l((()=>a(u)&&("never"!==d||j)?p(u,h):u));return i((()=>{L&&"never"!==d&&y(s(u,h,g,null!=L?L:void 0))}),[g,u,h,d,L]),j&&(k&&console.error("The `prefetch` prop is currently not supported when using the `locale` prop on `Link` to switch the locale.`"),k=!1),t.createElement(r,e({ref:m,href:C,hrefLang:j?h:void 0,onClick:function(e){f(L,g,h),v&&v(e)},prefetch:k},x))}const u=n(m);u.displayName="ClientLink";var h=u;export{h as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{COOKIE_LOCALE_NAME as t,COOKIE_MAX_AGE as a,COOKIE_SAME_SITE as c}from"../../shared/constants.js";function o(o,n,e){if(!(e!==n)||!o)return;const i=window.location.pathname.replace(o,""),r=""!==i?i:"/";document.cookie="".concat(t,"=").concat(e,"; path=").concat(r,"; max-age=").concat(a,"; sameSite=").concat(c)}export{o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const L="NEXT_LOCALE",E="X-NEXT-INTL-LOCALE",
|
|
1
|
+
const L="NEXT_LOCALE",t=31536e3,E="strict",c="X-NEXT-INTL-LOCALE",e="locale";export{L as COOKIE_LOCALE_NAME,t as COOKIE_MAX_AGE,E as COOKIE_SAME_SITE,c as HEADER_LOCALE_NAME,e as LOCALE_SEGMENT_NAME};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const s=function(e){var a,t,n;return{...e,alternateLinks:null===(a=e.alternateLinks)||void 0===a||a,localePrefix:null!==(t=e.localePrefix)&&void 0!==t?t:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(r);return function(r){var i,c;const{domain:d,locale:h}=l.default(s,r.headers,r.cookies,r.nextUrl.pathname),u=s.localeDetection&&(null===(i=r.cookies.get(a.COOKIE_LOCALE_NAME))||void 0===i?void 0:i.value)!==h,m=d?d.defaultLocale===h:h===s.defaultLocale,f=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(h,e))))||[],p=null!=s.domains&&!d;function v(t){const n=new URL(t,r.url);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.rewrite(n,function(){const e=new Headers(r.headers);return e.set(a.HEADER_LOCALE_NAME,h),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(f.length>0&&!t){const e=o.getBestMatchingDomain(d,h,f);e&&(t=e.domain,e.defaultLocale===h&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(h))&&(n.pathname=o.getNormalizedPathname(n.pathname,s.locales)))}var l;t&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port="",n.host=t);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const P=o.getNormalizedPathname(r.nextUrl.pathname,s.locales),g=o.getKnownLocaleFromPathname(r.nextUrl.pathname,s.locales),L=null!=g;let U,E,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const s=function(e){var a,t,n;return{...e,alternateLinks:null===(a=e.alternateLinks)||void 0===a||a,localePrefix:null!==(t=e.localePrefix)&&void 0!==t?t:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(r);return function(r){var i,c;const{domain:d,locale:h}=l.default(s,r.headers,r.cookies,r.nextUrl.pathname),u=s.localeDetection&&(null===(i=r.cookies.get(a.COOKIE_LOCALE_NAME))||void 0===i?void 0:i.value)!==h,m=d?d.defaultLocale===h:h===s.defaultLocale,f=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(h,e))))||[],p=null!=s.domains&&!d;function v(t){const n=new URL(t,r.url);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.rewrite(n,function(){const e=new Headers(r.headers);return e.set(a.HEADER_LOCALE_NAME,h),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(f.length>0&&!t){const e=o.getBestMatchingDomain(d,h,f);e&&(t=e.domain,e.defaultLocale===h&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(h))&&(n.pathname=o.getNormalizedPathname(n.pathname,s.locales)))}var l;t&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port="",n.host=t);return r.nextUrl.basePath&&(n.pathname=o.applyBasePath(n.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const P=o.getNormalizedPathname(r.nextUrl.pathname,s.locales),g=o.getKnownLocaleFromPathname(r.nextUrl.pathname,s.locales),L=null!=g;let U,E,O=r.nextUrl.pathname;if(s.pathnames){let e;if([e=h,E]=o.getInternalTemplate(s.pathnames,P),E){const a=s.pathnames[E],n="string"==typeof a?a:a[h];if(t.matchesPathname(n,P))O=o.formatTemplatePathname(P,n,E,g);else{const t=s.defaultLocale===h||(null==d?void 0:d.defaultLocale)===h;U=x(o.getPathWithSearch(o.formatTemplatePathname(P,"string"==typeof a?a:a[e],n,g||!t?h:void 0),r.nextUrl.search))}}}if(!U)if("/"===O){const e=o.getPathWithSearch("/".concat(h),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?v(e):x(e)}else{const e=o.getPathWithSearch(O,r.nextUrl.search);if(L){const a=o.getPathWithSearch(P,r.nextUrl.search);if("never"===s.localePrefix)U=x(a);else if(g===h)if(m&&"as-needed"===s.localePrefix)U=x(a);else if(s.domains){const t=o.getBestMatchingDomain(d,g,f);U=(null==d?void 0:d.domain)===(null==t?void 0:t.domain)||p?v(e):x(a,null==t?void 0:t.domain)}else U=v(e);else U=x("/".concat(h).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?v("/".concat(h).concat(e)):x("/".concat(h).concat(e))}var A;(u&&U.cookies.set(a.COOKIE_LOCALE_NAME,h,{path:r.nextUrl.basePath||void 0,sameSite:a.COOKIE_SAME_SITE,maxAge:a.COOKIE_MAX_AGE}),"never"!==s.localePrefix&&s.alternateLinks&&s.locales.length>1)&&U.headers.set("Link",n.default({config:s,localizedPathnames:null!=E?null===(A=s.pathnames)||void 0===A?void 0:A[E]:void 0,request:r,resolvedLocale:h}));return U}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../react-client/useLocale.js"),l=require("../shared/BaseLink.js");function a(e){return e&&e.__esModule?e:{default:e}}var u=a(r);function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("../../react-client/useLocale.js"),l=require("../shared/BaseLink.js");function a(e){return e&&e.__esModule?e:{default:e}}var u=a(r);function s(r,a){let{locale:s,...n}=r;const i=t.default(),o=s||i;return u.default.createElement(l.default,e.extends({ref:a,locale:o},n))}const n=r.forwardRef(s);n.displayName="ClientLink";var i=n;exports.default=i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ClientLink.js"),u=require("./clientRedirect.js"),n=require("./useBasePathname.js"),a=require("./useBaseRouter.js");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ClientLink.js"),u=require("./clientRedirect.js"),n=require("./useBasePathname.js"),a=require("./useBaseRouter.js");function l(e){return e&&e.__esModule?e:{default:e}}var i=l(r);exports.default=function(l){function s(r,u){return i.default.createElement(t.default,e.extends({ref:u,localePrefix:null==l?void 0:l.localePrefix},r))}const f=r.forwardRef(s);return f.displayName="Link",{Link:f,redirect:function(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];return u.default({...l,pathname:e},...t)},usePathname:function(){return n.default()},useRouter:a.default}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("react"),t=require("../../react-client/useLocale.js"),u=require("../../shared/utils.js"),n=require("../shared/syncLocaleCookie.js");exports.default=function(){const c=e.useRouter(),o=t.default(),s=e.usePathname();return r.useMemo((()=>{function e(e,r){return u.localizeHref(e,r||o,o,window.location.pathname)}function r(r){return function(t,u){const{locale:c,...a}=u||{};n.default(s,o,c);const i=[e(t,c)];return Object.keys(a).length>0&&i.push(a),r(...i)}}return{...c,push:r(c.push),replace:r(c.replace),prefetch:r(c.prefetch)}}),[o,s,c])};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ServerLink.js"),n=require("./serverRedirect.js");function u(e){return e&&e.__esModule?e:{default:e}}var o=u(r);exports.default=function(r){function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(n){return o.default.createElement(t.default,e.extends({localePrefix:r.localePrefix},n))},redirect:function(e){for(var t=arguments.length,u=new Array(t>1?t-1:0),o=1;o<t;o++)u[o-1]=arguments[o];return n.default({...r,pathname:e},...u)},usePathname:u("usePathname"),useRouter:u("useRouter")}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),t=require("./ServerLink.js"),n=require("./serverRedirect.js");function u(e){return e&&e.__esModule?e:{default:e}}var o=u(r);exports.default=function(r){function u(e){return()=>{throw new Error("`".concat(e,"` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."))}}return{Link:function(n){return o.default.createElement(t.default,e.extends({localePrefix:null==r?void 0:r.localePrefix},n))},redirect:function(e){for(var t=arguments.length,u=new Array(t>1?t-1:0),o=1;o<t;o++)u[o-1]=arguments[o];return n.default({...r,pathname:e},...u)},usePathname:u("usePathname"),useRouter:u("useRouter")}};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("next/link"),t=require("next/navigation"),l=require("react"),a=require("../../react-client/useLocale.js"),
|
|
2
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("next/link"),t=require("next/navigation"),l=require("react"),a=require("../../react-client/useLocale.js"),i=require("../../shared/utils.js"),u=require("./syncLocaleCookie.js");function n(e){return e&&e.__esModule?e:{default:e}}var f=n(r),o=n(l);function c(r,n){let{href:c,locale:s,localePrefix:d,onClick:v,prefetch:p,...h}=r;const q=t.usePathname(),x=a.default(),_=s!==x,[j,k]=l.useState((()=>i.isLocalHref(c)&&("never"!==d||_)?i.prefixHref(c,s):c));return l.useEffect((()=>{q&&"never"!==d&&k(i.localizeHref(c,s,x,null!=q?q:void 0))}),[x,c,s,d,q]),_&&(p=!1),o.default.createElement(f.default,e.extends({ref:n,href:j,hrefLang:_?s:void 0,onClick:function(e){u.default(q,x,s),v&&v(e)},prefetch:p},h))}const s=l.forwardRef(c);s.displayName="ClientLink";var d=s;exports.default=d;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/constants.js");exports.default=function(t,c,a){if(!(a!==c)||!t)return;const o=window.location.pathname.replace(t,""),n=""!==o?o:"/";document.cookie="".concat(e.COOKIE_LOCALE_NAME,"=").concat(a,"; path=").concat(n,"; max-age=").concat(e.COOKIE_MAX_AGE,"; sameSite=").concat(e.COOKIE_SAME_SITE)};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.COOKIE_LOCALE_NAME="NEXT_LOCALE",exports.HEADER_LOCALE_NAME="X-NEXT-INTL-LOCALE",exports.LOCALE_SEGMENT_NAME="locale";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.COOKIE_LOCALE_NAME="NEXT_LOCALE",exports.COOKIE_MAX_AGE=31536e3,exports.COOKIE_SAME_SITE="strict",exports.HEADER_LOCALE_NAME="X-NEXT-INTL-LOCALE",exports.LOCALE_SEGMENT_NAME="locale";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import React, { ReactElement } from 'react';
|
|
3
3
|
import { AllLocales, LocalePrefix } from '../../shared/types';
|
|
4
4
|
import useBaseRouter from './useBaseRouter';
|
|
5
|
-
export default function createSharedPathnamesNavigation<Locales extends AllLocales>(opts
|
|
6
|
-
locales
|
|
5
|
+
export default function createSharedPathnamesNavigation<Locales extends AllLocales>(opts?: {
|
|
6
|
+
locales?: Locales;
|
|
7
7
|
localePrefix?: LocalePrefix;
|
|
8
8
|
}): {
|
|
9
9
|
Link: (props: Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
@@ -22,9 +22,9 @@ type IntlNavigateOptions<Locales extends AllLocales> = {
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export default function useBaseRouter<Locales extends AllLocales>(): {
|
|
25
|
-
push(href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & IntlNavigateOptions<Locales>) | undefined)
|
|
26
|
-
replace(href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & IntlNavigateOptions<Locales>) | undefined)
|
|
27
|
-
prefetch(href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").PrefetchOptions & IntlNavigateOptions<Locales>) | undefined)
|
|
25
|
+
push: (href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & IntlNavigateOptions<Locales>) | undefined) => void;
|
|
26
|
+
replace: (href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").NavigateOptions & IntlNavigateOptions<Locales>) | undefined) => void;
|
|
27
|
+
prefetch: (href: string, options?: (import("next/dist/shared/lib/app-router-context.shared-runtime").PrefetchOptions & IntlNavigateOptions<Locales>) | undefined) => void;
|
|
28
28
|
back(): void;
|
|
29
29
|
forward(): void;
|
|
30
30
|
refresh(): void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { ComponentProps } from 'react';
|
|
2
2
|
import { AllLocales, LocalePrefix } from '../../shared/types';
|
|
3
3
|
import ServerLink from './ServerLink';
|
|
4
|
-
export default function createSharedPathnamesNavigation<Locales extends AllLocales>(opts
|
|
5
|
-
locales
|
|
4
|
+
export default function createSharedPathnamesNavigation<Locales extends AllLocales>(opts?: {
|
|
5
|
+
locales?: Locales;
|
|
6
6
|
localePrefix?: LocalePrefix;
|
|
7
7
|
}): {
|
|
8
8
|
Link: (props: ComponentProps<typeof ServerLink<Locales>>) => React.JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We have to keep the cookie value in sync as Next.js might
|
|
3
|
+
* skip a request to the server due to its router cache.
|
|
4
|
+
* See https://github.com/amannn/next-intl/issues/786.
|
|
5
|
+
*/
|
|
6
|
+
export default function syncLocaleCookie(pathname: string | null, locale: string, nextLocale?: string): void;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const COOKIE_LOCALE_NAME = "NEXT_LOCALE";
|
|
2
|
+
export declare const COOKIE_MAX_AGE = 31536000;
|
|
3
|
+
export declare const COOKIE_SAME_SITE = "strict";
|
|
4
|
+
export declare const COOKIE_BASE_PATH_NAME = "NEXT_INTL_BASE_PATH";
|
|
2
5
|
export declare const HEADER_LOCALE_NAME = "X-NEXT-INTL-LOCALE";
|
|
3
6
|
export declare const LOCALE_SEGMENT_NAME = "locale";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
84
84
|
"negotiator": "^0.6.3",
|
|
85
|
-
"use-intl": "^3.
|
|
85
|
+
"use-intl": "^3.5.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"eslint": "^8.54.0",
|
|
101
101
|
"eslint-config-molindo": "^7.0.0",
|
|
102
102
|
"eslint-plugin-deprecation": "^1.4.1",
|
|
103
|
-
"next": "^14.0
|
|
103
|
+
"next": "^14.1.0",
|
|
104
104
|
"path-to-regexp": "^6.2.1",
|
|
105
105
|
"publint": "^0.2.7",
|
|
106
106
|
"react": "^18.2.0",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"size-limit": [
|
|
115
115
|
{
|
|
116
116
|
"path": "dist/production/index.react-client.js",
|
|
117
|
-
"limit": "12.
|
|
117
|
+
"limit": "12.865 KB"
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
120
|
"path": "dist/production/index.react-server.js",
|
|
@@ -122,11 +122,11 @@
|
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
"path": "dist/production/navigation.react-client.js",
|
|
125
|
-
"limit": "2.
|
|
125
|
+
"limit": "2.83 KB"
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
"path": "dist/production/navigation.react-server.js",
|
|
129
|
-
"limit": "2.
|
|
129
|
+
"limit": "2.94 KB"
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
132
|
"path": "dist/production/server.react-client.js",
|
|
@@ -141,5 +141,5 @@
|
|
|
141
141
|
"limit": "5.8 KB"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "716d71605c2b855c6c6004e0c233bbc20ddeaf74"
|
|
145
145
|
}
|