next-intl 3.1.2 → 3.1.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/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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as n,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t}from"../shared/utils.js";import
|
|
1
|
+
import{NextResponse as e}from"next/server";import{COOKIE_LOCALE_NAME as n,HEADER_LOCALE_NAME as l}from"../shared/constants.js";import{matchesPathname as t}from"../shared/utils.js";import o 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 n,l,t;return{...e,alternateLinks:null===(n=e.alternateLinks)||void 0===n||n,localePrefix:null!==(l=e.localePrefix)&&void 0!==l?l:"always",localeDetection:null===(t=e.localeDetection)||void 0===t||t}}(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(n))||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))))||[],j=null!=h.domains&&!L;function w(n){return e.rewrite(new URL(n,v.url),function(){const e=new Headers(v.headers);return e.set(l,P),{request:{headers:e}}}())}function y(n,l){const t=new URL(n,v.url);if(k.length>0&&!l){const e=m(L,P,k);e&&(l=e.domain,e.defaultLocale===P&&"as-needed"===h.localePrefix&&(t.pathname=t.pathname.replace("/".concat(P),"")))}return l&&(t.host=l),e.redirect(t.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 n=h.pathnames[R],l="string"==typeof n?n:n[P];if(t(l,D))S=d(D,l,R,q);else{const t=h.defaultLocale===P||(null==L?void 0:L.defaultLocale)===P;H=y(f(d(D,"string"==typeof n?n:n[e],l,q||!t?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?w(e):y(e)}else{const e=f(S,v.nextUrl.search);if(A){const n=u(e,q);if("never"===h.localePrefix)H=y(n);else if(q===P)if(U&&"as-needed"===h.localePrefix)H=y(n);else if(h.domains){const l=m(L,q,k);H=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||j?w(e):y(n,null==l?void 0:l.domain)}else H=w(e);else H=y("/".concat(P).concat(n))}else H="never"===h.localePrefix||U&&("as-needed"===h.localePrefix||h.domains)?w("/".concat(P).concat(e)):y("/".concat(P).concat(e))}var z;(g&&H.cookies.set(n,P,{sameSite:"strict",maxAge:31536e3}),"never"!==h.localePrefix&&h.alternateLinks&&h.locales.length>1)&&H.headers.set("Link",o({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),"")))}return a&&(n.host=a),e.NextResponse.redirect(n.toString())}const L=o.getNormalizedPathname(r.nextUrl.pathname,i.locales),P=o.getKnownLocaleFromPathname(r.nextUrl.pathname,i.locales),g=null!=P;let E,A,O=r.nextUrl.pathname;if(i.pathnames){let e;if([e=u,A]=o.getInternalTemplate(i.pathnames,L),A){const t=i.pathnames[A],n="string"==typeof t?t:t[u];if(a.matchesPathname(n,L))O=o.formatTemplatePathname(L,n,A,P);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,P||!a?u:void 0),r.nextUrl.search))}}}if(!E)if("/"===O){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(O,r.nextUrl.search);if(g){const t=o.getBasePath(e,P);if("never"===i.localePrefix)E=x(t);else if(P===u)if(h&&"as-needed"===i.localePrefix)E=x(t);else if(i.domains){const a=o.getBestMatchingDomain(d,P,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 U;(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!=A?null===(U=i.pathnames)||void 0===U?void 0:U[A]:void 0,request:r,resolvedLocale:u}));return E}};
|
|
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),"")))}return a&&(n.host=a),e.NextResponse.redirect(n.toString())}const L=o.getNormalizedPathname(r.nextUrl.pathname,i.locales),P=o.getKnownLocaleFromPathname(r.nextUrl.pathname,i.locales),g=null!=P;let E,A,O=r.nextUrl.pathname;if(i.pathnames){let e;if([e=u,A]=o.getInternalTemplate(i.pathnames,L),A){const t=i.pathnames[A],n="string"==typeof t?t:t[u];if(a.matchesPathname(n,L))O=o.formatTemplatePathname(L,n,A,P);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,P||!a?u:void 0),r.nextUrl.search))}}}if(!E)if("/"===O){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(O,r.nextUrl.search);if(g){const t=o.getBasePath(e,P);if("never"===i.localePrefix)E=x(t);else if(P===u)if(h&&"as-needed"===i.localePrefix)E=x(t);else if(i.domains){const a=o.getBestMatchingDomain(d,P,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 U;(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!=A?null===(U=i.pathnames)||void 0===U?void 0:U[A]: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.3",
|
|
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.",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
75
75
|
"negotiator": "^0.6.3",
|
|
76
|
-
"use-intl": "^3.1.
|
|
76
|
+
"use-intl": "^3.1.3"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"limit": "5.7 KB"
|
|
126
126
|
}
|
|
127
127
|
],
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "f4423350fcba6707c005725deade19a7083c22b5"
|
|
129
129
|
}
|