next-intl 3.11.0 → 3.11.2

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/README.md CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  ## Features
23
23
 
24
- Internationalization is an essential part of the user experience. `next-intl` gives you everything you need to get language subtleties right and has always got your back whenever you need to fine-tune a translation.
24
+ Internationalization (i18n) is an essential part of the user experience, therefore `next-intl` gives you all the parts you need to get language nuances right.
25
25
 
26
26
  - 🌟 **ICU message syntax**: Localize your messages with interpolation, cardinal & ordinal plurals, enum-based label selection and rich text.
27
27
  - 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
@@ -32,8 +32,6 @@ Internationalization is an essential part of the user experience. `next-intl` gi
32
32
 
33
33
  ## What does it look like?
34
34
 
35
- This library is based on the premise that messages can be grouped by namespaces (typically a component name).
36
-
37
35
  ```jsx
38
36
  // UserProfile.tsx
39
37
  import {useTranslations} from 'next-intl';
@@ -64,10 +64,12 @@ function createMiddleware(config) {
64
64
  }
65
65
  }
66
66
  if (redirectDomain) {
67
- var _request$headers$get;
68
- urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
69
- urlObj.port = '';
70
67
  urlObj.host = redirectDomain;
68
+ if (request.headers.get('x-forwarded-host')) {
69
+ var _request$headers$get, _request$headers$get2;
70
+ urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
71
+ urlObj.port = (_request$headers$get2 = request.headers.get('x-forwarded-port')) !== null && _request$headers$get2 !== void 0 ? _request$headers$get2 : '';
72
+ }
71
73
  }
72
74
  if (request.nextUrl.basePath) {
73
75
  urlObj.pathname = utils.applyBasePath(urlObj.pathname, request.nextUrl.basePath);
@@ -109,3 +109,4 @@ function resolveLocale(config, requestHeaders, requestCookies, pathname) {
109
109
  }
110
110
 
111
111
  exports.default = resolveLocale;
112
+ exports.getAcceptLanguageLocale = getAcceptLanguageLocale;
@@ -104,7 +104,12 @@ function getRoute(_ref3) {
104
104
  return template;
105
105
  }
106
106
  function getBasePath(pathname) {
107
- return window.location.pathname.replace(pathname, '');
107
+ let windowPathname = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.pathname;
108
+ if (pathname === '/') {
109
+ return windowPathname;
110
+ } else {
111
+ return windowPathname.replace(pathname, '');
112
+ }
108
113
  }
109
114
 
110
115
  exports.compileLocalizedPathname = compileLocalizedPathname;
@@ -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 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
+ import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as t,COOKIE_SAME_SITE as a,COOKIE_MAX_AGE as o,HEADER_LOCALE_NAME as n}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 h,getBestMatchingDomain as m,applyBasePath as v}from"./utils.js";function x(x){const p=function(e){var t,a,o;return{...e,alternateLinks:null===(t=e.alternateLinks)||void 0===t||t,localePrefix:null!==(a=e.localePrefix)&&void 0!==a?a:"always",localeDetection:null===(o=e.localeDetection)||void 0===o||o}}(x);return function(x){var P,U;const g=decodeURI(x.nextUrl.pathname),{domain:L,locale:k}=s(p,x.headers,x.cookies,g),w=p.localeDetection&&(null===(P=x.cookies.get(t))||void 0===P?void 0:P.value)!==k,b=L?L.defaultLocale===k:k===p.defaultLocale,j=(null===(U=p.domains)||void 0===U?void 0:U.filter((e=>i(k,e))))||[],y=null!=p.domains&&!L;function D(t){const a=new URL(t,x.url);return x.nextUrl.basePath&&(a.pathname=v(a.pathname,x.nextUrl.basePath)),e.rewrite(a,function(){const e=new Headers(x.headers);return e.set(n,k),{request:{headers:e}}}())}function R(t,a){const o=new URL(t,x.url);if(j.length>0&&!a){const e=m(L,k,j);e&&(a=e.domain,e.defaultLocale===k&&"as-needed"===p.localePrefix&&o.pathname.startsWith("/".concat(k))&&(o.pathname=c(o.pathname,p.locales)))}var n,l;a&&(o.host=a,x.headers.get("x-forwarded-host")&&(o.protocol=null!==(n=x.headers.get("x-forwarded-proto"))&&void 0!==n?n:x.nextUrl.protocol,o.port=null!==(l=x.headers.get("x-forwarded-port"))&&void 0!==l?l:""));return x.nextUrl.basePath&&(o.pathname=v(o.pathname,x.nextUrl.basePath)),e.redirect(o.toString())}const q=c(g,p.locales),A=d(g,p.locales),H=null!=A;let S,z,I=g;if(p.pathnames){let e;if([e,z]=f(p.pathnames,q,k),z){const t=p.pathnames[z],a="string"==typeof t?t:t[k];if(l(a,q))I=u(q,a,z,A);else{let o;o=e?"string"==typeof t?t:t[e]:z;const n=!H&&b||"never"===p.localePrefix?void 0:k;S=R(h(u(q,o,a,n),x.nextUrl.search))}}}if(!S)if("/"===I){const e=h("/".concat(k),x.nextUrl.search);S="never"===p.localePrefix||b&&"as-needed"===p.localePrefix?D(e):R(e)}else{const e=h(I,x.nextUrl.search);if(H){const t=h(q,x.nextUrl.search);if("never"===p.localePrefix)S=R(t);else if(A===k)if(b&&"as-needed"===p.localePrefix)S=R(t);else if(p.domains){const a=m(L,A,j);S=(null==L?void 0:L.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"===p.localePrefix||b&&("as-needed"===p.localePrefix||p.domains)?D("/".concat(k).concat(e)):R("/".concat(k).concat(e))}var V;(w&&S.cookies.set(t,k,{path:x.nextUrl.basePath||void 0,sameSite:a,maxAge:o}),"never"!==p.localePrefix&&p.alternateLinks&&p.locales.length>1)&&S.headers.set("Link",r({config:p,localizedPathnames:null!=z?null===(V=p.pathnames)||void 0===V?void 0:V[z]:void 0,request:x,resolvedLocale:k}));return S}}export{x as default};
@@ -1 +1 @@
1
- import{match as t}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as e}from"../shared/constants.js";import{getFirstPathnameSegment as n,findCaseInsensitiveLocale as a,isLocaleSupportedOnDomain as l,getHost as c}from"./utils.js";function r(l,c,r,i){let s,{defaultLocale:u,localeDetection:f,locales:d}=l;if(i){const t=n(i),o=a(t,d);o&&(s=o)}if(!s&&f&&r&&r.has(e)){var m;const t=null===(m=r.get(e))||void 0===m?void 0:m.value;t&&d.includes(t)&&(s=t)}return!s&&f&&c&&(s=function(e,n,a){let l;const c=new o({headers:{"accept-language":e.get("accept-language")||void 0}}).languages();try{l=t(c,n,a)}catch(t){}return l}(c,d,u)),s||(s=u),s}function i(t,o,e,n){const{domains:a}=t,i=r(t,o,e,n);if(a){const t=function(t,o){var e;let n=c(t);if(n=null===(e=n)||void 0===e?void 0:e.replace(/:\d+$/,""),n&&o)return o.find((t=>t.domain===n))}(o,a),e=n&&n.startsWith("/".concat(i));if(t)return{locale:l(i,t)||e?i:t.defaultLocale,domain:t}}return{locale:i}}function s(t,o,e,n){return t.domains?i(t,o,e,n):{locale:r(t,o,e,n)}}export{s as default};
1
+ import{match as t}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as e}from"../shared/constants.js";import{getFirstPathnameSegment as n,findCaseInsensitiveLocale as a,isLocaleSupportedOnDomain as l,getHost as c}from"./utils.js";function r(e,n,a){let l;const c=new o({headers:{"accept-language":e.get("accept-language")||void 0}}).languages();try{l=t(c,n,a)}catch(t){}return l}function i(t,o,l,c){let i,{defaultLocale:s,localeDetection:u,locales:f}=t;if(c){const t=n(c),o=a(t,f);o&&(i=o)}if(!i&&u&&l&&l.has(e)){var d;const t=null===(d=l.get(e))||void 0===d?void 0:d.value;t&&f.includes(t)&&(i=t)}return!i&&u&&o&&(i=r(o,f,s)),i||(i=s),i}function s(t,o,e,n){const{domains:a}=t,r=i(t,o,e,n);if(a){const t=function(t,o){var e;let n=c(t);if(n=null===(e=n)||void 0===e?void 0:e.replace(/:\d+$/,""),n&&o)return o.find((t=>t.domain===n))}(o,a),e=n&&n.startsWith("/".concat(r));if(t)return{locale:l(r,t)||e?r:t.defaultLocale,domain:t}}return{locale:r}}function u(t,o,e,n){return t.domains?s(t,o,e,n):{locale:i(t,o,e,n)}}export{u as default,r as getAcceptLanguageLocale};
@@ -1 +1 @@
1
- import{unlocalizePathname as t,matchesPathname as n}from"../../shared/utils.js";function e(t){return"string"==typeof t?{pathname:t}:t}function r(t){function n(t){return String(t)}const e=new URLSearchParams;for(const[r,a]of Object.entries(t))Array.isArray(a)?a.forEach((t=>{e.append(r,n(t))})):e.set(r,n(a));return"?"+e.toString()}function a(t){let{pathname:n,locale:e,params:a,pathnames:o,query:c}=t;function i(t){let n=o[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[e];let o=n;if(a&&Object.entries(a).forEach((t=>{let[n,e]=t;o=Array.isArray(e)?o.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),e.map((t=>String(t))).join("/")):o.replace("[".concat(n,"]"),String(e))})),o.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(a)));return c&&(o+=r(c)),o}if("string"==typeof n){return s(i(n))}{const{pathname:t,...e}=n;return{...e,pathname:s(i(t))}}}function o(e){var r;let{locale:a,pathname:o,pathnames:c}=e;const i=t(decodeURI(o),a);let s=null===(r=Object.entries(c).find((t=>{let[,e]=t;const r="string"!=typeof e?e[a]:e;return n(r,i)})))||void 0===r?void 0:r[0];return s||(s=o),s}function c(t){return window.location.pathname.replace(t,"")}export{a as compileLocalizedPathname,c as getBasePath,o as getRoute,e as normalizeNameOrNameWithParams,r as serializeSearchParams};
1
+ import{unlocalizePathname as t,matchesPathname as n}from"../../shared/utils.js";function e(t){return"string"==typeof t?{pathname:t}:t}function r(t){function n(t){return String(t)}const e=new URLSearchParams;for(const[r,a]of Object.entries(t))Array.isArray(a)?a.forEach((t=>{e.append(r,n(t))})):e.set(r,n(a));return"?"+e.toString()}function a(t){let{pathname:n,locale:e,params:a,pathnames:o,query:i}=t;function c(t){let n=o[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[e];let o=n;if(a&&Object.entries(a).forEach((t=>{let[n,e]=t;o=Array.isArray(e)?o.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),e.map((t=>String(t))).join("/")):o.replace("[".concat(n,"]"),String(e))})),o.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(a)));return i&&(o+=r(i)),o}if("string"==typeof n){return s(c(n))}{const{pathname:t,...e}=n;return{...e,pathname:s(c(t))}}}function o(e){var r;let{locale:a,pathname:o,pathnames:i}=e;const c=t(decodeURI(o),a);let s=null===(r=Object.entries(i).find((t=>{let[,e]=t;const r="string"!=typeof e?e[a]:e;return n(r,c)})))||void 0===r?void 0:r[0];return s||(s=o),s}function i(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===t?n:n.replace(t,"")}export{a as compileLocalizedPathname,i as getBasePath,o as getRoute,e as normalizeNameOrNameWithParams,r as serializeSearchParams};
@@ -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 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}};
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 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,u),{request:{headers:e}}}())}function P(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,i;t&&(n.host=t,r.headers.get("x-forwarded-host")&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port=null!==(i=r.headers.get("x-forwarded-port"))&&void 0!==i?i:""));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=P(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?x(e):P(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=P(a);else if(L===u)if(m&&"as-needed"===s.localePrefix)U=P(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?x(e):P(a,null==t?void 0:t.domain)}else U=x(e);else U=P("/".concat(u).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?x("/".concat(u).concat(e)):P("/".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}};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),n=require("../shared/constants.js"),a=require("./utils.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(t);function i(t,o,i,l){let c,{defaultLocale:u,localeDetection:s,locales:d}=t;if(l){const e=a.getFirstPathnameSegment(l),t=a.findCaseInsensitiveLocale(e,d);t&&(c=t)}if(!c&&s&&i&&i.has(n.COOKIE_LOCALE_NAME)){var f;const e=null===(f=i.get(n.COOKIE_LOCALE_NAME))||void 0===f?void 0:f.value;e&&d.includes(e)&&(c=e)}return!c&&s&&o&&(c=function(t,n,a){let o;const i=new r.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{o=e.match(i,n,a)}catch(e){}return o}(o,d,u)),c||(c=u),c}function l(e,t,n,o){const{domains:r}=e,l=i(e,t,n,o);if(r){const e=function(e,t){var n;let o=a.getHost(e);if(o=null===(n=o)||void 0===n?void 0:n.replace(/:\d+$/,""),o&&t)return t.find((e=>e.domain===o))}(t,r),n=o&&o.startsWith("/".concat(l));if(e)return{locale:a.isLocaleSupportedOnDomain(l,e)||n?l:e.defaultLocale,domain:e}}return{locale:l}}exports.default=function(e,t,n,a){return e.domains?l(e,t,n,a):{locale:i(e,t,n,a)}};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),a=require("../shared/constants.js"),n=require("./utils.js");function o(e){return e&&e.__esModule?e:{default:e}}var r=o(t);function c(t,a,n){let o;const c=new r.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{o=e.match(c,a,n)}catch(e){}return o}function l(e,t,o,r){let l,{defaultLocale:i,localeDetection:u,locales:s}=e;if(r){const e=n.getFirstPathnameSegment(r),t=n.findCaseInsensitiveLocale(e,s);t&&(l=t)}if(!l&&u&&o&&o.has(a.COOKIE_LOCALE_NAME)){var d;const e=null===(d=o.get(a.COOKIE_LOCALE_NAME))||void 0===d?void 0:d.value;e&&s.includes(e)&&(l=e)}return!l&&u&&t&&(l=c(t,s,i)),l||(l=i),l}function i(e,t,a,o){const{domains:r}=e,c=l(e,t,a,o);if(r){const e=function(e,t){var a;let o=n.getHost(e);if(o=null===(a=o)||void 0===a?void 0:a.replace(/:\d+$/,""),o&&t)return t.find((e=>e.domain===o))}(t,r),a=o&&o.startsWith("/".concat(c));if(e)return{locale:n.isLocaleSupportedOnDomain(c,e)||a?c:e.defaultLocale,domain:e}}return{locale:c}}exports.default=function(e,t,a,n){return e.domains?i(e,t,a,n):{locale:l(e,t,a,n)}},exports.getAcceptLanguageLocale=c;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:i}=e;function c(e){let t=o[e];return t||(t=e),t}function s(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),i&&(r+=t(i)),r}if("string"==typeof r){return s(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:s(c(e))}}},exports.getBasePath=function(e){return window.location.pathname.replace(e,"")},exports.getRoute=function(t){var r;let{locale:n,pathname:a,pathnames:o}=t;const i=e.unlocalizePathname(decodeURI(a),n);let c=null===(r=Object.entries(o).find((t=>{let[,r]=t;const a="string"!=typeof r?r[n]:r;return e.matchesPathname(a,i)})))||void 0===r?void 0:r[0];return c||(c=a),c},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:i}=e;function c(e){let t=o[e];return t||(t=e),t}function s(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),i&&(r+=t(i)),r}if("string"==typeof r){return s(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:s(c(e))}}},exports.getBasePath=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===e?t:t.replace(e,"")},exports.getRoute=function(t){var r;let{locale:n,pathname:a,pathnames:o}=t;const i=e.unlocalizePathname(decodeURI(a),n);let c=null===(r=Object.entries(o).find((t=>{let[,r]=t;const a="string"!=typeof r?r[n]:r;return e.matchesPathname(a,i)})))||void 0===r?void 0:r[0];return c||(c=a),c},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
@@ -1,6 +1,7 @@
1
1
  import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
2
  import { AllLocales } from '../shared/types';
3
3
  import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
4
+ export declare function getAcceptLanguageLocale<Locales extends AllLocales>(requestHeaders: Headers, locales: Locales, defaultLocale: string): string | undefined;
4
5
  export default function resolveLocale<Locales extends AllLocales>(config: MiddlewareConfigWithDefaults<Locales>, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
5
6
  locale: Locales[number];
6
7
  domain?: DomainConfig<Locales>;
@@ -48,5 +48,5 @@ export declare function getRoute<Locales extends AllLocales>({ locale, pathname,
48
48
  pathname: string;
49
49
  pathnames: Pathnames<Locales>;
50
50
  }): string;
51
- export declare function getBasePath(pathname: string): string;
51
+ export declare function getBasePath(pathname: string, windowPathname?: string): string;
52
52
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.11.0",
3
+ "version": "3.11.2",
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.11.0"
85
+ "use-intl": "^3.11.2"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -122,11 +122,11 @@
122
122
  },
123
123
  {
124
124
  "path": "dist/production/navigation.react-client.js",
125
- "limit": "2.94 KB"
125
+ "limit": "2.96 KB"
126
126
  },
127
127
  {
128
128
  "path": "dist/production/navigation.react-server.js",
129
- "limit": "3.03 KB"
129
+ "limit": "3.06 KB"
130
130
  },
131
131
  {
132
132
  "path": "dist/production/server.react-client.js",
@@ -141,5 +141,5 @@
141
141
  "limit": "5.95 KB"
142
142
  }
143
143
  ],
144
- "gitHead": "5db8a1d7acd8d60f241828f62dab3bcfbd411007"
144
+ "gitHead": "672eccf549b25116a161f21ebad075fe4ae81bc8"
145
145
  }