next-intl 3.10.0 → 3.11.0-beta.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.
@@ -24,10 +24,12 @@ function createMiddleware(config) {
24
24
  const configWithDefaults = receiveConfig(config);
25
25
  return function middleware(request) {
26
26
  var _request$cookies$get, _configWithDefaults$d;
27
+ // Resolve potential foreign symbols (e.g. /ja/%E7%B4%84 → /ja/約))
28
+ const nextPathname = decodeURI(request.nextUrl.pathname);
27
29
  const {
28
30
  domain,
29
31
  locale
30
- } = resolveLocale.default(configWithDefaults, request.headers, request.cookies, request.nextUrl.pathname);
32
+ } = resolveLocale.default(configWithDefaults, request.headers, request.cookies, nextPathname);
31
33
  const hasOutdatedCookie = configWithDefaults.localeDetection && ((_request$cookies$get = request.cookies.get(constants.COOKIE_LOCALE_NAME)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
32
34
  const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === configWithDefaults.defaultLocale;
33
35
  const domainConfigs = ((_configWithDefaults$d = configWithDefaults.domains) === null || _configWithDefaults$d === void 0 ? void 0 : _configWithDefaults$d.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
@@ -72,12 +74,12 @@ function createMiddleware(config) {
72
74
  }
73
75
  return server.NextResponse.redirect(urlObj.toString());
74
76
  }
75
- const normalizedPathname = utils.getNormalizedPathname(request.nextUrl.pathname, configWithDefaults.locales);
76
- const pathLocale = utils.getPathnameLocale(request.nextUrl.pathname, configWithDefaults.locales);
77
+ const normalizedPathname = utils.getNormalizedPathname(nextPathname, configWithDefaults.locales);
78
+ const pathLocale = utils.getPathnameLocale(nextPathname, configWithDefaults.locales);
77
79
  const hasLocalePrefix = pathLocale != null;
78
80
  let response;
79
81
  let internalTemplateName;
80
- let pathname = request.nextUrl.pathname;
82
+ let pathname = nextPathname;
81
83
  if (configWithDefaults.pathnames) {
82
84
  let resolvedTemplateLocale;
83
85
  [resolvedTemplateLocale, internalTemplateName] = utils.getInternalTemplate(configWithDefaults.pathnames, normalizedPathname, locale);
@@ -1 +1 @@
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,getPathnameLocale as d,getInternalTemplate as f,formatTemplatePathname as m,getPathWithSearch as h,getBestMatchingDomain as u,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=u(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,S]=f(x.pathnames,q,g),S){const t=x.pathnames[S],a="string"==typeof t?t:t[g];if(o(a,q))z=m(q,a,S,A);else{let n;n=e?"string"==typeof t?t:t[e]:S;const l=!H&&w||"never"===x.localePrefix?void 0:g;R=D(h(m(q,n,a,l),v.nextUrl.search))}}}if(!R)if("/"===z){const e=h("/".concat(g),v.nextUrl.search);R="never"===x.localePrefix||w&&"as-needed"===x.localePrefix?y(e):D(e)}else{const e=h(z,v.nextUrl.search);if(H){const t=h(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=u(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
+ 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 o}from"../shared/constants.js";import{matchesPathname as l}from"../shared/utils.js";import r from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import{isLocaleSupportedOnDomain as i,getNormalizedPathname as c,getPathnameLocale as d,getInternalTemplate as f,formatTemplatePathname as u,getPathWithSearch as m,getBestMatchingDomain as h,applyBasePath as v}from"./utils.js";function p(p){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}}(p);return function(p){var P,U;const L=decodeURI(p.nextUrl.pathname),{domain:g,locale:k}=s(x,p.headers,p.cookies,L),w=x.localeDetection&&(null===(P=p.cookies.get(t))||void 0===P?void 0:P.value)!==k,b=g?g.defaultLocale===k:k===x.defaultLocale,j=(null===(U=x.domains)||void 0===U?void 0:U.filter((e=>i(k,e))))||[],y=null!=x.domains&&!g;function D(t){const a=new URL(t,p.url);return p.nextUrl.basePath&&(a.pathname=v(a.pathname,p.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(p.headers);return e.set(o,k),{request:{headers:e}}}())}function R(t,a){const n=new URL(t,p.url);if(j.length>0&&!a){const e=h(g,k,j);e&&(a=e.domain,e.defaultLocale===k&&"as-needed"===x.localePrefix&&n.pathname.startsWith("/".concat(k))&&(n.pathname=c(n.pathname,x.locales)))}var o;a&&(n.protocol=null!==(o=p.headers.get("x-forwarded-proto"))&&void 0!==o?o:p.nextUrl.protocol,n.port="",n.host=a);return p.nextUrl.basePath&&(n.pathname=v(n.pathname,p.nextUrl.basePath)),e.redirect(n.toString())}const q=c(L,x.locales),A=d(L,x.locales),H=null!=A;let S,z,I=L;if(x.pathnames){let e;if([e,z]=f(x.pathnames,q,k),z){const t=x.pathnames[z],a="string"==typeof t?t:t[k];if(l(a,q))I=u(q,a,z,A);else{let n;n=e?"string"==typeof t?t:t[e]:z;const o=!H&&b||"never"===x.localePrefix?void 0:k;S=R(m(u(q,n,a,o),p.nextUrl.search))}}}if(!S)if("/"===I){const e=m("/".concat(k),p.nextUrl.search);S="never"===x.localePrefix||b&&"as-needed"===x.localePrefix?D(e):R(e)}else{const e=m(I,p.nextUrl.search);if(H){const t=m(q,p.nextUrl.search);if("never"===x.localePrefix)S=R(t);else if(A===k)if(b&&"as-needed"===x.localePrefix)S=R(t);else if(x.domains){const a=h(g,A,j);S=(null==g?void 0:g.domain)===(null==a?void 0:a.domain)||y?D(e):R(t,null==a?void 0:a.domain)}else S=D(e);else S=R("/".concat(k).concat(t))}else S="never"===x.localePrefix||b&&("as-needed"===x.localePrefix||x.domains)?D("/".concat(k).concat(e)):R("/".concat(k).concat(e))}var V;(w&&S.cookies.set(t,k,{path:p.nextUrl.basePath||void 0,sameSite:a,maxAge:n}),"never"!==x.localePrefix&&x.alternateLinks&&x.locales.length>1)&&S.headers.set("Link",r({config:x,localizedPathnames:null!=z?null===(V=x.pathnames)||void 0===V?void 0:V[z]:void 0,request:p,resolvedLocale:k}));return S}}export{p as default};
@@ -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:h,locale:d}=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)!==d,m=h?h.defaultLocale===d:d===s.defaultLocale,f=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(d,e))))||[],p=null!=s.domains&&!h;function x(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,d),{request:{headers:e}}}())}function v(a,t){const n=new URL(a,r.url);if(f.length>0&&!t){const e=o.getBestMatchingDomain(h,d,f);e&&(t=e.domain,e.defaultLocale===d&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(d))&&(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.getPathnameLocale(r.nextUrl.pathname,s.locales),L=null!=g;let U,E,O=r.nextUrl.pathname;if(s.pathnames){let e;if([e,E]=o.getInternalTemplate(s.pathnames,P,d),E){const a=s.pathnames[E],n="string"==typeof a?a:a[d];if(t.matchesPathname(n,P))O=o.formatTemplatePathname(P,n,E,g);else{let t;t=e?"string"==typeof a?a:a[e]:E;const l=!L&&m||"never"===s.localePrefix?void 0:d;U=v(o.getPathWithSearch(o.formatTemplatePathname(P,t,n,l),r.nextUrl.search))}}}if(!U)if("/"===O){const e=o.getPathWithSearch("/".concat(d),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?x(e):v(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=v(a);else if(g===d)if(m&&"as-needed"===s.localePrefix)U=v(a);else if(s.domains){const t=o.getBestMatchingDomain(h,g,f);U=(null==h?void 0:h.domain)===(null==t?void 0:t.domain)||p?x(e):v(a,null==t?void 0:t.domain)}else U=x(e);else U=v("/".concat(d).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?x("/".concat(d).concat(e)):v("/".concat(d).concat(e))}var A;(u&&U.cookies.set(a.COOKIE_LOCALE_NAME,d,{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:d}));return U}};
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 d=decodeURI(r.nextUrl.pathname),{domain:h,locale:u}=l.default(s,r.headers,r.cookies,d),f=s.localeDetection&&(null===(i=r.cookies.get(a.COOKIE_LOCALE_NAME))||void 0===i?void 0:i.value)!==u,m=h?h.defaultLocale===u:u===s.defaultLocale,p=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=s.domains&&!h;function P(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,u),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(p.length>0&&!t){const e=o.getBestMatchingDomain(h,u,p);e&&(t=e.domain,e.defaultLocale===u&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(u))&&(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 g=o.getNormalizedPathname(d,s.locales),L=o.getPathnameLocale(d,s.locales),E=null!=L;let U,O,A=d;if(s.pathnames){let e;if([e,O]=o.getInternalTemplate(s.pathnames,g,u),O){const a=s.pathnames[O],n="string"==typeof a?a:a[u];if(t.matchesPathname(n,g))A=o.formatTemplatePathname(g,n,O,L);else{let t;t=e?"string"==typeof a?a:a[e]:O;const l=!E&&m||"never"===s.localePrefix?void 0:u;U=x(o.getPathWithSearch(o.formatTemplatePathname(g,t,n,l),r.nextUrl.search))}}}if(!U)if("/"===A){const e=o.getPathWithSearch("/".concat(u),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?P(e):x(e)}else{const e=o.getPathWithSearch(A,r.nextUrl.search);if(E){const a=o.getPathWithSearch(g,r.nextUrl.search);if("never"===s.localePrefix)U=x(a);else if(L===u)if(m&&"as-needed"===s.localePrefix)U=x(a);else if(s.domains){const t=o.getBestMatchingDomain(h,L,p);U=(null==h?void 0:h.domain)===(null==t?void 0:t.domain)||v?P(e):x(a,null==t?void 0:t.domain)}else U=P(e);else U=x("/".concat(u).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?P("/".concat(u).concat(e)):x("/".concat(u).concat(e))}var _;(f&&U.cookies.set(a.COOKIE_LOCALE_NAME,u,{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!=O?null===(_=s.pathnames)||void 0===_?void 0:_[O]:void 0,request:r,resolvedLocale:u}));return U}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.10.0",
3
+ "version": "3.11.0-beta.1",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -16,16 +16,6 @@
16
16
  "type": "git",
17
17
  "url": "https://github.com/amannn/next-intl"
18
18
  },
19
- "scripts": {
20
- "build": "rm -rf dist && rollup -c",
21
- "test": "TZ=Europe/Berlin vitest",
22
- "lint": "pnpm run lint:source && pnpm run lint:package",
23
- "lint:source": "eslint src test && tsc --noEmit",
24
- "lint:package": "publint && attw --pack",
25
- "prepublishOnly": "CI=true turbo test && turbo lint && turbo build && cp ../../README.md .",
26
- "postpublish": "git checkout . && rm ./README.md",
27
- "size": "size-limit"
28
- },
29
19
  "main": "./dist/index.react-client.js",
30
20
  "module": "./dist/esm/index.react-client.js",
31
21
  "typings": "./dist/types/src/index.react-client.d.ts",
@@ -138,8 +128,15 @@
138
128
  },
139
129
  {
140
130
  "path": "dist/production/middleware.js",
141
- "limit": "5.9 KB"
131
+ "limit": "5.95 KB"
142
132
  }
143
133
  ],
144
- "gitHead": "9dd129cdd72c8ac6704b2c9776d018e8db7a758e"
145
- }
134
+ "scripts": {
135
+ "build": "rm -rf dist && rollup -c",
136
+ "test": "TZ=Europe/Berlin vitest",
137
+ "lint": "pnpm run lint:source && pnpm run lint:package",
138
+ "lint:source": "eslint src test && tsc --noEmit",
139
+ "lint:package": "publint && attw --pack",
140
+ "size": "size-limit"
141
+ }
142
+ }