next-intl 3.1.3 → 3.1.4-alpha.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.
@@ -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, host) {
47
+ function redirect(url, redirectDomain) {
48
48
  const urlObj = new URL(url, request.url);
49
49
  if (domainConfigs.length > 0) {
50
- if (!host) {
50
+ if (!redirectDomain) {
51
51
  const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainConfigs);
52
52
  if (bestMatchingDomain) {
53
- host = bestMatchingDomain.domain;
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 (host) {
61
- urlObj.host = host;
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 n,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t}from"../shared/utils.js";import o 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 n,l,t;return{...e,alternateLinks:null===(n=e.alternateLinks)||void 0===n||n,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(t=e.localeDetection)||void 0===t||t}}(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(n))||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))))||[],j=null!=h.domains&&!L;function w(n){return e.rewrite(new URL(n,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(n,l){const t=new URL(n,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(t.pathname=t.pathname.replace("/".concat(P),"")))}return l&&(t.host=l),e.redirect(t.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 n=h.pathnames[R],l="string"==typeof n?n:n[P];if(t(l,D))S=d(D,l,R,q);else{const t=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof n?n:n[e],l,q||!t?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?w(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const n=u(e,q);if("never"===h.localePrefix)H=y(n);else if(q===P)if(U&&"as-needed"===h.localePrefix)H=y(n);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||j?w(e):y(n,null==l?void 0:l.domain)}else H=w(e);else H=y("/".concat(P).concat(n))}else H="never"===h.localePrefix||U&&("as-needed"===h.localePrefix||h.domains)?w("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(g&&H.cookies.set(n,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",o({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
+ 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),"")))}return a&&(n.host=a),e.NextResponse.redirect(n.toString())}const L=o.getNormalizedPathname(r.nextUrl.pathname,i.locales),P=o.getKnownLocaleFromPathname(r.nextUrl.pathname,i.locales),g=null!=P;let E,A,O=r.nextUrl.pathname;if(i.pathnames){let e;if([e=u,A]=o.getInternalTemplate(i.pathnames,L),A){const t=i.pathnames[A],n="string"==typeof t?t:t[u];if(a.matchesPathname(n,L))O=o.formatTemplatePathname(L,n,A,P);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,P||!a?u:void 0),r.nextUrl.search))}}}if(!E)if("/"===O){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(O,r.nextUrl.search);if(g){const t=o.getBasePath(e,P);if("never"===i.localePrefix)E=x(t);else if(P===u)if(h&&"as-needed"===i.localePrefix)E=x(t);else if(i.domains){const a=o.getBestMatchingDomain(d,P,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 U;(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!=A?null===(U=i.pathnames)||void 0===U?void 0:U[A]:void 0,request:r,resolvedLocale:u}));return E}};
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",
3
+ "version": "3.1.4-alpha.1",
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.",
@@ -10,14 +10,6 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/amannn/next-intl"
12
12
  },
13
- "scripts": {
14
- "build": "rm -rf dist && rollup -c",
15
- "test": "TZ=Europe/Berlin vitest",
16
- "lint": "eslint src test && tsc --noEmit",
17
- "prepublishOnly": "CI=true turbo test && turbo lint && turbo build && cp ../../README.md .",
18
- "postpublish": "git checkout . && rm ./README.md",
19
- "size": "size-limit"
20
- },
21
13
  "main": "./dist/index.react-client.js",
22
14
  "module": "./dist/esm/index.react-client.js",
23
15
  "typings": "./dist/types/src/index.react-client.d.ts",
@@ -125,5 +117,10 @@
125
117
  "limit": "5.7 KB"
126
118
  }
127
119
  ],
128
- "gitHead": "f4423350fcba6707c005725deade19a7083c22b5"
129
- }
120
+ "scripts": {
121
+ "build": "rm -rf dist && rollup -c",
122
+ "test": "TZ=Europe/Berlin vitest",
123
+ "lint": "eslint src test && tsc --noEmit",
124
+ "size": "size-limit"
125
+ }
126
+ }