next-intl 3.9.4 → 3.10.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.
- package/dist/development/middleware/middleware.js +12 -3
- package/dist/development/middleware/utils.js +30 -9
- package/dist/development/shared/utils.js +3 -3
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/production/shared/utils.js +1 -1
- package/dist/types/src/middleware/utils.d.ts +1 -1
- package/package.json +4 -4
|
@@ -80,15 +80,24 @@ function createMiddleware(config) {
|
|
|
80
80
|
let pathname = request.nextUrl.pathname;
|
|
81
81
|
if (configWithDefaults.pathnames) {
|
|
82
82
|
let resolvedTemplateLocale;
|
|
83
|
-
[resolvedTemplateLocale
|
|
83
|
+
[resolvedTemplateLocale, internalTemplateName] = utils.getInternalTemplate(configWithDefaults.pathnames, normalizedPathname, locale);
|
|
84
84
|
if (internalTemplateName) {
|
|
85
85
|
const pathnameConfig = configWithDefaults.pathnames[internalTemplateName];
|
|
86
86
|
const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[locale];
|
|
87
87
|
if (utils$1.matchesPathname(localeTemplate, normalizedPathname)) {
|
|
88
88
|
pathname = utils.formatTemplatePathname(normalizedPathname, localeTemplate, internalTemplateName, pathLocale);
|
|
89
89
|
} else {
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
let sourceTemplate;
|
|
91
|
+
if (resolvedTemplateLocale) {
|
|
92
|
+
// A localized pathname from another locale has matched
|
|
93
|
+
sourceTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[resolvedTemplateLocale];
|
|
94
|
+
} else {
|
|
95
|
+
// An internal pathname has matched that
|
|
96
|
+
// doesn't have a localized pathname
|
|
97
|
+
sourceTemplate = internalTemplateName;
|
|
98
|
+
}
|
|
99
|
+
const localePrefix = (hasLocalePrefix || !hasMatchedDefaultLocale) && configWithDefaults.localePrefix !== 'never' ? locale : undefined;
|
|
100
|
+
response = redirect(utils.getPathWithSearch(utils.formatTemplatePathname(normalizedPathname, sourceTemplate, localeTemplate, localePrefix), request.nextUrl.search));
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
}
|
|
@@ -7,7 +7,8 @@ var utils = require('../shared/utils.js');
|
|
|
7
7
|
function getFirstPathnameSegment(pathname) {
|
|
8
8
|
return pathname.split('/')[1];
|
|
9
9
|
}
|
|
10
|
-
function getInternalTemplate(pathnames, pathname) {
|
|
10
|
+
function getInternalTemplate(pathnames, pathname, locale) {
|
|
11
|
+
// Try to find a localized pathname that matches
|
|
11
12
|
for (const [internalPathname, localizedPathnamesOrPathname] of Object.entries(pathnames)) {
|
|
12
13
|
if (typeof localizedPathnamesOrPathname === 'string') {
|
|
13
14
|
const localizedPathname = localizedPathnamesOrPathname;
|
|
@@ -15,13 +16,33 @@ function getInternalTemplate(pathnames, pathname) {
|
|
|
15
16
|
return [undefined, internalPathname];
|
|
16
17
|
}
|
|
17
18
|
} else {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// Prefer the entry with the current locale in case multiple
|
|
20
|
+
// localized pathnames match the current pathname
|
|
21
|
+
const sortedEntries = Object.entries(localizedPathnamesOrPathname);
|
|
22
|
+
const curLocaleIndex = sortedEntries.findIndex(_ref => {
|
|
23
|
+
let [entryLocale] = _ref;
|
|
24
|
+
return entryLocale === locale;
|
|
25
|
+
});
|
|
26
|
+
if (curLocaleIndex > 0) {
|
|
27
|
+
sortedEntries.unshift(sortedEntries.splice(curLocaleIndex, 1)[0]);
|
|
28
|
+
}
|
|
29
|
+
for (const [entryLocale, entryPathname] of sortedEntries) {
|
|
30
|
+
if (utils.matchesPathname(entryPathname, pathname)) {
|
|
31
|
+
return [entryLocale, internalPathname];
|
|
21
32
|
}
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
}
|
|
36
|
+
|
|
37
|
+
// Try to find an internal pathname that matches (this can be the case
|
|
38
|
+
// if all localized pathnames are different from the internal pathnames).
|
|
39
|
+
for (const internalPathname of Object.keys(pathnames)) {
|
|
40
|
+
if (utils.matchesPathname(internalPathname, pathname)) {
|
|
41
|
+
return [undefined, internalPathname];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// No match
|
|
25
46
|
return [undefined, undefined];
|
|
26
47
|
}
|
|
27
48
|
function formatTemplatePathname(sourcePathname, sourceTemplate, targetTemplate, localePrefix) {
|
|
@@ -76,10 +97,10 @@ function formatPathname(template, params) {
|
|
|
76
97
|
|
|
77
98
|
// Simplify syntax for optional catchall ('[[...slug]]') so
|
|
78
99
|
// we can replace the value with simple interpolation
|
|
79
|
-
template = template.
|
|
100
|
+
template = template.replace(/\[\[/g, '[').replace(/\]\]/g, ']');
|
|
80
101
|
let result = template;
|
|
81
|
-
Object.entries(params).forEach(
|
|
82
|
-
let [key, value] =
|
|
102
|
+
Object.entries(params).forEach(_ref2 => {
|
|
103
|
+
let [key, value] = _ref2;
|
|
83
104
|
result = result.replace("[".concat(key, "]"), value);
|
|
84
105
|
});
|
|
85
106
|
return result;
|
|
@@ -92,8 +113,8 @@ function getPathWithSearch(pathname, search) {
|
|
|
92
113
|
return pathWithSearch;
|
|
93
114
|
}
|
|
94
115
|
function getHost(requestHeaders) {
|
|
95
|
-
var
|
|
96
|
-
return (
|
|
116
|
+
var _ref3, _requestHeaders$get;
|
|
117
|
+
return (_ref3 = (_requestHeaders$get = requestHeaders.get('x-forwarded-host')) !== null && _requestHeaders$get !== void 0 ? _requestHeaders$get : requestHeaders.get('host')) !== null && _ref3 !== void 0 ? _ref3 : undefined;
|
|
97
118
|
}
|
|
98
119
|
function isLocaleSupportedOnDomain(locale, domain) {
|
|
99
120
|
return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
|
|
@@ -68,11 +68,11 @@ pathname) {
|
|
|
68
68
|
function templateToRegex(template) {
|
|
69
69
|
const regexPattern = template
|
|
70
70
|
// Replace optional catchall ('[[...slug]]')
|
|
71
|
-
.
|
|
71
|
+
.replace(/\[\[(\.\.\.[^\]]+)\]\]/g, '?(.*)')
|
|
72
72
|
// Replace catchall ('[...slug]')
|
|
73
|
-
.
|
|
73
|
+
.replace(/\[(\.\.\.[^\]]+)\]/g, '(.+)')
|
|
74
74
|
// Replace regular parameter ('[slug]')
|
|
75
|
-
.
|
|
75
|
+
.replace(/\[([^\]]+)\]/g, '([^/]+)');
|
|
76
76
|
return new RegExp("^".concat(regexPattern, "$"));
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -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
|
|
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 +1 @@
|
|
|
1
|
-
import{matchesPathname as n,templateToRegex as t}from"../shared/utils.js";function e(n){return n.split("/")[1]}function o(t,e){for(const[
|
|
1
|
+
import{matchesPathname as n,templateToRegex as t}from"../shared/utils.js";function e(n){return n.split("/")[1]}function o(t,e,o){for(const[r,c]of Object.entries(t))if("string"==typeof c){if(n(c,e))return[void 0,r]}else{const t=Object.entries(c),i=t.findIndex((n=>{let[t]=n;return t===o}));i>0&&t.unshift(t.splice(i,1)[0]);for(const[o,c]of t)if(n(c,e))return[o,r]}for(const o of Object.keys(t))if(n(o,e))return[void 0,o];return[void 0,void 0]}function r(n,t,e,o){const r=u(t,n);let c="";return o&&(c="/".concat(o)),c+=f(e,r),c=p(c),c}function c(n,t){n.endsWith("/")||(n+="/");const e=n.match(new RegExp("^/(".concat(t.join("|"),")/(.*)"),"i"));let o=e?"/"+e[2]:n;return"/"!==o&&(o=p(o)),o}function i(n,t){return t.find((t=>t.toLowerCase()===n.toLowerCase()))}function l(n,t){const o=e(n);return i(o,t)?o:void 0}function u(n,e){const o=t(n).exec(e);if(!o)return;const r={};for(let t=1;t<o.length;t++){var c;const e=null===(c=n.match(/\[([^\]]+)\]/g))||void 0===c?void 0:c[t-1].replace(/[[\]]/g,"");e&&(r[e]=o[t])}return r}function f(n,t){if(!t)return n;let e=n=n.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((n=>{let[t,o]=n;e=e.replace("[".concat(t,"]"),o)})),e}function s(n,t){let e=n;return t&&(e+=t),e}function a(n){var t,e;return null!==(t=null!==(e=n.get("x-forwarded-host"))&&void 0!==e?e:n.get("host"))&&void 0!==t?t:void 0}function d(n,t){return t.defaultLocale===n||!t.locales||t.locales.includes(n)}function v(n,t,e){let o;return n&&d(t,n)&&(o=n),o||(o=e.find((n=>n.defaultLocale===t))),o||(o=e.find((n=>null!=n.locales&&n.locales.includes(t)))),o||null!=(null==n?void 0:n.locales)||(o=n),o||(o=e.find((n=>!n.locales))),o}function h(n,t){return p(t+n)}function p(n){return n.endsWith("/")&&(n=n.slice(0,-1)),n}export{h as applyBasePath,i as findCaseInsensitiveLocale,f as formatPathname,r as formatTemplatePathname,v as getBestMatchingDomain,e as getFirstPathnameSegment,a as getHost,o as getInternalTemplate,c as getNormalizedPathname,s as getPathWithSearch,l as getPathnameLocale,u as getRouteParams,d as isLocaleSupportedOnDomain};
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,
|
|
1
|
+
function t(t){const n="object"==typeof t?t.pathname:t;return null!=n&&!n.startsWith("/")}function n(t){if("object"==typeof t)return null==t.host&&null==t.hostname;return!/^[a-z]+:/i.test(t)}function e(e,c){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c,a=arguments.length>3?arguments[3]:void 0;if(!n(e)||t(e))return e;const l=c!==o,i=null==c||u(c,a);return(l||i)&&null!=c?r(e,c):e}function r(t,n){let e;return"string"==typeof t?e=o(n,t):(e={...t},t.pathname&&(e.pathname=o(n,t.pathname))),e}function c(t,n){return t.replace(new RegExp("^/".concat(n)),"")||"/"}function o(t,n){let e="/"+t;return/^\/(\?.*)?$/.test(n)&&(n=n.slice(1)),e+=n,e}function u(t,n){const e="/".concat(t);return n===e||n.startsWith("".concat(e,"/"))}function a(t,n){return l(t).test(n)}function l(t){const n=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(n,"$"))}export{u as hasPathnamePrefixed,n as isLocalHref,t as isRelativeHref,e as localizeHref,a as matchesPathname,r as prefixHref,o as prefixPathname,l as templateToRegex,c as unlocalizePathname};
|
|
@@ -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:
|
|
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 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(e){return e.split("/")[1]}function n(e,t){return t.find((t=>t.toLowerCase()===e.toLowerCase()))}function o(t,n){const o=e.templateToRegex(t).exec(n);if(!o)return;const r={};for(let e=1;e<o.length;e++){var a;const n=null===(a=t.match(/\[([^\]]+)\]/g))||void 0===a?void 0:a[e-1].replace(/[[\]]/g,"");n&&(r[n]=o[e])}return r}function r(e,t){if(!t)return e;let n=e=e.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(e){return e.split("/")[1]}function n(e,t){return t.find((t=>t.toLowerCase()===e.toLowerCase()))}function o(t,n){const o=e.templateToRegex(t).exec(n);if(!o)return;const r={};for(let e=1;e<o.length;e++){var a;const n=null===(a=t.match(/\[([^\]]+)\]/g))||void 0===a?void 0:a[e-1].replace(/[[\]]/g,"");n&&(r[n]=o[e])}return r}function r(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((e=>{let[t,o]=e;n=n.replace("[".concat(t,"]"),o)})),n}function a(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}function s(e){return e.endsWith("/")&&(e=e.slice(0,-1)),e}exports.applyBasePath=function(e,t){return s(t+e)},exports.findCaseInsensitiveLocale=n,exports.formatPathname=r,exports.formatTemplatePathname=function(e,t,n,a){const c=o(t,e);let i="";return a&&(i="/".concat(a)),i+=r(n,c),i=s(i),i},exports.getBestMatchingDomain=function(e,t,n){let o;return e&&a(t,e)&&(o=e),o||(o=n.find((e=>e.defaultLocale===t))),o||(o=n.find((e=>null!=e.locales&&e.locales.includes(t)))),o||null!=(null==e?void 0:e.locales)||(o=e),o||(o=n.find((e=>!e.locales))),o},exports.getFirstPathnameSegment=t,exports.getHost=function(e){var t,n;return null!==(t=null!==(n=e.get("x-forwarded-host"))&&void 0!==n?n:e.get("host"))&&void 0!==t?t:void 0},exports.getInternalTemplate=function(t,n,o){for(const[r,a]of Object.entries(t))if("string"==typeof a){const t=a;if(e.matchesPathname(t,n))return[void 0,r]}else{const t=Object.entries(a),s=t.findIndex((e=>{let[t]=e;return t===o}));s>0&&t.unshift(t.splice(s,1)[0]);for(const[o,a]of t)if(e.matchesPathname(a,n))return[o,r]}for(const o of Object.keys(t))if(e.matchesPathname(o,n))return[void 0,o];return[void 0,void 0]},exports.getNormalizedPathname=function(e,t){e.endsWith("/")||(e+="/");const n=e.match(new RegExp("^/(".concat(t.join("|"),")/(.*)"),"i"));let o=n?"/"+n[2]:e;return"/"!==o&&(o=s(o)),o},exports.getPathWithSearch=function(e,t){let n=e;return t&&(n+=t),n},exports.getPathnameLocale=function(e,o){const r=t(e);return n(r,o)?r:void 0},exports.getRouteParams=o,exports.isLocaleSupportedOnDomain=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(e,t){let n;return"string"==typeof e?n=r(t,e):(n={...e},e.pathname&&(n.pathname=r(t,e.pathname))),n}function r(e,t){let n="/"+e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function o(e,t){const n="/".concat(e);return t===n||t.startsWith("".concat(n,"/"))}function a(e){const t=e.
|
|
1
|
+
"use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(e,t){let n;return"string"==typeof e?n=r(t,e):(n={...e},e.pathname&&(n.pathname=r(t,e.pathname))),n}function r(e,t){let n="/"+e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function o(e,t){const n="/".concat(e);return t===n||t.startsWith("".concat(n,"/"))}function a(e){const t=e.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasPathnamePrefixed=o,exports.isLocalHref=t,exports.isRelativeHref=e,exports.localizeHref=function(r,a){let c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:a,s=arguments.length>3?arguments[3]:void 0;if(!t(r)||e(r))return r;const l=a!==c,u=null==a||o(a,s);return(l||u)&&null!=a?n(r,a):r},exports.matchesPathname=function(e,t){return a(e).test(t)},exports.prefixHref=n,exports.prefixPathname=r,exports.templateToRegex=a,exports.unlocalizePathname=function(e,t){return e.replace(new RegExp("^/".concat(t)),"")||"/"};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AllLocales } from '../shared/types';
|
|
2
2
|
import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
|
|
3
3
|
export declare function getFirstPathnameSegment(pathname: string): string;
|
|
4
|
-
export declare function getInternalTemplate<Locales extends AllLocales, Pathnames extends NonNullable<MiddlewareConfigWithDefaults<Locales>['pathnames']>>(pathnames: Pathnames, pathname: string): [Locales[number] | undefined, keyof Pathnames | undefined];
|
|
4
|
+
export declare function getInternalTemplate<Locales extends AllLocales, Pathnames extends NonNullable<MiddlewareConfigWithDefaults<Locales>['pathnames']>>(pathnames: Pathnames, pathname: string, locale: Locales[number]): [Locales[number] | undefined, keyof Pathnames | undefined];
|
|
5
5
|
export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, localePrefix?: string): string;
|
|
6
6
|
/**
|
|
7
7
|
* Removes potential locales from the pathname.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
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.
|
|
85
|
+
"use-intl": "^3.10.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -138,8 +138,8 @@
|
|
|
138
138
|
},
|
|
139
139
|
{
|
|
140
140
|
"path": "dist/production/middleware.js",
|
|
141
|
-
"limit": "5.
|
|
141
|
+
"limit": "5.9 KB"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "9dd129cdd72c8ac6704b2c9776d018e8db7a758e"
|
|
145
145
|
}
|