next-intl 3.8.0 → 3.9.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 +10 -8
- package/dist/development/index.react-server.js +2 -2
- package/dist/development/middleware/middleware.js +1 -1
- package/dist/development/middleware/resolveLocale.js +4 -3
- package/dist/development/middleware/utils.js +11 -7
- package/dist/development/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js} +4 -4
- package/dist/esm/index.react-server.js +1 -1
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/middleware/resolveLocale.js +1 -1
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/production/index.react-server.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/middleware/resolveLocale.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/types/src/middleware/utils.d.ts +3 -2
- package/dist/types/src/react-server/{NextIntlClientProvider.d.ts → NextIntlClientProviderServer.d.ts} +1 -1
- package/dist/types/src/react-server/index.d.ts +1 -1
- package/package.json +4 -4
- /package/dist/esm/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js} +0 -0
- /package/dist/production/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js} +0 -0
- /package/dist/types/test/react-server/{NextIntlClientProvider.test.d.ts → NextIntlClientProviderServer.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
<br>
|
|
3
|
+
<a href="https://next-intl-docs.vercel.app/">
|
|
4
|
+
<picture>
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="media/logo-dark-mode.svg">
|
|
6
|
+
<source media="(prefers-color-scheme: light)" srcset="media/logo.svg">
|
|
7
|
+
<img alt="next-intl" src="media/logo.svg" width="600">
|
|
8
|
+
</picture>
|
|
9
|
+
</a>
|
|
10
|
+
<br>
|
|
11
|
+
<br>
|
|
10
12
|
</h1>
|
|
11
13
|
|
|
12
14
|
> Internationalization (i18n) for Next.js that gets out of your way.
|
|
@@ -8,7 +8,7 @@ var useFormatter = require('./react-server/useFormatter.js');
|
|
|
8
8
|
var useNow = require('./react-server/useNow.js');
|
|
9
9
|
var useTimeZone = require('./react-server/useTimeZone.js');
|
|
10
10
|
var useMessages = require('./react-server/useMessages.js');
|
|
11
|
-
var
|
|
11
|
+
var NextIntlClientProviderServer = require('./react-server/NextIntlClientProviderServer.js');
|
|
12
12
|
var core = require('use-intl/core');
|
|
13
13
|
|
|
14
14
|
|
|
@@ -19,7 +19,7 @@ exports.useFormatter = useFormatter.default;
|
|
|
19
19
|
exports.useNow = useNow.default;
|
|
20
20
|
exports.useTimeZone = useTimeZone.default;
|
|
21
21
|
exports.useMessages = useMessages.default;
|
|
22
|
-
exports.NextIntlClientProvider =
|
|
22
|
+
exports.NextIntlClientProvider = NextIntlClientProviderServer.default;
|
|
23
23
|
Object.keys(core).forEach(function (k) {
|
|
24
24
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
25
|
enumerable: true,
|
|
@@ -73,7 +73,7 @@ function createMiddleware(config) {
|
|
|
73
73
|
return server.NextResponse.redirect(urlObj.toString());
|
|
74
74
|
}
|
|
75
75
|
const normalizedPathname = utils.getNormalizedPathname(request.nextUrl.pathname, configWithDefaults.locales);
|
|
76
|
-
const pathLocale = utils.
|
|
76
|
+
const pathLocale = utils.getPathnameLocale(request.nextUrl.pathname, configWithDefaults.locales);
|
|
77
77
|
const hasLocalePrefix = pathLocale != null;
|
|
78
78
|
let response;
|
|
79
79
|
let internalTemplateName;
|
|
@@ -46,9 +46,10 @@ function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname)
|
|
|
46
46
|
|
|
47
47
|
// Prio 1: Use route prefix
|
|
48
48
|
if (pathname) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const pathLocaleCandidate = utils.getFirstPathnameSegment(pathname);
|
|
50
|
+
const matchedLocale = utils.findCaseInsensitiveLocale(pathLocaleCandidate, locales);
|
|
51
|
+
if (matchedLocale) {
|
|
52
|
+
locale = matchedLocale;
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('../shared/utils.js');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function getFirstPathnameSegment(pathname) {
|
|
8
8
|
return pathname.split('/')[1];
|
|
9
9
|
}
|
|
10
10
|
function getInternalTemplate(pathnames, pathname) {
|
|
@@ -44,16 +44,19 @@ function getNormalizedPathname(pathname, locales) {
|
|
|
44
44
|
if (!pathname.endsWith('/')) {
|
|
45
45
|
pathname += '/';
|
|
46
46
|
}
|
|
47
|
-
const match = pathname.match("^/(".concat(locales.join('|'), ")/(.*)"));
|
|
47
|
+
const match = pathname.match(new RegExp("^/(".concat(locales.join('|'), ")/(.*)"), 'i'));
|
|
48
48
|
let result = match ? '/' + match[2] : pathname;
|
|
49
49
|
if (result !== '/') {
|
|
50
50
|
result = normalizeTrailingSlash(result);
|
|
51
51
|
}
|
|
52
52
|
return result;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
function findCaseInsensitiveLocale(candidate, locales) {
|
|
55
|
+
return locales.find(locale => locale.toLowerCase() === candidate.toLowerCase());
|
|
56
|
+
}
|
|
57
|
+
function getPathnameLocale(pathname, locales) {
|
|
58
|
+
const pathLocaleCandidate = getFirstPathnameSegment(pathname);
|
|
59
|
+
const pathLocale = findCaseInsensitiveLocale(pathLocaleCandidate, locales) ? pathLocaleCandidate : undefined;
|
|
57
60
|
return pathLocale;
|
|
58
61
|
}
|
|
59
62
|
function getRouteParams(template, pathname) {
|
|
@@ -135,14 +138,15 @@ function normalizeTrailingSlash(pathname) {
|
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
exports.applyBasePath = applyBasePath;
|
|
141
|
+
exports.findCaseInsensitiveLocale = findCaseInsensitiveLocale;
|
|
138
142
|
exports.formatPathname = formatPathname;
|
|
139
143
|
exports.formatTemplatePathname = formatTemplatePathname;
|
|
140
144
|
exports.getBestMatchingDomain = getBestMatchingDomain;
|
|
145
|
+
exports.getFirstPathnameSegment = getFirstPathnameSegment;
|
|
141
146
|
exports.getHost = getHost;
|
|
142
147
|
exports.getInternalTemplate = getInternalTemplate;
|
|
143
|
-
exports.getKnownLocaleFromPathname = getKnownLocaleFromPathname;
|
|
144
|
-
exports.getLocaleFromPathname = getLocaleFromPathname;
|
|
145
148
|
exports.getNormalizedPathname = getNormalizedPathname;
|
|
146
149
|
exports.getPathWithSearch = getPathWithSearch;
|
|
150
|
+
exports.getPathnameLocale = getPathnameLocale;
|
|
147
151
|
exports.getRouteParams = getRouteParams;
|
|
148
152
|
exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
|
package/dist/development/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js}
RENAMED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var NextIntlClientProvider
|
|
7
|
+
var NextIntlClientProvider = require('../shared/NextIntlClientProvider.js');
|
|
8
8
|
var getLocale = require('../server/react-server/getLocale.js');
|
|
9
9
|
var getNow = require('../server/react-server/getNow.js');
|
|
10
10
|
var getTimeZone = require('../server/react-server/getTimeZone.js');
|
|
@@ -13,14 +13,14 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
13
|
|
|
14
14
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
15
15
|
|
|
16
|
-
async function
|
|
16
|
+
async function NextIntlClientProviderServer(_ref) {
|
|
17
17
|
let {
|
|
18
18
|
locale,
|
|
19
19
|
now,
|
|
20
20
|
timeZone,
|
|
21
21
|
...rest
|
|
22
22
|
} = _ref;
|
|
23
|
-
return /*#__PURE__*/React__default.default.createElement(NextIntlClientProvider
|
|
23
|
+
return /*#__PURE__*/React__default.default.createElement(NextIntlClientProvider.default
|
|
24
24
|
// We need to be careful about potentially reading from headers here.
|
|
25
25
|
// See https://github.com/amannn/next-intl/issues/631
|
|
26
26
|
, _rollupPluginBabelHelpers.extends({
|
|
@@ -30,4 +30,4 @@ async function NextIntlClientProvider(_ref) {
|
|
|
30
30
|
}, rest));
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
exports.default =
|
|
33
|
+
exports.default = NextIntlClientProviderServer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{default as useLocale}from"./react-server/useLocale.js";export{default as useTranslations}from"./react-server/useTranslations.js";export{default as useFormatter}from"./react-server/useFormatter.js";export{default as useNow}from"./react-server/useNow.js";export{default as useTimeZone}from"./react-server/useTimeZone.js";export{default as useMessages}from"./react-server/useMessages.js";export{default as NextIntlClientProvider}from"./react-server/
|
|
1
|
+
export{default as useLocale}from"./react-server/useLocale.js";export{default as useTranslations}from"./react-server/useTranslations.js";export{default as useFormatter}from"./react-server/useFormatter.js";export{default as useNow}from"./react-server/useNow.js";export{default as useTimeZone}from"./react-server/useTimeZone.js";export{default as useMessages}from"./react-server/useMessages.js";export{default as NextIntlClientProvider}from"./react-server/NextIntlClientProviderServer.js";export*from"use-intl/core";
|
|
@@ -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,
|
|
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 u,getPathWithSearch as m,getBestMatchingDomain as h,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=h(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=g,S]=f(x.pathnames,q),S){const t=x.pathnames[S],a="string"==typeof t?t:t[g];if(o(a,q))z=u(q,a,S,A);else{const n=x.defaultLocale===g||(null==L?void 0:L.defaultLocale)===g;R=D(m(u(q,"string"==typeof t?t:t[e],a,A||!n?g:void 0),v.nextUrl.search))}}}if(!R)if("/"===z){const e=m("/".concat(g),v.nextUrl.search);R="never"===x.localePrefix||w&&"as-needed"===x.localePrefix?y(e):D(e)}else{const e=m(z,v.nextUrl.search);if(H){const t=m(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=h(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{match as t}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as e}from"../shared/constants.js";import{
|
|
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 +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[o,r]of Object.entries(t))if("string"==typeof r){if(n(r,e))return[void 0,o]}else for(const[t,
|
|
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[o,r]of Object.entries(t))if("string"==typeof r){if(n(r,e))return[void 0,o]}else for(const[t,c]of Object.entries(r))if(n(c,e))return[t,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 l(n,t){return t.find((t=>t.toLowerCase()===n.toLowerCase()))}function i(n,t){const o=e(n);return l(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.replaceAll("[[","[").replaceAll("]]","]");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,l 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,i as getPathnameLocale,u as getRouteParams,d as isLocaleSupportedOnDomain};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./react-server/useLocale.js"),r=require("./react-server/useTranslations.js"),t=require("./react-server/useFormatter.js"),s=require("./react-server/useNow.js"),u=require("./react-server/useTimeZone.js"),o=require("./react-server/useMessages.js"),a=require("./react-server/
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./react-server/useLocale.js"),r=require("./react-server/useTranslations.js"),t=require("./react-server/useFormatter.js"),s=require("./react-server/useNow.js"),u=require("./react-server/useTimeZone.js"),o=require("./react-server/useMessages.js"),a=require("./react-server/NextIntlClientProviderServer.js"),i=require("use-intl/core");exports.useLocale=e.default,exports.useTranslations=r.default,exports.useFormatter=t.default,exports.useNow=s.default,exports.useTimeZone=u.default,exports.useMessages=o.default,exports.NextIntlClientProvider=a.default,Object.keys(i).forEach((function(e){"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return i[e]}})}));
|
|
@@ -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:d,locale:h}=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)!==h,m=d?d.defaultLocale===h:h===s.defaultLocale,f=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(h,e))))||[],p=null!=s.domains&&!d;function v(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,h),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(f.length>0&&!t){const e=o.getBestMatchingDomain(d,h,f);e&&(t=e.domain,e.defaultLocale===h&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(h))&&(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.
|
|
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:d,locale:h}=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)!==h,m=d?d.defaultLocale===h:h===s.defaultLocale,f=(null===(c=s.domains)||void 0===c?void 0:c.filter((e=>o.isLocaleSupportedOnDomain(h,e))))||[],p=null!=s.domains&&!d;function v(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,h),{request:{headers:e}}}())}function x(a,t){const n=new URL(a,r.url);if(f.length>0&&!t){const e=o.getBestMatchingDomain(d,h,f);e&&(t=e.domain,e.defaultLocale===h&&"as-needed"===s.localePrefix&&n.pathname.startsWith("/".concat(h))&&(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=h,E]=o.getInternalTemplate(s.pathnames,P),E){const a=s.pathnames[E],n="string"==typeof a?a:a[h];if(t.matchesPathname(n,P))O=o.formatTemplatePathname(P,n,E,g);else{const t=s.defaultLocale===h||(null==d?void 0:d.defaultLocale)===h;U=x(o.getPathWithSearch(o.formatTemplatePathname(P,"string"==typeof a?a:a[e],n,g||!t?h:void 0),r.nextUrl.search))}}}if(!U)if("/"===O){const e=o.getPathWithSearch("/".concat(h),r.nextUrl.search);U="never"===s.localePrefix||m&&"as-needed"===s.localePrefix?v(e):x(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=x(a);else if(g===h)if(m&&"as-needed"===s.localePrefix)U=x(a);else if(s.domains){const t=o.getBestMatchingDomain(d,g,f);U=(null==d?void 0:d.domain)===(null==t?void 0:t.domain)||p?v(e):x(a,null==t?void 0:t.domain)}else U=v(e);else U=x("/".concat(h).concat(a))}else U="never"===s.localePrefix||m&&("as-needed"===s.localePrefix||s.domains)?v("/".concat(h).concat(e)):x("/".concat(h).concat(e))}var A;(u&&U.cookies.set(a.COOKIE_LOCALE_NAME,h,{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:h}));return U}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@formatjs/intl-localematcher"),t=require("negotiator"),
|
|
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 +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(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
|
|
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.replaceAll("[[","[").replaceAll("]]","]");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 l(e){return e.endsWith("/")&&(e=e.slice(0,-1)),e}exports.applyBasePath=function(e,t){return l(t+e)},exports.findCaseInsensitiveLocale=n,exports.formatPathname=r,exports.formatTemplatePathname=function(e,t,n,a){const s=o(t,e);let c="";return a&&(c="/".concat(a)),c+=r(n,s),c=l(c),c},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){for(const[o,r]of Object.entries(t))if("string"==typeof r){const t=r;if(e.matchesPathname(t,n))return[void 0,o]}else for(const[t,a]of Object.entries(r))if(e.matchesPathname(a,n))return[t,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=l(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,13 +1,14 @@
|
|
|
1
1
|
import { AllLocales } from '../shared/types';
|
|
2
2
|
import { DomainConfig, MiddlewareConfigWithDefaults } from './NextIntlMiddlewareConfig';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getFirstPathnameSegment(pathname: string): string;
|
|
4
4
|
export declare function getInternalTemplate<Locales extends AllLocales, Pathnames extends NonNullable<MiddlewareConfigWithDefaults<Locales>['pathnames']>>(pathnames: Pathnames, pathname: string): [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.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getNormalizedPathname<Locales extends AllLocales>(pathname: string, locales: Locales): string;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function findCaseInsensitiveLocale<Locales extends AllLocales>(candidate: string, locales: Locales): string | undefined;
|
|
11
|
+
export declare function getPathnameLocale<Locales extends AllLocales>(pathname: string, locales: Locales): Locales[number] | undefined;
|
|
11
12
|
export declare function getRouteParams(template: string, pathname: string): Record<string, string> | undefined;
|
|
12
13
|
export declare function formatPathname(template: string, params?: object): string;
|
|
13
14
|
export declare function getPathWithSearch(pathname: string, search: string | undefined): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ComponentProps } from 'react';
|
|
2
2
|
import BaseNextIntlClientProvider from '../shared/NextIntlClientProvider';
|
|
3
3
|
type Props = ComponentProps<typeof BaseNextIntlClientProvider>;
|
|
4
|
-
export default function
|
|
4
|
+
export default function NextIntlClientProviderServer({ locale, now, timeZone, ...rest }: Props): Promise<React.JSX.Element>;
|
|
5
5
|
export {};
|
|
@@ -11,5 +11,5 @@ export { default as useFormatter } from './useFormatter';
|
|
|
11
11
|
export { default as useNow } from './useNow';
|
|
12
12
|
export { default as useTimeZone } from './useTimeZone';
|
|
13
13
|
export { default as useMessages } from './useMessages';
|
|
14
|
-
export { default as NextIntlClientProvider } from './
|
|
14
|
+
export { default as NextIntlClientProvider } from './NextIntlClientProviderServer';
|
|
15
15
|
export * from 'use-intl/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1",
|
|
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.9.1"
|
|
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.855 KB"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "cb74c29e9a494691f27445f4b2043c924a8713c0"
|
|
145
145
|
}
|
/package/dist/esm/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js}
RENAMED
|
File without changes
|
/package/dist/production/react-server/{NextIntlClientProvider.js → NextIntlClientProviderServer.js}
RENAMED
|
File without changes
|
|
File without changes
|