next-intl 3.1.3 → 3.1.4
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.
|
@@ -44,21 +44,24 @@ function createMiddleware(config) {
|
|
|
44
44
|
function rewrite(url) {
|
|
45
45
|
return server.NextResponse.rewrite(new URL(url, request.url), getResponseInit());
|
|
46
46
|
}
|
|
47
|
-
function redirect(url,
|
|
47
|
+
function redirect(url, redirectDomain) {
|
|
48
48
|
const urlObj = new URL(url, request.url);
|
|
49
49
|
if (domainConfigs.length > 0) {
|
|
50
|
-
if (!
|
|
50
|
+
if (!redirectDomain) {
|
|
51
51
|
const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainConfigs);
|
|
52
52
|
if (bestMatchingDomain) {
|
|
53
|
-
|
|
53
|
+
redirectDomain = bestMatchingDomain.domain;
|
|
54
54
|
if (bestMatchingDomain.defaultLocale === locale && configWithDefaults.localePrefix === 'as-needed') {
|
|
55
55
|
urlObj.pathname = urlObj.pathname.replace("/".concat(locale), '');
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
60
|
+
if (redirectDomain) {
|
|
61
|
+
var _request$headers$get;
|
|
62
|
+
urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
|
|
63
|
+
urlObj.port = '';
|
|
64
|
+
urlObj.host = redirectDomain;
|
|
62
65
|
}
|
|
63
66
|
return server.NextResponse.redirect(urlObj.toString());
|
|
64
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),g=h.localeDetection&&(null===(p=v.cookies.get(o))||void 0===p?void 0:p.value)!==P,U=L?L.defaultLocale===P:P===h.defaultLocale,k=(null===(x=h.domains)||void 0===x?void 0:x.filter((e=>r(P,e))))||[],w=null!=h.domains&&!L;function j(o){return e.rewrite(new URL(o,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(o,l){const n=new URL(o,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(n.pathname=n.pathname.replace("/".concat(P),"")))}var t;l&&(n.protocol=null!==(t=v.headers.get("x-forwarded-proto"))&&void 0!==t?t:v.nextUrl.protocol,n.port="",n.host=l);return e.redirect(n.toString())}const D=i(v.nextUrl.pathname,h.locales),q=s(v.nextUrl.pathname,h.locales),A=null!=q;let H,R,S=v.nextUrl.pathname;if(h.pathnames){let e;if([e=P,R]=c(h.pathnames,D),R){const o=h.pathnames[R],l="string"==typeof o?o:o[P];if(n(l,D))S=d(D,l,R,q);else{const n=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof o?o:o[e],l,q||!n?P:void 0),v.nextUrl.search))}}}if(!H)if("/"===S){const e=f("/".concat(P),v.nextUrl.search);H="never"===h.localePrefix||U&&"as-needed"===h.localePrefix?j(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const o=u(e,q);if("never"===h.localePrefix)H=y(o);else if(q===P)if(U&&"as-needed"===h.localePrefix)H=y(o);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||w?j(e):y(o,null==l?void 0:l.domain)}else H=j(e);else H=y("/".concat(P).concat(o))}else H="never"===h.localePrefix||U&&("as-needed"===h.localePrefix||h.domains)?j("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(g&&H.cookies.set(o,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",t({config:h,localizedPathnames:null!=R?null===(z=h.pathnames)||void 0===z?void 0:z[R]:void 0,request:v,resolvedLocale:P}));return H}}export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),t=require("../shared/constants.js"),a=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const i=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}}(r);return function(r){var s,c;const{domain:d,locale:u}=l.default(i,r.headers,r.cookies,r.nextUrl.pathname),f=i.localeDetection&&(null===(s=r.cookies.get(t.COOKIE_LOCALE_NAME))||void 0===s?void 0:s.value)!==u,h=d?d.defaultLocale===u:u===i.defaultLocale,m=(null===(c=i.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=i.domains&&!d;function p(a){return e.NextResponse.rewrite(new URL(a,r.url),function(){const e=new Headers(r.headers);return e.set(t.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function x(t,a){const n=new URL(t,r.url);if(m.length>0&&!a){const e=o.getBestMatchingDomain(d,u,m);e&&(a=e.domain,e.defaultLocale===u&&"as-needed"===i.localePrefix&&(n.pathname=n.pathname.replace("/".concat(u),"")))}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),t=require("../shared/constants.js"),a=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const i=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}}(r);return function(r){var s,c;const{domain:d,locale:u}=l.default(i,r.headers,r.cookies,r.nextUrl.pathname),f=i.localeDetection&&(null===(s=r.cookies.get(t.COOKIE_LOCALE_NAME))||void 0===s?void 0:s.value)!==u,h=d?d.defaultLocale===u:u===i.defaultLocale,m=(null===(c=i.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=i.domains&&!d;function p(a){return e.NextResponse.rewrite(new URL(a,r.url),function(){const e=new Headers(r.headers);return e.set(t.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function x(t,a){const n=new URL(t,r.url);if(m.length>0&&!a){const e=o.getBestMatchingDomain(d,u,m);e&&(a=e.domain,e.defaultLocale===u&&"as-needed"===i.localePrefix&&(n.pathname=n.pathname.replace("/".concat(u),"")))}var l;a&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port="",n.host=a);return e.NextResponse.redirect(n.toString())}const L=o.getNormalizedPathname(r.nextUrl.pathname,i.locales),g=o.getKnownLocaleFromPathname(r.nextUrl.pathname,i.locales),P=null!=g;let E,U,A=r.nextUrl.pathname;if(i.pathnames){let e;if([e=u,U]=o.getInternalTemplate(i.pathnames,L),U){const t=i.pathnames[U],n="string"==typeof t?t:t[u];if(a.matchesPathname(n,L))A=o.formatTemplatePathname(L,n,U,g);else{const a=i.defaultLocale===u||(null==d?void 0:d.defaultLocale)===u;E=x(o.getPathWithSearch(o.formatTemplatePathname(L,"string"==typeof t?t:t[e],n,g||!a?u:void 0),r.nextUrl.search))}}}if(!E)if("/"===A){const e=o.getPathWithSearch("/".concat(u),r.nextUrl.search);E="never"===i.localePrefix||h&&"as-needed"===i.localePrefix?p(e):x(e)}else{const e=o.getPathWithSearch(A,r.nextUrl.search);if(P){const t=o.getBasePath(e,g);if("never"===i.localePrefix)E=x(t);else if(g===u)if(h&&"as-needed"===i.localePrefix)E=x(t);else if(i.domains){const a=o.getBestMatchingDomain(d,g,m);E=(null==d?void 0:d.domain)===(null==a?void 0:a.domain)||v?p(e):x(t,null==a?void 0:a.domain)}else E=p(e);else E=x("/".concat(u).concat(t))}else E="never"===i.localePrefix||h&&("as-needed"===i.localePrefix||i.domains)?p("/".concat(u).concat(e)):x("/".concat(u).concat(e))}var O;(f&&E.cookies.set(t.COOKIE_LOCALE_NAME,u,{sameSite:"strict",maxAge:31536e3}),"never"!==i.localePrefix&&i.alternateLinks&&i.locales.length>1)&&E.headers.set("Link",n.default({config:i,localizedPathnames:null!=U?null===(O=i.pathnames)||void 0===O?void 0:O[U]:void 0,request:r,resolvedLocale:u}));return E}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4",
|
|
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.",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
75
75
|
"negotiator": "^0.6.3",
|
|
76
|
-
"use-intl": "^3.1.
|
|
76
|
+
"use-intl": "^3.1.4"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -122,8 +122,8 @@
|
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
"path": "dist/production/middleware.js",
|
|
125
|
-
"limit": "5.
|
|
125
|
+
"limit": "5.72 KB"
|
|
126
126
|
}
|
|
127
127
|
],
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "ae5c0347f70e19ee61fe94b0828655936759df6f"
|
|
129
129
|
}
|