next-intl 3.11.2 → 3.11.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.
|
@@ -36,6 +36,19 @@ function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
|
|
|
36
36
|
}
|
|
37
37
|
return locale;
|
|
38
38
|
}
|
|
39
|
+
function getLocaleFromPrefix(pathname, locales) {
|
|
40
|
+
const pathLocaleCandidate = utils.getFirstPathnameSegment(pathname);
|
|
41
|
+
return utils.findCaseInsensitiveLocale(pathLocaleCandidate, locales);
|
|
42
|
+
}
|
|
43
|
+
function getLocaleFromCookie(requestCookies, locales) {
|
|
44
|
+
if (requestCookies.has(constants.COOKIE_LOCALE_NAME)) {
|
|
45
|
+
var _requestCookies$get;
|
|
46
|
+
const value = (_requestCookies$get = requestCookies.get(constants.COOKIE_LOCALE_NAME)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
|
|
47
|
+
if (value && locales.includes(value)) {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
39
52
|
function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname) {
|
|
40
53
|
let {
|
|
41
54
|
defaultLocale,
|
|
@@ -46,22 +59,12 @@ function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname)
|
|
|
46
59
|
|
|
47
60
|
// Prio 1: Use route prefix
|
|
48
61
|
if (pathname) {
|
|
49
|
-
|
|
50
|
-
const matchedLocale = utils.findCaseInsensitiveLocale(pathLocaleCandidate, locales);
|
|
51
|
-
if (matchedLocale) {
|
|
52
|
-
locale = matchedLocale;
|
|
53
|
-
}
|
|
62
|
+
locale = getLocaleFromPrefix(pathname, locales);
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
// Prio 2: Use existing cookie
|
|
57
66
|
if (!locale && localeDetection && requestCookies) {
|
|
58
|
-
|
|
59
|
-
var _requestCookies$get;
|
|
60
|
-
const value = (_requestCookies$get = requestCookies.get(constants.COOKIE_LOCALE_NAME)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
|
|
61
|
-
if (value && locales.includes(value)) {
|
|
62
|
-
locale = value;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
67
|
+
locale = getLocaleFromCookie(requestCookies, locales);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
// Prio 3: Use the `accept-language` header
|
|
@@ -76,26 +79,56 @@ function resolveLocaleFromPrefix(_ref, requestHeaders, requestCookies, pathname)
|
|
|
76
79
|
return locale;
|
|
77
80
|
}
|
|
78
81
|
function resolveLocaleFromDomain(config, requestHeaders, requestCookies, pathname) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
const domains = config.domains;
|
|
83
|
+
const domain = findDomainFromHost(requestHeaders, domains);
|
|
84
|
+
if (!domain) {
|
|
85
|
+
return {
|
|
86
|
+
locale: resolveLocaleFromPrefix(config, requestHeaders, requestCookies, pathname)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
let locale;
|
|
83
90
|
|
|
84
|
-
// Prio 1: Use
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
domain
|
|
92
|
-
|
|
91
|
+
// Prio 1: Use route prefix
|
|
92
|
+
if (pathname) {
|
|
93
|
+
const prefixLocale = getLocaleFromPrefix(pathname, config.locales);
|
|
94
|
+
if (prefixLocale) {
|
|
95
|
+
if (utils.isLocaleSupportedOnDomain(prefixLocale, domain)) {
|
|
96
|
+
locale = prefixLocale;
|
|
97
|
+
} else {
|
|
98
|
+
// Causes a redirect to a domain that supports the locale
|
|
99
|
+
return {
|
|
100
|
+
locale: prefixLocale,
|
|
101
|
+
domain
|
|
102
|
+
};
|
|
103
|
+
}
|
|
93
104
|
}
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
// Prio 2: Use
|
|
107
|
+
// Prio 2: Use existing cookie
|
|
108
|
+
if (!locale && config.localeDetection && requestCookies) {
|
|
109
|
+
const cookieLocale = getLocaleFromCookie(requestCookies, config.locales);
|
|
110
|
+
if (cookieLocale) {
|
|
111
|
+
if (utils.isLocaleSupportedOnDomain(cookieLocale, domain)) {
|
|
112
|
+
locale = cookieLocale;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Prio 3: Use the `accept-language` header
|
|
118
|
+
if (!locale && config.localeDetection && requestHeaders) {
|
|
119
|
+
const headerLocale = getAcceptLanguageLocale(requestHeaders, domain.locales || config.locales, domain.defaultLocale);
|
|
120
|
+
if (headerLocale) {
|
|
121
|
+
locale = headerLocale;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Prio 4: Use default locale
|
|
126
|
+
if (!locale) {
|
|
127
|
+
locale = domain.defaultLocale;
|
|
128
|
+
}
|
|
97
129
|
return {
|
|
98
|
-
locale
|
|
130
|
+
locale,
|
|
131
|
+
domain
|
|
99
132
|
};
|
|
100
133
|
}
|
|
101
134
|
function resolveLocale(config, requestHeaders, requestCookies, pathname) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{match as
|
|
1
|
+
import{match as e}from"@formatjs/intl-localematcher";import o from"negotiator";import{COOKIE_LOCALE_NAME as t}from"../shared/constants.js";import{isLocaleSupportedOnDomain as n,getHost as l,getFirstPathnameSegment as a,findCaseInsensitiveLocale as c}from"./utils.js";function i(t,n,l){let a;const c=new o({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{a=e(c,n,l)}catch(e){}return a}function r(e,o){const t=a(e);return c(t,o)}function u(e,o){if(e.has(t)){var n;const l=null===(n=e.get(t))||void 0===n?void 0:n.value;if(l&&o.includes(l))return l}}function f(e,o,t,n){let l,{defaultLocale:a,localeDetection:c,locales:f}=e;return n&&(l=r(n,f)),!l&&c&&t&&(l=u(t,f)),!l&&c&&o&&(l=i(o,f,a)),l||(l=a),l}function s(e,o,t,a){const c=function(e,o){var t;let n=l(e);if(n=null===(t=n)||void 0===t?void 0:t.replace(/:\d+$/,""),n&&o)return o.find((e=>e.domain===n))}(o,e.domains);if(!c)return{locale:f(e,o,t,a)};let s;if(a){const o=r(a,e.locales);if(o){if(!n(o,c))return{locale:o,domain:c};s=o}}if(!s&&e.localeDetection&&t){const o=u(t,e.locales);o&&n(o,c)&&(s=o)}if(!s&&e.localeDetection&&o){const t=i(o,c.locales||e.locales,c.defaultLocale);t&&(s=t)}return s||(s=c.defaultLocale),{locale:s,domain:c}}function d(e,o,t,n){return e.domains?s(e,o,t,n):{locale:f(e,o,t,n)}}export{d as default,i as getAcceptLanguageLocale};
|
|
@@ -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"),o=require("./utils.js");function a(e){return e&&e.__esModule?e:{default:e}}var l=a(t);function c(t,n,o){let a;const c=new l.default({headers:{"accept-language":t.get("accept-language")||void 0}}).languages();try{a=e.match(c,n,o)}catch(e){}return a}function i(e,t){const n=o.getFirstPathnameSegment(e);return o.findCaseInsensitiveLocale(n,t)}function r(e,t){if(e.has(n.COOKIE_LOCALE_NAME)){var o;const a=null===(o=e.get(n.COOKIE_LOCALE_NAME))||void 0===o?void 0:o.value;if(a&&t.includes(a))return a}}function u(e,t,n,o){let a,{defaultLocale:l,localeDetection:u,locales:s}=e;return o&&(a=i(o,s)),!a&&u&&n&&(a=r(n,s)),!a&&u&&t&&(a=c(t,s,l)),a||(a=l),a}function s(e,t,n,a){const l=function(e,t){var n;let a=o.getHost(e);if(a=null===(n=a)||void 0===n?void 0:n.replace(/:\d+$/,""),a&&t)return t.find((e=>e.domain===a))}(t,e.domains);if(!l)return{locale:u(e,t,n,a)};let s;if(a){const t=i(a,e.locales);if(t){if(!o.isLocaleSupportedOnDomain(t,l))return{locale:t,domain:l};s=t}}if(!s&&e.localeDetection&&n){const t=r(n,e.locales);t&&o.isLocaleSupportedOnDomain(t,l)&&(s=t)}if(!s&&e.localeDetection&&t){const n=c(t,l.locales||e.locales,l.defaultLocale);n&&(s=n)}return s||(s=l.defaultLocale),{locale:s,domain:l}}exports.default=function(e,t,n,o){return e.domains?s(e,t,n,o):{locale:u(e,t,n,o)}},exports.getAcceptLanguageLocale=c;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.3",
|
|
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.11.
|
|
85
|
+
"use-intl": "^3.11.3"
|
|
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": "
|
|
141
|
+
"limit": "6 KB"
|
|
142
142
|
}
|
|
143
143
|
],
|
|
144
|
-
"gitHead": "
|
|
144
|
+
"gitHead": "c4eac9cae1b10254486ab71cbfa35fb1f39e1b05"
|
|
145
145
|
}
|