next-intl 3.21.0-canary.0 → 3.22.0-canary.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.
@@ -12,11 +12,12 @@ var syncCookie = require('./syncCookie.js');
12
12
  var utils = require('./utils.js');
13
13
 
14
14
  function createMiddleware(routing, options) {
15
- var _ref, _options$alternateLin, _ref2, _options$localeDetect;
15
+ var _ref, _options$alternateLin, _ref2, _options$localeDetect, _ref3, _options$localeCookie;
16
16
  const resolvedRouting = config.receiveRoutingConfig(routing);
17
17
  const resolvedOptions = {
18
18
  alternateLinks: (_ref = (_options$alternateLin = options === null || options === void 0 ? void 0 : options.alternateLinks) !== null && _options$alternateLin !== void 0 ? _options$alternateLin : routing.alternateLinks) !== null && _ref !== void 0 ? _ref : true,
19
- localeDetection: (_ref2 = (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing === null || routing === void 0 ? void 0 : routing.localeDetection) !== null && _ref2 !== void 0 ? _ref2 : true
19
+ localeDetection: (_ref2 = (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing === null || routing === void 0 ? void 0 : routing.localeDetection) !== null && _ref2 !== void 0 ? _ref2 : true,
20
+ localeCookie: (_ref3 = (_options$localeCookie = options === null || options === void 0 ? void 0 : options.localeCookie) !== null && _options$localeCookie !== void 0 ? _options$localeCookie : routing === null || routing === void 0 ? void 0 : routing.localeCookie) !== null && _ref3 !== void 0 ? _ref3 : true
20
21
  };
21
22
  return function middleware(request) {
22
23
  var _resolvedRouting$doma;
@@ -153,8 +154,8 @@ function createMiddleware(routing, options) {
153
154
  }
154
155
  }
155
156
  }
156
- if (resolvedOptions.localeDetection) {
157
- syncCookie.default(request, response, locale);
157
+ if (resolvedOptions.localeDetection && resolvedOptions.localeCookie) {
158
+ syncCookie.default(request, response, locale, resolvedOptions.localeCookie);
158
159
  }
159
160
  if (resolvedRouting.localePrefix.mode !== 'never' && resolvedOptions.alternateLinks && resolvedRouting.locales.length > 1) {
160
161
  response.headers.set('Link', getAlternateLinksHeaderValue.default({
@@ -4,14 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var constants = require('../shared/constants.js');
6
6
 
7
- function syncCookie(request, response, locale) {
7
+ function syncCookie(request, response, locale, localeCookie) {
8
8
  var _request$cookies$get;
9
9
  const hasOutdatedCookie = ((_request$cookies$get = request.cookies.get(constants.COOKIE_LOCALE_NAME)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
10
10
  if (hasOutdatedCookie) {
11
11
  response.cookies.set(constants.COOKIE_LOCALE_NAME, locale, {
12
12
  path: request.nextUrl.basePath || undefined,
13
13
  sameSite: constants.COOKIE_SAME_SITE,
14
- maxAge: constants.COOKIE_MAX_AGE
14
+ maxAge: constants.COOKIE_MAX_AGE,
15
+ ...(typeof localeCookie === 'object' && localeCookie)
15
16
  });
16
17
  }
17
18
  }
@@ -16,6 +16,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
16
 
17
17
  var React__default = /*#__PURE__*/_interopDefault(React);
18
18
 
19
+ /**
20
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
21
+ **/
19
22
  function createLocalizedPathnamesNavigation(routing) {
20
23
  const config$1 = config.receiveRoutingConfig(routing);
21
24
  function useTypedLocale() {
@@ -14,6 +14,9 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var React__default = /*#__PURE__*/_interopDefault(React);
16
16
 
17
+ /**
18
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
19
+ **/
17
20
  function createSharedPathnamesNavigation(routing) {
18
21
  const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
19
22
  function Link(props, ref) {
@@ -1 +1 @@
1
- import{NextResponse as e}from"next/server";import{receiveRoutingConfig as l}from"../routing/config.js";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as r,getLocalePrefix as n}from"../shared/utils.js";import a from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as u,getInternalTemplate as m,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,L){var g,k,j,w;const b=l(P),y={alternateLinks:null===(g=null!==(k=null==L?void 0:L.alternateLinks)&&void 0!==k?k:P.alternateLinks)||void 0===g||g,localeDetection:null===(j=null!==(w=null==L?void 0:L.localeDetection)&&void 0!==w?w:null==P?void 0:P.localeDetection)||void 0===j||j};return function(l){var P;let L;try{L=decodeURI(l.nextUrl.pathname)}catch(l){return e.next()}const g=c(L),{domain:k,locale:j}=i(b,y,l.headers,l.cookies,g),w=k?k.defaultLocale===j:j===b.defaultLocale,D=(null===(P=b.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],R=null!=b.domains&&!k;function q(t){const r=new URL(t,l.url);l.nextUrl.basePath&&(r.pathname=p(r.pathname,l.nextUrl.basePath));const n=new Headers(l.headers);return n.set(o,j),e.rewrite(r,{request:{headers:n}})}function H(o,t){const n=new URL(r(o),l.url);if(D.length>0&&!t&&k){const e=v(k,j,D);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===b.localePrefix.mode&&(n.pathname=f(n.pathname,b.locales,b.localePrefix)))}var a,i;t&&(n.host=t,l.headers.get("x-forwarded-host")&&(n.protocol=null!==(a=l.headers.get("x-forwarded-proto"))&&void 0!==a?a:l.nextUrl.protocol,n.port=null!==(i=l.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return l.nextUrl.basePath&&(n.pathname=p(n.pathname,l.nextUrl.basePath)),e.redirect(n.toString())}const z=f(g,b.locales,b.localePrefix),A=u(g,b.locales,b.localePrefix),C=null!=A,I="never"===b.localePrefix.mode||w&&"as-needed"===b.localePrefix.mode;let S,V,B=z;const E=b.pathnames;if(E){let e;if([e,V]=m(E,z,j),V){const o=E[V],r="string"==typeof o?o:o[j];if(t(r,z))B=h(z,r,V);else{let t;t=e?"string"==typeof o?o:o[e]:V;const a=I?void 0:n(j,b.localePrefix),i=h(z,t,r);S=H(x(i,a,l.nextUrl.search))}}}if(!S)if("/"!==B||C){const e=x(B,U(j),l.nextUrl.search);if(C){const o=x(z,A.prefix,l.nextUrl.search);if("never"===b.localePrefix.mode)S=H(x(z,void 0,l.nextUrl.search));else if(A.exact)if(w&&I)S=H(x(z,void 0,l.nextUrl.search));else if(b.domains){const l=v(k,A.locale,D);S=(null==k?void 0:k.domain)===(null==l?void 0:l.domain)||R?q(e):H(o,null==l?void 0:l.domain)}else S=q(e);else S=H(o)}else S=I?q(e):H(x(z,n(j,b.localePrefix),l.nextUrl.search))}else S=I?q(x(B,U(j),l.nextUrl.search)):H(x(z,n(j,b.localePrefix),l.nextUrl.search));return y.localeDetection&&s(l,S,j),"never"!==b.localePrefix.mode&&y.alternateLinks&&b.locales.length>1&&S.headers.set("Link",a({routing:b,localizedPathnames:null!=V&&E?null==E?void 0:E[V]:void 0,request:l,resolvedLocale:j})),S}}export{P as default};
1
+ import{NextResponse as e}from"next/server";import{receiveRoutingConfig as l}from"../routing/config.js";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as t,normalizeTrailingSlash as n,getLocalePrefix as r}from"../shared/utils.js";import a from"./getAlternateLinksHeaderValue.js";import i from"./resolveLocale.js";import s from"./syncCookie.js";import{sanitizePathname as c,isLocaleSupportedOnDomain as d,getNormalizedPathname as f,getPathnameMatch as u,getInternalTemplate as m,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as v,applyBasePath as p,getLocaleAsPrefix as U}from"./utils.js";function P(P,k){var L,g,j,w,C,b;const y=l(P),D={alternateLinks:null===(L=null!==(g=null==k?void 0:k.alternateLinks)&&void 0!==g?g:P.alternateLinks)||void 0===L||L,localeDetection:null===(j=null!==(w=null==k?void 0:k.localeDetection)&&void 0!==w?w:null==P?void 0:P.localeDetection)||void 0===j||j,localeCookie:null===(C=null!==(b=null==k?void 0:k.localeCookie)&&void 0!==b?b:null==P?void 0:P.localeCookie)||void 0===C||C};return function(l){var P;let k;try{k=decodeURI(l.nextUrl.pathname)}catch(l){return e.next()}const L=c(k),{domain:g,locale:j}=i(y,D,l.headers,l.cookies,L),w=g?g.defaultLocale===j:j===y.defaultLocale,C=(null===(P=y.domains)||void 0===P?void 0:P.filter((e=>d(j,e))))||[],b=null!=y.domains&&!g;function R(t){const n=new URL(t,l.url);l.nextUrl.basePath&&(n.pathname=p(n.pathname,l.nextUrl.basePath));const r=new Headers(l.headers);return r.set(o,j),e.rewrite(n,{request:{headers:r}})}function q(o,t){const r=new URL(n(o),l.url);if(C.length>0&&!t&&g){const e=v(g,j,C);e&&(t=e.domain,e.defaultLocale===j&&"as-needed"===y.localePrefix.mode&&(r.pathname=f(r.pathname,y.locales,y.localePrefix)))}var a,i;t&&(r.host=t,l.headers.get("x-forwarded-host")&&(r.protocol=null!==(a=l.headers.get("x-forwarded-proto"))&&void 0!==a?a:l.nextUrl.protocol,r.port=null!==(i=l.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return l.nextUrl.basePath&&(r.pathname=p(r.pathname,l.nextUrl.basePath)),e.redirect(r.toString())}const H=f(L,y.locales,y.localePrefix),z=u(L,y.locales,y.localePrefix),A=null!=z,I="never"===y.localePrefix.mode||w&&"as-needed"===y.localePrefix.mode;let S,V,B=H;const E=y.pathnames;if(E){let e;if([e,V]=m(E,H,j),V){const o=E[V],n="string"==typeof o?o:o[j];if(t(n,H))B=h(H,n,V);else{let t;t=e?"string"==typeof o?o:o[e]:V;const a=I?void 0:r(j,y.localePrefix),i=h(H,t,n);S=q(x(i,a,l.nextUrl.search))}}}if(!S)if("/"!==B||A){const e=x(B,U(j),l.nextUrl.search);if(A){const o=x(H,z.prefix,l.nextUrl.search);if("never"===y.localePrefix.mode)S=q(x(H,void 0,l.nextUrl.search));else if(z.exact)if(w&&I)S=q(x(H,void 0,l.nextUrl.search));else if(y.domains){const l=v(g,z.locale,C);S=(null==g?void 0:g.domain)===(null==l?void 0:l.domain)||b?R(e):q(o,null==l?void 0:l.domain)}else S=R(e);else S=q(o)}else S=I?R(e):q(x(H,r(j,y.localePrefix),l.nextUrl.search))}else S=I?R(x(B,U(j),l.nextUrl.search)):q(x(H,r(j,y.localePrefix),l.nextUrl.search));return D.localeDetection&&D.localeCookie&&s(l,S,j,D.localeCookie),"never"!==y.localePrefix.mode&&D.alternateLinks&&y.locales.length>1&&S.headers.set("Link",a({routing:y,localizedPathnames:null!=V&&E?null==E?void 0:E[V]:void 0,request:l,resolvedLocale:j})),S}}export{P as default};
@@ -1 +1 @@
1
- import{COOKIE_LOCALE_NAME as e,COOKIE_SAME_SITE as o,COOKIE_MAX_AGE as t}from"../shared/constants.js";function a(a,s,i){var n;(null===(n=a.cookies.get(e))||void 0===n?void 0:n.value)!==i&&s.cookies.set(e,i,{path:a.nextUrl.basePath||void 0,sameSite:o,maxAge:t})}export{a as default};
1
+ import{COOKIE_LOCALE_NAME as e,COOKIE_SAME_SITE as o,COOKIE_MAX_AGE as t}from"../shared/constants.js";function a(a,s,i,n){var r;(null===(r=a.cookies.get(e))||void 0===r?void 0:r.value)!==i&&s.cookies.set(e,i,{path:a.nextUrl.basePath||void 0,sameSite:o,maxAge:t,..."object"==typeof n&&n})}export{a as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../routing/config.js"),t=require("../shared/constants.js"),l=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),o=require("./resolveLocale.js"),r=require("./syncCookie.js"),i=require("./utils.js");exports.default=function(s,c){var d,f,h,m;const u=a.receiveRoutingConfig(s),x={alternateLinks:null===(d=null!==(f=null==c?void 0:c.alternateLinks)&&void 0!==f?f:s.alternateLinks)||void 0===d||d,localeDetection:null===(h=null!==(m=null==c?void 0:c.localeDetection)&&void 0!==m?m:null==s?void 0:s.localeDetection)||void 0===h||h};return function(a){var s;let c;try{c=decodeURI(a.nextUrl.pathname)}catch(a){return e.NextResponse.next()}const d=i.sanitizePathname(c),{domain:f,locale:h}=o.default(u,x,a.headers,a.cookies,d),m=f?f.defaultLocale===h:h===u.defaultLocale,P=(null===(s=u.domains)||void 0===s?void 0:s.filter((e=>i.isLocaleSupportedOnDomain(h,e))))||[],p=null!=u.domains&&!f;function v(l){const n=new URL(l,a.url);a.nextUrl.basePath&&(n.pathname=i.applyBasePath(n.pathname,a.nextUrl.basePath));const o=new Headers(a.headers);return o.set(t.HEADER_LOCALE_NAME,h),e.NextResponse.rewrite(n,{request:{headers:o}})}function g(t,n){const o=new URL(l.normalizeTrailingSlash(t),a.url);if(P.length>0&&!n&&f){const e=i.getBestMatchingDomain(f,h,P);e&&(n=e.domain,e.defaultLocale===h&&"as-needed"===u.localePrefix.mode&&(o.pathname=i.getNormalizedPathname(o.pathname,u.locales,u.localePrefix)))}var r,s;n&&(o.host=n,a.headers.get("x-forwarded-host")&&(o.protocol=null!==(r=a.headers.get("x-forwarded-proto"))&&void 0!==r?r:a.nextUrl.protocol,o.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(o.pathname=i.applyBasePath(o.pathname,a.nextUrl.basePath)),e.NextResponse.redirect(o.toString())}const L=i.getNormalizedPathname(d,u.locales,u.localePrefix),U=i.getPathnameMatch(d,u.locales,u.localePrefix),q=null!=U,j="never"===u.localePrefix.mode||m&&"as-needed"===u.localePrefix.mode;let k,D,R=L;const w=u.pathnames;if(w){let e;if([e,D]=i.getInternalTemplate(w,L,h),D){const t=w[D],n="string"==typeof t?t:t[h];if(l.matchesPathname(n,L))R=i.formatTemplatePathname(L,n,D);else{let o;o=e?"string"==typeof t?t:t[e]:D;const r=j?void 0:l.getLocalePrefix(h,u.localePrefix),s=i.formatTemplatePathname(L,o,n);k=g(i.formatPathname(s,r,a.nextUrl.search))}}}if(!k)if("/"!==R||q){const e=i.formatPathname(R,i.getLocaleAsPrefix(h),a.nextUrl.search);if(q){const t=i.formatPathname(L,U.prefix,a.nextUrl.search);if("never"===u.localePrefix.mode)k=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(U.exact)if(m&&j)k=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(u.domains){const a=i.getBestMatchingDomain(f,U.locale,P);k=(null==f?void 0:f.domain)===(null==a?void 0:a.domain)||p?v(e):g(t,null==a?void 0:a.domain)}else k=v(e);else k=g(t)}else k=j?v(e):g(i.formatPathname(L,l.getLocalePrefix(h,u.localePrefix),a.nextUrl.search))}else k=j?v(i.formatPathname(R,i.getLocaleAsPrefix(h),a.nextUrl.search)):g(i.formatPathname(L,l.getLocalePrefix(h,u.localePrefix),a.nextUrl.search));return x.localeDetection&&r.default(a,k,h),"never"!==u.localePrefix.mode&&x.alternateLinks&&u.locales.length>1&&k.headers.set("Link",n.default({routing:u,localizedPathnames:null!=D&&w?null==w?void 0:w[D]:void 0,request:a,resolvedLocale:h})),k}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../routing/config.js"),t=require("../shared/constants.js"),l=require("../shared/utils.js"),o=require("./getAlternateLinksHeaderValue.js"),n=require("./resolveLocale.js"),r=require("./syncCookie.js"),i=require("./utils.js");exports.default=function(s,c){var d,u,f,h,m,x;const P=a.receiveRoutingConfig(s),v={alternateLinks:null===(d=null!==(u=null==c?void 0:c.alternateLinks)&&void 0!==u?u:s.alternateLinks)||void 0===d||d,localeDetection:null===(f=null!==(h=null==c?void 0:c.localeDetection)&&void 0!==h?h:null==s?void 0:s.localeDetection)||void 0===f||f,localeCookie:null===(m=null!==(x=null==c?void 0:c.localeCookie)&&void 0!==x?x:null==s?void 0:s.localeCookie)||void 0===m||m};return function(a){var s;let c;try{c=decodeURI(a.nextUrl.pathname)}catch(a){return e.NextResponse.next()}const d=i.sanitizePathname(c),{domain:u,locale:f}=n.default(P,v,a.headers,a.cookies,d),h=u?u.defaultLocale===f:f===P.defaultLocale,m=(null===(s=P.domains)||void 0===s?void 0:s.filter((e=>i.isLocaleSupportedOnDomain(f,e))))||[],x=null!=P.domains&&!u;function p(l){const o=new URL(l,a.url);a.nextUrl.basePath&&(o.pathname=i.applyBasePath(o.pathname,a.nextUrl.basePath));const n=new Headers(a.headers);return n.set(t.HEADER_LOCALE_NAME,f),e.NextResponse.rewrite(o,{request:{headers:n}})}function g(t,o){const n=new URL(l.normalizeTrailingSlash(t),a.url);if(m.length>0&&!o&&u){const e=i.getBestMatchingDomain(u,f,m);e&&(o=e.domain,e.defaultLocale===f&&"as-needed"===P.localePrefix.mode&&(n.pathname=i.getNormalizedPathname(n.pathname,P.locales,P.localePrefix)))}var r,s;o&&(n.host=o,a.headers.get("x-forwarded-host")&&(n.protocol=null!==(r=a.headers.get("x-forwarded-proto"))&&void 0!==r?r:a.nextUrl.protocol,n.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(n.pathname=i.applyBasePath(n.pathname,a.nextUrl.basePath)),e.NextResponse.redirect(n.toString())}const L=i.getNormalizedPathname(d,P.locales,P.localePrefix),U=i.getPathnameMatch(d,P.locales,P.localePrefix),k=null!=U,q="never"===P.localePrefix.mode||h&&"as-needed"===P.localePrefix.mode;let j,C,D=L;const R=P.pathnames;if(R){let e;if([e,C]=i.getInternalTemplate(R,L,f),C){const t=R[C],o="string"==typeof t?t:t[f];if(l.matchesPathname(o,L))D=i.formatTemplatePathname(L,o,C);else{let n;n=e?"string"==typeof t?t:t[e]:C;const r=q?void 0:l.getLocalePrefix(f,P.localePrefix),s=i.formatTemplatePathname(L,n,o);j=g(i.formatPathname(s,r,a.nextUrl.search))}}}if(!j)if("/"!==D||k){const e=i.formatPathname(D,i.getLocaleAsPrefix(f),a.nextUrl.search);if(k){const t=i.formatPathname(L,U.prefix,a.nextUrl.search);if("never"===P.localePrefix.mode)j=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(U.exact)if(h&&q)j=g(i.formatPathname(L,void 0,a.nextUrl.search));else if(P.domains){const a=i.getBestMatchingDomain(u,U.locale,m);j=(null==u?void 0:u.domain)===(null==a?void 0:a.domain)||x?p(e):g(t,null==a?void 0:a.domain)}else j=p(e);else j=g(t)}else j=q?p(e):g(i.formatPathname(L,l.getLocalePrefix(f,P.localePrefix),a.nextUrl.search))}else j=q?p(i.formatPathname(D,i.getLocaleAsPrefix(f),a.nextUrl.search)):g(i.formatPathname(L,l.getLocalePrefix(f,P.localePrefix),a.nextUrl.search));return v.localeDetection&&v.localeCookie&&r.default(a,j,f,v.localeCookie),"never"!==P.localePrefix.mode&&v.alternateLinks&&P.locales.length>1&&j.headers.set("Link",o.default({routing:P,localizedPathnames:null!=C&&R?null==R?void 0:R[C]:void 0,request:a,resolvedLocale:f})),j}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/constants.js");exports.default=function(t,s,o){var a;(null===(a=t.cookies.get(e.COOKIE_LOCALE_NAME))||void 0===a?void 0:a.value)!==o&&s.cookies.set(e.COOKIE_LOCALE_NAME,o,{path:t.nextUrl.basePath||void 0,sameSite:e.COOKIE_SAME_SITE,maxAge:e.COOKIE_MAX_AGE})};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/constants.js");exports.default=function(t,o,s,a){var r;(null===(r=t.cookies.get(e.COOKIE_LOCALE_NAME))||void 0===r?void 0:r.value)!==s&&o.cookies.set(e.COOKIE_LOCALE_NAME,s,{path:t.nextUrl.basePath||void 0,sameSite:e.COOKIE_SAME_SITE,maxAge:e.COOKIE_MAX_AGE,..."object"==typeof a&&a})};
@@ -1,7 +1,21 @@
1
+ import { NextResponse } from 'next/server';
2
+ type ResponseCookieOptions = Pick<NonNullable<Parameters<typeof NextResponse.prototype.cookies.set>['2']>, 'maxAge' | 'domain' | 'expires' | 'partitioned' | 'path' | 'priority' | 'sameSite' | 'secure'>;
1
3
  export type MiddlewareOptions = {
2
- /** Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http */
4
+ /**
5
+ * Sets the `Link` response header to notify search engines about content in other languages (defaults to `true`). See https://developers.google.com/search/docs/specialty/international/localized-versions#http
6
+ * @see https://next-intl-docs.vercel.app/docs/routing/middleware#alternate-links
7
+ **/
3
8
  alternateLinks?: boolean;
4
- /** By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection. */
9
+ /**
10
+ * Can be used to disable the locale cookie or to customize it.
11
+ * @see https://next-intl-docs.vercel.app/docs/routing/middleware#locale-cookie
12
+ */
13
+ localeCookie?: boolean | ResponseCookieOptions;
14
+ /**
15
+ * By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection.
16
+ * @see https://next-intl-docs.vercel.app/docs/routing/middleware#locale-detection
17
+ **/
5
18
  localeDetection?: boolean;
6
19
  };
7
20
  export type ResolvedMiddlewareOptions = Required<MiddlewareOptions>;
21
+ export {};
@@ -1,2 +1,3 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
- export default function syncCookie(request: NextRequest, response: NextResponse, locale: string): void;
2
+ import { MiddlewareOptions } from './config';
3
+ export default function syncCookie(request: NextRequest, response: NextResponse, locale: string, localeCookie: MiddlewareOptions['localeCookie']): void;
@@ -3,6 +3,9 @@ import { RoutingConfigLocalizedNavigation } from '../../routing/config';
3
3
  import { DomainsConfig, LocalePrefixMode, Locales, Pathnames } from '../../routing/types';
4
4
  import { HrefOrHrefWithParams } from '../shared/utils';
5
5
  import ClientLink from './ClientLink';
6
+ /**
7
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
8
+ **/
6
9
  export default function createLocalizedPathnamesNavigation<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode = 'always', AppPathnames extends Pathnames<AppLocales> = never, AppDomains extends DomainsConfig<AppLocales> = never>(routing: RoutingConfigLocalizedNavigation<AppLocales, AppLocalePrefixMode, AppPathnames, AppDomains>): {
7
10
  Link: <Pathname extends keyof AppPathnames>(props: (Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
8
11
  href: string | import("url").UrlObject;
@@ -1,6 +1,9 @@
1
1
  import React, { ReactElement } from 'react';
2
2
  import { RoutingConfigSharedNavigation } from '../../routing/config';
3
3
  import { DomainsConfig, LocalePrefixMode, Locales } from '../../routing/types';
4
+ /**
5
+ * @deprecated Consider switching to `createNavigation` (see https://github.com/amannn/next-intl/pull/1316)
6
+ **/
4
7
  export default function createSharedPathnamesNavigation<AppLocales extends Locales, AppLocalePrefixMode extends LocalePrefixMode, AppDomains extends DomainsConfig<AppLocales> = never>(routing?: RoutingConfigSharedNavigation<AppLocales, AppLocalePrefixMode, AppDomains>): {
5
8
  Link: (props: Omit<Omit<Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
6
9
  href: string | import("url").UrlObject;
@@ -37,6 +37,15 @@ declare function getTranslatorImpl<NestedKey extends NamespaceKeys<IntlMessages,
37
37
  }, [
38
38
  NestedKey
39
39
  ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): any;
40
+ has<TargetKey extends MessageKeys<NestedValueOf<{
41
+ '!': IntlMessages;
42
+ }, [
43
+ NestedKey
44
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
45
+ '!': IntlMessages;
46
+ }, [
47
+ NestedKey
48
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: TargetKey): boolean;
40
49
  };
41
50
  declare const _default: typeof getTranslatorImpl;
42
51
  export default _default;
@@ -37,6 +37,15 @@ declare function getTranslations<NestedKey extends NamespaceKeys<IntlMessages, N
37
37
  }, [
38
38
  NestedKey
39
39
  ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: [TargetKey] extends [never] ? string : TargetKey): any;
40
+ has<TargetKey extends MessageKeys<NestedValueOf<{
41
+ '!': IntlMessages;
42
+ }, [
43
+ NestedKey
44
+ ] extends [never] ? '!' : `!.${NestedKey}`>, NestedKeyOf<NestedValueOf<{
45
+ '!': IntlMessages;
46
+ }, [
47
+ NestedKey
48
+ ] extends [never] ? '!' : `!.${NestedKey}`>>>>(key: [TargetKey] extends [never] ? string : TargetKey): boolean;
40
49
  }>;
41
50
  declare function getTranslations<NestedKey extends NamespaceKeys<IntlMessages, NestedKeyOf<IntlMessages>> = never>(opts?: {
42
51
  locale: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.21.0-canary.0",
3
+ "version": "3.22.0-canary.0",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -87,11 +87,11 @@
87
87
  "dependencies": {
88
88
  "@formatjs/intl-localematcher": "^0.5.4",
89
89
  "negotiator": "^0.6.3",
90
- "use-intl": "^3.21.0-canary.0"
90
+ "use-intl": "^3.22.0-canary.0"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
94
94
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
95
95
  },
96
- "gitHead": "3105da4fefa30e07be10849ca72e515034e5fe9b"
96
+ "gitHead": "be122b24844db127d9495f4f04b3e3551eefd4b3"
97
97
  }