next-intl 3.1.2 → 3.1.4-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
<hr />
|
|
15
15
|
|
|
16
|
-
📣 [Support for
|
|
16
|
+
📣 [Support for the App Router and Server Components has arrived →](https://next-intl-docs.vercel.app/docs/getting-started/app-router)
|
|
17
17
|
|
|
18
18
|
<hr />
|
|
19
19
|
|
|
@@ -28,7 +28,7 @@ function createMiddleware(config) {
|
|
|
28
28
|
domain,
|
|
29
29
|
locale
|
|
30
30
|
} = resolveLocale.default(configWithDefaults, request.headers, request.cookies, request.nextUrl.pathname);
|
|
31
|
-
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;
|
|
31
|
+
const hasOutdatedCookie = configWithDefaults.localeDetection && ((_request$cookies$get = request.cookies.get(constants.COOKIE_LOCALE_NAME)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
|
|
32
32
|
const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === configWithDefaults.defaultLocale;
|
|
33
33
|
const domainConfigs = ((_configWithDefaults$d = configWithDefaults.domains) === null || _configWithDefaults$d === void 0 ? void 0 : _configWithDefaults$d.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
|
|
34
34
|
const hasUnknownHost = configWithDefaults.domains != null && !domain;
|
|
@@ -44,21 +44,24 @@ function createMiddleware(config) {
|
|
|
44
44
|
function rewrite(url) {
|
|
45
45
|
return server.NextResponse.rewrite(new URL(url, request.url), getResponseInit());
|
|
46
46
|
}
|
|
47
|
-
function redirect(url,
|
|
47
|
+
function redirect(url, redirectDomain) {
|
|
48
48
|
const urlObj = new URL(url, request.url);
|
|
49
49
|
if (domainConfigs.length > 0) {
|
|
50
|
-
if (!
|
|
50
|
+
if (!redirectDomain) {
|
|
51
51
|
const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainConfigs);
|
|
52
52
|
if (bestMatchingDomain) {
|
|
53
|
-
|
|
53
|
+
redirectDomain = bestMatchingDomain.domain;
|
|
54
54
|
if (bestMatchingDomain.defaultLocale === locale && configWithDefaults.localePrefix === 'as-needed') {
|
|
55
55
|
urlObj.pathname = urlObj.pathname.replace("/".concat(locale), '');
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
60
|
+
if (redirectDomain) {
|
|
61
|
+
var _request$headers$get;
|
|
62
|
+
urlObj.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : request.nextUrl.protocol;
|
|
63
|
+
urlObj.port = '';
|
|
64
|
+
urlObj.host = redirectDomain;
|
|
62
65
|
}
|
|
63
66
|
return server.NextResponse.redirect(urlObj.toString());
|
|
64
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as o,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as n}from"../shared/utils.js";import t from"./getAlternateLinksHeaderValue.js";import a from"./resolveLocale.js";import{isLocaleSupportedOnDomain as r,getNormalizedPathname as i,getKnownLocaleFromPathname as s,getInternalTemplate as c,formatTemplatePathname as d,getPathWithSearch as f,getBasePath as u,getBestMatchingDomain as m}from"./utils.js";function v(v){const h=function(e){var o,l,n;return{...e,alternateLinks:null===(o=e.alternateLinks)||void 0===o||o,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(n=e.localeDetection)||void 0===n||n}}(v);return function(v){var p,x;const{domain:L,locale:P}=a(h,v.headers,v.cookies,v.nextUrl.pathname),g=h.localeDetection&&(null===(p=v.cookies.get(o))||void 0===p?void 0:p.value)!==P,U=L?L.defaultLocale===P:P===h.defaultLocale,k=(null===(x=h.domains)||void 0===x?void 0:x.filter((e=>r(P,e))))||[],w=null!=h.domains&&!L;function j(o){return e.rewrite(new URL(o,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(o,l){const n=new URL(o,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(n.pathname=n.pathname.replace("/".concat(P),"")))}var t;l&&(n.protocol=null!==(t=v.headers.get("x-forwarded-proto"))&&void 0!==t?t:v.nextUrl.protocol,n.port="",n.host=l);return e.redirect(n.toString())}const D=i(v.nextUrl.pathname,h.locales),q=s(v.nextUrl.pathname,h.locales),A=null!=q;let H,R,S=v.nextUrl.pathname;if(h.pathnames){let e;if([e=P,R]=c(h.pathnames,D),R){const o=h.pathnames[R],l="string"==typeof o?o:o[P];if(n(l,D))S=d(D,l,R,q);else{const n=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof o?o:o[e],l,q||!n?P:void 0),v.nextUrl.search))}}}if(!H)if("/"===S){const e=f("/".concat(P),v.nextUrl.search);H="never"===h.localePrefix||U&&"as-needed"===h.localePrefix?j(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const o=u(e,q);if("never"===h.localePrefix)H=y(o);else if(q===P)if(U&&"as-needed"===h.localePrefix)H=y(o);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||w?j(e):y(o,null==l?void 0:l.domain)}else H=j(e);else H=y("/".concat(P).concat(o))}else H="never"===h.localePrefix||U&&("as-needed"===h.localePrefix||h.domains)?j("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(g&&H.cookies.set(o,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",t({config:h,localizedPathnames:null!=R?null===(z=h.pathnames)||void 0===z?void 0:z[R]:void 0,request:v,resolvedLocale:P}));return H}}export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),t=require("../shared/constants.js"),a=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const i=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}}(r);return function(r){var s,c;const{domain:d,locale:u}=l.default(i,r.headers,r.cookies,r.nextUrl.pathname),f=(null===(s=r.cookies.get(t.COOKIE_LOCALE_NAME))||void 0===s?void 0:s.value)!==u,h=d?d.defaultLocale===u:u===i.defaultLocale,m=(null===(c=i.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=i.domains&&!d;function p(a){return e.NextResponse.rewrite(new URL(a,r.url),function(){const e=new Headers(r.headers);return e.set(t.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function x(t,a){const n=new URL(t,r.url);if(m.length>0&&!a){const e=o.getBestMatchingDomain(d,u,m);e&&(a=e.domain,e.defaultLocale===u&&"as-needed"===i.localePrefix&&(n.pathname=n.pathname.replace("/".concat(u),"")))}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),t=require("../shared/constants.js"),a=require("../shared/utils.js"),n=require("./getAlternateLinksHeaderValue.js"),l=require("./resolveLocale.js"),o=require("./utils.js");exports.default=function(r){const i=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}}(r);return function(r){var s,c;const{domain:d,locale:u}=l.default(i,r.headers,r.cookies,r.nextUrl.pathname),f=i.localeDetection&&(null===(s=r.cookies.get(t.COOKIE_LOCALE_NAME))||void 0===s?void 0:s.value)!==u,h=d?d.defaultLocale===u:u===i.defaultLocale,m=(null===(c=i.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(u,e))))||[],v=null!=i.domains&&!d;function p(a){return e.NextResponse.rewrite(new URL(a,r.url),function(){const e=new Headers(r.headers);return e.set(t.HEADER_LOCALE_NAME,u),{request:{headers:e}}}())}function x(t,a){const n=new URL(t,r.url);if(m.length>0&&!a){const e=o.getBestMatchingDomain(d,u,m);e&&(a=e.domain,e.defaultLocale===u&&"as-needed"===i.localePrefix&&(n.pathname=n.pathname.replace("/".concat(u),"")))}var l;a&&(n.protocol=null!==(l=r.headers.get("x-forwarded-proto"))&&void 0!==l?l:r.nextUrl.protocol,n.port="",n.host=a);return e.NextResponse.redirect(n.toString())}const L=o.getNormalizedPathname(r.nextUrl.pathname,i.locales),g=o.getKnownLocaleFromPathname(r.nextUrl.pathname,i.locales),P=null!=g;let E,U,A=r.nextUrl.pathname;if(i.pathnames){let e;if([e=u,U]=o.getInternalTemplate(i.pathnames,L),U){const t=i.pathnames[U],n="string"==typeof t?t:t[u];if(a.matchesPathname(n,L))A=o.formatTemplatePathname(L,n,U,g);else{const a=i.defaultLocale===u||(null==d?void 0:d.defaultLocale)===u;E=x(o.getPathWithSearch(o.formatTemplatePathname(L,"string"==typeof t?t:t[e],n,g||!a?u:void 0),r.nextUrl.search))}}}if(!E)if("/"===A){const e=o.getPathWithSearch("/".concat(u),r.nextUrl.search);E="never"===i.localePrefix||h&&"as-needed"===i.localePrefix?p(e):x(e)}else{const e=o.getPathWithSearch(A,r.nextUrl.search);if(P){const t=o.getBasePath(e,g);if("never"===i.localePrefix)E=x(t);else if(g===u)if(h&&"as-needed"===i.localePrefix)E=x(t);else if(i.domains){const a=o.getBestMatchingDomain(d,g,m);E=(null==d?void 0:d.domain)===(null==a?void 0:a.domain)||v?p(e):x(t,null==a?void 0:a.domain)}else E=p(e);else E=x("/".concat(u).concat(t))}else E="never"===i.localePrefix||h&&("as-needed"===i.localePrefix||i.domains)?p("/".concat(u).concat(e)):x("/".concat(u).concat(e))}var O;(f&&E.cookies.set(t.COOKIE_LOCALE_NAME,u,{sameSite:"strict",maxAge:31536e3}),"never"!==i.localePrefix&&i.alternateLinks&&i.locales.length>1)&&E.headers.set("Link",n.default({config:i,localizedPathnames:null!=U?null===(O=i.pathnames)||void 0===O?void 0:O[U]:void 0,request:r,resolvedLocale:u}));return E}};
|
|
@@ -19,7 +19,7 @@ type MiddlewareConfig<Locales extends AllLocales> = RoutingBaseConfig<Locales> &
|
|
|
19
19
|
domains?: Array<DomainConfig<Locales>>;
|
|
20
20
|
/** 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 */
|
|
21
21
|
alternateLinks?: boolean;
|
|
22
|
-
/** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
|
|
22
|
+
/** By setting this to `false`, the cookie as well as the `accept-language` header will no longer be used for locale detection. */
|
|
23
23
|
localeDetection?: boolean;
|
|
24
24
|
/** Maps internal pathnames to external ones which can be localized per locale. */
|
|
25
25
|
pathnames?: Pathnames<Locales>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.4-alpha.1",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"description": "A minimal, but complete solution for internationalization in Next.js apps.",
|
|
@@ -10,14 +10,6 @@
|
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/amannn/next-intl"
|
|
12
12
|
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "rm -rf dist && rollup -c",
|
|
15
|
-
"test": "TZ=Europe/Berlin vitest",
|
|
16
|
-
"lint": "eslint src test && tsc --noEmit",
|
|
17
|
-
"prepublishOnly": "CI=true turbo test && turbo lint && turbo build && cp ../../README.md .",
|
|
18
|
-
"postpublish": "git checkout . && rm ./README.md",
|
|
19
|
-
"size": "size-limit"
|
|
20
|
-
},
|
|
21
13
|
"main": "./dist/index.react-client.js",
|
|
22
14
|
"module": "./dist/esm/index.react-client.js",
|
|
23
15
|
"typings": "./dist/types/src/index.react-client.d.ts",
|
|
@@ -73,7 +65,7 @@
|
|
|
73
65
|
"dependencies": {
|
|
74
66
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
75
67
|
"negotiator": "^0.6.3",
|
|
76
|
-
"use-intl": "^3.1.
|
|
68
|
+
"use-intl": "^3.1.3"
|
|
77
69
|
},
|
|
78
70
|
"peerDependencies": {
|
|
79
71
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -125,5 +117,10 @@
|
|
|
125
117
|
"limit": "5.7 KB"
|
|
126
118
|
}
|
|
127
119
|
],
|
|
128
|
-
"
|
|
129
|
-
|
|
120
|
+
"scripts": {
|
|
121
|
+
"build": "rm -rf dist && rollup -c",
|
|
122
|
+
"test": "TZ=Europe/Berlin vitest",
|
|
123
|
+
"lint": "eslint src test && tsc --noEmit",
|
|
124
|
+
"size": "size-limit"
|
|
125
|
+
}
|
|
126
|
+
}
|