next-intl 3.19.2 → 3.19.3
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/getAlternateLinksHeaderValue.js +1 -1
- package/dist/development/middleware/utils.js +7 -4
- package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/types/src/middleware/utils.d.ts +1 -1
- package/package.json +3 -3
|
@@ -39,7 +39,7 @@ function getAlternateLinksHeaderValue(_ref) {
|
|
|
39
39
|
return pathname;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
const links = utils.getLocalePrefixes(routing.locales, routing.localePrefix).flatMap(_ref2 => {
|
|
42
|
+
const links = utils.getLocalePrefixes(routing.locales, routing.localePrefix, false).flatMap(_ref2 => {
|
|
43
43
|
let [locale, prefix] = _ref2;
|
|
44
44
|
function prefixPathname(pathname) {
|
|
45
45
|
if (pathname === '/') {
|
|
@@ -79,13 +79,16 @@ function getNormalizedPathname(pathname, locales, localePrefix) {
|
|
|
79
79
|
return result;
|
|
80
80
|
}
|
|
81
81
|
function getLocalePrefixes(locales, localePrefix) {
|
|
82
|
-
|
|
82
|
+
let sort = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
83
|
+
const prefixes = locales.map(locale => [locale, utils.getLocalePrefix(locale, localePrefix)]);
|
|
84
|
+
if (sort) {
|
|
85
|
+
// More specific ones first
|
|
86
|
+
prefixes.sort((a, b) => b[1].length - a[1].length);
|
|
87
|
+
}
|
|
88
|
+
return prefixes;
|
|
83
89
|
}
|
|
84
90
|
function getPathnameMatch(pathname, locales, localePrefix) {
|
|
85
91
|
const localePrefixes = getLocalePrefixes(locales, localePrefix);
|
|
86
|
-
|
|
87
|
-
// More specific ones first
|
|
88
|
-
localePrefixes.sort((a, b) => b[1].length - a[1].length);
|
|
89
92
|
for (const [locale, prefix] of localePrefixes) {
|
|
90
93
|
let exact, matches;
|
|
91
94
|
if (pathname === prefix || pathname.startsWith(prefix + '/')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function c(c){var m;let{localizedPathnames:p,request:s,resolvedLocale:i,routing:f}=c;const h=s.nextUrl.clone(),u=a(s.headers);function d(a,t){return a.pathname=e(a.pathname),s.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,s.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(t,'"')}function x(e,a){return p&&"object"==typeof p?r(e,p[i],p[a]):e}u&&(h.port="",h.host=u),h.protocol=null!==(m=s.headers.get("x-forwarded-proto"))&&void 0!==m?m:h.protocol,h.pathname=t(h.pathname,f.locales,f.localePrefix);const w=o(f.locales,f.localePrefix).flatMap((e=>{let a,[t,o]=e;function l(e){return"/"===e?o:o+e}if(f.domains){return(f.domains.filter((e=>n(t,e)))||[]).map((e=>(a=new URL(h),a.port="",a.host=e.domain,a.pathname=x(h.pathname,t),t===e.defaultLocale&&"always"!==f.localePrefix.mode||(a.pathname=l(a.pathname)),d(a,t))))}{let e;e=p&&"object"==typeof p?x(h.pathname,t):h.pathname,t===f.defaultLocale&&"always"!==f.localePrefix.mode||(e=l(e)),a=new URL(e,h)}return d(a,t)}));if(!f.domains&&("always"!==f.localePrefix.mode||"/"===h.pathname)){const e=new URL(x(h.pathname,f.defaultLocale),h);w.push(d(e,"x-default"))}return w.join(", ")}export{c as default};
|
|
1
|
+
import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function c(c){var m;let{localizedPathnames:p,request:s,resolvedLocale:i,routing:f}=c;const h=s.nextUrl.clone(),u=a(s.headers);function d(a,t){return a.pathname=e(a.pathname),s.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,s.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(t,'"')}function x(e,a){return p&&"object"==typeof p?r(e,p[i],p[a]):e}u&&(h.port="",h.host=u),h.protocol=null!==(m=s.headers.get("x-forwarded-proto"))&&void 0!==m?m:h.protocol,h.pathname=t(h.pathname,f.locales,f.localePrefix);const w=o(f.locales,f.localePrefix,!1).flatMap((e=>{let a,[t,o]=e;function l(e){return"/"===e?o:o+e}if(f.domains){return(f.domains.filter((e=>n(t,e)))||[]).map((e=>(a=new URL(h),a.port="",a.host=e.domain,a.pathname=x(h.pathname,t),t===e.defaultLocale&&"always"!==f.localePrefix.mode||(a.pathname=l(a.pathname)),d(a,t))))}{let e;e=p&&"object"==typeof p?x(h.pathname,t):h.pathname,t===f.defaultLocale&&"always"!==f.localePrefix.mode||(e=l(e)),a=new URL(e,h)}return d(a,t)}));if(!f.domains&&("always"!==f.localePrefix.mode||"/"===h.pathname)){const e=new URL(x(h.pathname,f.defaultLocale),h);w.push(d(e,"x-default"))}return w.join(", ")}export{c as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getSortedPathnames as e,matchesPathname as t,normalizeTrailingSlash as n,getLocalePrefix as
|
|
1
|
+
import{getSortedPathnames as e,matchesPathname as t,normalizeTrailingSlash as n,getLocalePrefix as o,templateToRegex as r,prefixPathname as c}from"../shared/utils.js";function l(n,o,r){const c=e(Object.keys(n));for(const e of c){const c=n[e];if("string"==typeof c){if(t(c,o))return[void 0,e]}else{const n=Object.entries(c),l=n.findIndex((e=>{let[t]=e;return t===r}));l>0&&n.unshift(n.splice(l,1)[0]);for(const[r,c]of n)if(t(c,o))return[r,e]}}for(const e of Object.keys(n))if(t(e,o))return[void 0,e];return[void 0,void 0]}function i(e,t,o,r){let c="";return c+=d(o,a(t,e)),c=n(c),c}function u(e,t,o){e.endsWith("/")||(e+="/");const r=s(t,o),c=new RegExp("^(".concat(r.map((e=>{let[,t]=e;return t.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),l=e.match(c);let i=l?"/"+l[2]:e;return"/"!==i&&(i=n(i)),i}function s(e,t){let n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const r=e.map((e=>[e,o(e,t)]));return n&&r.sort(((e,t)=>t[1].length-e[1].length)),r}function f(e,t,n){const o=s(t,n);for(const[t,n]of o){let o,r;if(e===n||e.startsWith(n+"/"))o=r=!0;else{const t=e.toLowerCase(),c=n.toLowerCase();(t===c||t.startsWith(c+"/"))&&(o=!1,r=!0)}if(r)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:o}}}function a(e,t){const o=n(t),c=n(e),l=r(c).exec(o);if(!l)return;const i={};for(let e=1;e<l.length;e++){var u;const t=null===(u=c.match(/\[([^\]]+)\]/g))||void 0===u?void 0:u[e-1].replace(/[[\]]/g,"");t&&(i[t]=l[e])}return i}function d(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 h(e,t,n){let o=e;return t&&(o=c(t,o)),n&&(o+=n),o}function g(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}function p(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}function v(e,t,n){let o;return e&&p(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}function x(e,t){return n(t+e)}function m(e){return"/".concat(e)}function j(e){return e.replace(/\\/g,"%5C").replace(/\/+/g,"/")}export{x as applyBasePath,h as formatPathname,d as formatPathnameTemplate,i as formatTemplatePathname,v as getBestMatchingDomain,g as getHost,l as getInternalTemplate,m as getLocaleAsPrefix,s as getLocalePrefixes,u as getNormalizedPathname,f as getPathnameMatch,a as getRouteParams,p as isLocaleSupportedOnDomain,j as sanitizePathname};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js"),a=require("./utils.js");exports.default=function(t){var o;let{localizedPathnames:n,request:l,resolvedLocale:r,routing:s}=t;const i=l.nextUrl.clone(),c=a.getHost(l.headers);function p(t,o){return t.pathname=e.normalizeTrailingSlash(t.pathname),l.nextUrl.basePath&&((t=new URL(t)).pathname=a.applyBasePath(t.pathname,l.nextUrl.basePath)),"<".concat(t.toString(),'>; rel="alternate"; hreflang="').concat(o,'"')}function m(e,t){return n&&"object"==typeof n?a.formatTemplatePathname(e,n[r],n[t]):e}c&&(i.port="",i.host=c),i.protocol=null!==(o=l.headers.get("x-forwarded-proto"))&&void 0!==o?o:i.protocol,i.pathname=a.getNormalizedPathname(i.pathname,s.locales,s.localePrefix);const h=a.getLocalePrefixes(s.locales,s.localePrefix).flatMap((e=>{let t,[o,l]=e;function r(e){return"/"===e?l:l+e}if(s.domains){return(s.domains.filter((e=>a.isLocaleSupportedOnDomain(o,e)))||[]).map((e=>(t=new URL(i),t.port="",t.host=e.domain,t.pathname=m(i.pathname,o),o===e.defaultLocale&&"always"!==s.localePrefix.mode||(t.pathname=r(t.pathname)),p(t,o))))}{let e;e=n&&"object"==typeof n?m(i.pathname,o):i.pathname,o===s.defaultLocale&&"always"!==s.localePrefix.mode||(e=r(e)),t=new URL(e,i)}return p(t,o)}));if(!s.domains&&("always"!==s.localePrefix.mode||"/"===i.pathname)){const e=new URL(m(i.pathname,s.defaultLocale),i);h.push(p(e,"x-default"))}return h.join(", ")};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js"),a=require("./utils.js");exports.default=function(t){var o;let{localizedPathnames:n,request:l,resolvedLocale:r,routing:s}=t;const i=l.nextUrl.clone(),c=a.getHost(l.headers);function p(t,o){return t.pathname=e.normalizeTrailingSlash(t.pathname),l.nextUrl.basePath&&((t=new URL(t)).pathname=a.applyBasePath(t.pathname,l.nextUrl.basePath)),"<".concat(t.toString(),'>; rel="alternate"; hreflang="').concat(o,'"')}function m(e,t){return n&&"object"==typeof n?a.formatTemplatePathname(e,n[r],n[t]):e}c&&(i.port="",i.host=c),i.protocol=null!==(o=l.headers.get("x-forwarded-proto"))&&void 0!==o?o:i.protocol,i.pathname=a.getNormalizedPathname(i.pathname,s.locales,s.localePrefix);const h=a.getLocalePrefixes(s.locales,s.localePrefix,!1).flatMap((e=>{let t,[o,l]=e;function r(e){return"/"===e?l:l+e}if(s.domains){return(s.domains.filter((e=>a.isLocaleSupportedOnDomain(o,e)))||[]).map((e=>(t=new URL(i),t.port="",t.host=e.domain,t.pathname=m(i.pathname,o),o===e.defaultLocale&&"always"!==s.localePrefix.mode||(t.pathname=r(t.pathname)),p(t,o))))}{let e;e=n&&"object"==typeof n?m(i.pathname,o):i.pathname,o===s.defaultLocale&&"always"!==s.localePrefix.mode||(e=r(e)),t=new URL(e,i)}return p(t,o)}));if(!s.domains&&("always"!==s.localePrefix.mode||"/"===i.pathname)){const e=new URL(m(i.pathname,s.defaultLocale),i);h.push(p(e,"x-default"))}return h.join(", ")};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(t,n){
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(t,n){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];const o=t.map((t=>[t,e.getLocalePrefix(t,n)]));return r&&o.sort(((e,t)=>t[1].length-e[1].length)),o}function n(t,n){const r=e.normalizeTrailingSlash(n),o=e.normalizeTrailingSlash(t),a=e.templateToRegex(o).exec(r);if(!a)return;const l={};for(let e=1;e<a.length;e++){var i;const t=null===(i=o.match(/\[([^\]]+)\]/g))||void 0===i?void 0:i[e-1].replace(/[[\]]/g,"");t&&(l[t]=a[e])}return l}function r(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((e=>{let[t,r]=e;n=n.replace("[".concat(t,"]"),r)})),n}function o(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}exports.applyBasePath=function(t,n){return e.normalizeTrailingSlash(n+t)},exports.formatPathname=function(t,n,r){let o=t;return n&&(o=e.prefixPathname(n,o)),r&&(o+=r),o},exports.formatPathnameTemplate=r,exports.formatTemplatePathname=function(t,o,a,l){let i="";return i+=r(a,n(o,t)),i=e.normalizeTrailingSlash(i),i},exports.getBestMatchingDomain=function(e,t,n){let r;return e&&o(t,e)&&(r=e),r||(r=n.find((e=>e.defaultLocale===t))),r||(r=n.find((e=>null!=e.locales&&e.locales.includes(t)))),r||null!=(null==e?void 0:e.locales)||(r=e),r||(r=n.find((e=>!e.locales))),r},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,r){const o=e.getSortedPathnames(Object.keys(t));for(const a of o){const o=t[a];if("string"==typeof o){const t=o;if(e.matchesPathname(t,n))return[void 0,a]}else{const t=Object.entries(o),l=t.findIndex((e=>{let[t]=e;return t===r}));l>0&&t.unshift(t.splice(l,1)[0]);for(const[r,o]of t)if(e.matchesPathname(o,n))return[r,a]}}for(const r of Object.keys(t))if(e.matchesPathname(r,n))return[void 0,r];return[void 0,void 0]},exports.getLocaleAsPrefix=function(e){return"/".concat(e)},exports.getLocalePrefixes=t,exports.getNormalizedPathname=function(n,r,o){n.endsWith("/")||(n+="/");const a=t(r,o),l=new RegExp("^(".concat(a.map((e=>{let[,t]=e;return t.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),i=n.match(l);let s=i?"/"+i[2]:n;return"/"!==s&&(s=e.normalizeTrailingSlash(s)),s},exports.getPathnameMatch=function(e,n,r){const o=t(n,r);for(const[t,n]of o){let r,o;if(e===n||e.startsWith(n+"/"))r=o=!0;else{const t=e.toLowerCase(),a=n.toLowerCase();(t===a||t.startsWith(a+"/"))&&(r=!1,o=!0)}if(o)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:r}}},exports.getRouteParams=n,exports.isLocaleSupportedOnDomain=o,exports.sanitizePathname=function(e){return e.replace(/\\/g,"%5C").replace(/\/+/g,"/")};
|
|
@@ -7,7 +7,7 @@ export declare function formatTemplatePathname(sourcePathname: string, sourceTem
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function getNormalizedPathname<AppLocales extends Locales>(pathname: string, locales: AppLocales, localePrefix: LocalePrefixConfigVerbose<AppLocales>): string;
|
|
9
9
|
export declare function findCaseInsensitiveString(candidate: string, strings: Array<string>): string | undefined;
|
|
10
|
-
export declare function getLocalePrefixes<AppLocales extends Locales>(locales: AppLocales, localePrefix: LocalePrefixConfigVerbose<AppLocales
|
|
10
|
+
export declare function getLocalePrefixes<AppLocales extends Locales>(locales: AppLocales, localePrefix: LocalePrefixConfigVerbose<AppLocales>, sort?: boolean): Array<[AppLocales[number], string]>;
|
|
11
11
|
export declare function getPathnameMatch<AppLocales extends Locales>(pathname: string, locales: AppLocales, localePrefix: LocalePrefixConfigVerbose<AppLocales>): {
|
|
12
12
|
locale: AppLocales[number];
|
|
13
13
|
prefix: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.3",
|
|
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.19.
|
|
90
|
+
"use-intl": "^3.19.3"
|
|
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": "
|
|
96
|
+
"gitHead": "aa60ddebea13ddbd9bf8377b28774c4a9839cd7d"
|
|
97
97
|
}
|