next-intl 3.22.0-canary.0 → 3.22.0
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/middleware.js +17 -20
- package/dist/development/middleware/resolveLocale.js +21 -30
- package/dist/development/middleware/syncCookie.js +7 -7
- package/dist/development/middleware/utils.js +4 -1
- package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +4 -2
- package/dist/development/navigation/react-client/createNavigation.js +1 -1
- package/dist/development/navigation/react-client/createSharedPathnamesNavigation.js +4 -2
- package/dist/development/navigation/react-client/useBaseRouter.js +3 -3
- package/dist/development/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -0
- package/dist/development/navigation/react-server/createSharedPathnamesNavigation.js +2 -0
- package/dist/development/navigation/shared/BaseLink.js +2 -1
- package/dist/development/navigation/shared/LegacyBaseLink.js +3 -1
- package/dist/development/navigation/shared/createSharedNavigationFns.js +2 -1
- package/dist/development/navigation/shared/syncLocaleCookie.js +26 -5
- package/dist/development/plugin.js +16 -6
- package/dist/development/react-client/index.js +3 -1
- package/dist/development/routing/config.js +18 -1
- package/dist/development/server/react-client/index.js +2 -0
- package/dist/development/server/react-server/RequestLocale.js +1 -1
- package/dist/development/server/react-server/RequestLocaleLegacy.js +1 -1
- package/dist/development/server/react-server/createRequestConfig.js +1 -1
- package/dist/development/server.react-client.js +1 -0
- package/dist/development/server.react-server.js +1 -0
- package/dist/development/shared/constants.js +0 -9
- package/dist/development/shared/utils.js +2 -2
- package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/esm/middleware/middleware.js +1 -1
- package/dist/esm/middleware/resolveLocale.js +1 -1
- package/dist/esm/middleware/syncCookie.js +1 -1
- package/dist/esm/middleware/utils.js +1 -1
- package/dist/esm/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/createNavigation.js +1 -1
- package/dist/esm/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/esm/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/esm/navigation/shared/BaseLink.js +1 -1
- package/dist/esm/navigation/shared/LegacyBaseLink.js +1 -1
- package/dist/esm/navigation/shared/createSharedNavigationFns.js +1 -1
- package/dist/esm/navigation/shared/syncLocaleCookie.js +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/routing/config.js +1 -1
- package/dist/esm/server/react-client/index.js +1 -1
- package/dist/esm/server/react-server/RequestLocale.js +1 -1
- package/dist/esm/server/react-server/RequestLocaleLegacy.js +1 -1
- package/dist/esm/server.react-client.js +1 -1
- package/dist/esm/server.react-server.js +1 -1
- package/dist/esm/shared/constants.js +1 -1
- package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/production/middleware/middleware.js +1 -1
- package/dist/production/middleware/resolveLocale.js +1 -1
- package/dist/production/middleware/syncCookie.js +1 -1
- package/dist/production/middleware/utils.js +1 -1
- package/dist/production/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/createNavigation.js +1 -1
- package/dist/production/navigation/react-client/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-client/useBaseRouter.js +1 -1
- package/dist/production/navigation/react-server/createLocalizedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/react-server/createSharedPathnamesNavigation.js +1 -1
- package/dist/production/navigation/shared/BaseLink.js +1 -1
- package/dist/production/navigation/shared/LegacyBaseLink.js +1 -1
- package/dist/production/navigation/shared/createSharedNavigationFns.js +1 -1
- package/dist/production/navigation/shared/syncLocaleCookie.js +1 -1
- package/dist/production/plugin.js +1 -1
- package/dist/production/routing/config.js +1 -1
- package/dist/production/server/react-client/index.js +1 -1
- package/dist/production/server/react-server/RequestLocale.js +1 -1
- package/dist/production/server/react-server/RequestLocaleLegacy.js +1 -1
- package/dist/production/server.react-client.js +1 -1
- package/dist/production/server.react-server.js +1 -1
- package/dist/production/shared/constants.js +1 -1
- package/dist/types/src/middleware/middleware.d.ts +10 -2
- package/dist/types/src/middleware/resolveLocale.d.ts +2 -3
- package/dist/types/src/middleware/syncCookie.d.ts +2 -2
- package/dist/types/src/middleware/utils.d.ts +1 -1
- package/dist/types/src/navigation/react-client/ClientLink.d.ts +1 -1
- package/dist/types/src/navigation/react-client/createLocalizedPathnamesNavigation.d.ts +5 -4
- package/dist/types/src/navigation/react-client/createNavigation.d.ts +14 -13
- package/dist/types/src/navigation/react-client/createSharedPathnamesNavigation.d.ts +5 -4
- package/dist/types/src/navigation/react-client/index.d.ts +1 -1
- package/dist/types/src/navigation/react-client/useBasePathname.d.ts +1 -1
- package/dist/types/src/navigation/react-client/useBaseRouter.d.ts +3 -2
- package/dist/types/src/navigation/react-server/ServerLink.d.ts +1 -1
- package/dist/types/src/navigation/react-server/createLocalizedPathnamesNavigation.d.ts +4 -3
- package/dist/types/src/navigation/react-server/createNavigation.d.ts +14 -13
- package/dist/types/src/navigation/react-server/createSharedPathnamesNavigation.d.ts +1 -1
- package/dist/types/src/navigation/shared/BaseLink.d.ts +2 -0
- package/dist/types/src/navigation/shared/LegacyBaseLink.d.ts +2 -0
- package/dist/types/src/navigation/shared/createSharedNavigationFns.d.ts +18 -14
- package/dist/types/src/navigation/shared/redirects.d.ts +1 -1
- package/dist/types/src/navigation/shared/syncLocaleCookie.d.ts +2 -1
- package/dist/types/src/react-client/index.d.ts +1 -1
- package/dist/types/src/react-server/getTranslator.d.ts +1 -1
- package/dist/types/src/routing/config.d.ts +30 -3
- package/dist/types/src/server/react-client/index.d.ts +2 -1
- package/dist/types/src/server/react-server/getRequestConfig.d.ts +1 -1
- package/dist/types/src/server/react-server/getTranslations.d.ts +1 -1
- package/dist/types/src/server/react-server/index.d.ts +4 -1
- package/dist/types/src/shared/constants.d.ts +0 -3
- package/dist/types/src/shared/utils.d.ts +4 -4
- package/package.json +5 -4
- package/dist/types/src/middleware/config.d.ts +0 -21
|
@@ -50,7 +50,7 @@ function getAlternateLinksHeaderValue(_ref) {
|
|
|
50
50
|
}
|
|
51
51
|
let url;
|
|
52
52
|
if (routing.domains) {
|
|
53
|
-
const domainConfigs = routing.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur))
|
|
53
|
+
const domainConfigs = routing.domains.filter(cur => utils.isLocaleSupportedOnDomain(locale, cur));
|
|
54
54
|
return domainConfigs.map(domainConfig => {
|
|
55
55
|
url = new URL(normalizedUrl);
|
|
56
56
|
url.port = '';
|
|
@@ -11,21 +11,22 @@ var resolveLocale = require('./resolveLocale.js');
|
|
|
11
11
|
var syncCookie = require('./syncCookie.js');
|
|
12
12
|
var utils = require('./utils.js');
|
|
13
13
|
|
|
14
|
-
function createMiddleware(routing,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
function createMiddleware(routing, /** @deprecated Should be passed via the first parameter `routing` instead (ideally defined with `defineRouting`) */
|
|
15
|
+
options) {
|
|
16
|
+
var _options$alternateLin, _options$localeDetect, _options$localeCookie;
|
|
17
|
+
const resolvedRouting = config.receiveRoutingConfig({
|
|
18
|
+
...routing,
|
|
19
|
+
alternateLinks: (_options$alternateLin = options === null || options === void 0 ? void 0 : options.alternateLinks) !== null && _options$alternateLin !== void 0 ? _options$alternateLin : routing.alternateLinks,
|
|
20
|
+
localeDetection: (_options$localeDetect = options === null || options === void 0 ? void 0 : options.localeDetection) !== null && _options$localeDetect !== void 0 ? _options$localeDetect : routing.localeDetection,
|
|
21
|
+
localeCookie: (_options$localeCookie = options === null || options === void 0 ? void 0 : options.localeCookie) !== null && _options$localeCookie !== void 0 ? _options$localeCookie : routing.localeCookie
|
|
22
|
+
});
|
|
22
23
|
return function middleware(request) {
|
|
23
24
|
var _resolvedRouting$doma;
|
|
24
25
|
let unsafeExternalPathname;
|
|
25
26
|
try {
|
|
26
27
|
// Resolve potential foreign symbols (e.g. /ja/%E7%B4%84 → /ja/約))
|
|
27
28
|
unsafeExternalPathname = decodeURI(request.nextUrl.pathname);
|
|
28
|
-
} catch (
|
|
29
|
+
} catch (_unused) {
|
|
29
30
|
// In case an invalid pathname is encountered, forward
|
|
30
31
|
// it to Next.js which in turn responds with a 400
|
|
31
32
|
return server.NextResponse.next();
|
|
@@ -37,7 +38,7 @@ function createMiddleware(routing, options) {
|
|
|
37
38
|
const {
|
|
38
39
|
domain,
|
|
39
40
|
locale
|
|
40
|
-
} = resolveLocale.default(resolvedRouting,
|
|
41
|
+
} = resolveLocale.default(resolvedRouting, request.headers, request.cookies, externalPathname);
|
|
41
42
|
const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === resolvedRouting.defaultLocale;
|
|
42
43
|
const domainsConfig = ((_resolvedRouting$doma = resolvedRouting.domains) === null || _resolvedRouting$doma === void 0 ? void 0 : _resolvedRouting$doma.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
|
|
43
44
|
const hasUnknownHost = resolvedRouting.domains != null && !domain;
|
|
@@ -91,18 +92,14 @@ function createMiddleware(routing, options) {
|
|
|
91
92
|
[resolvedTemplateLocale, internalTemplateName] = utils.getInternalTemplate(pathnames, unprefixedExternalPathname, locale);
|
|
92
93
|
if (internalTemplateName) {
|
|
93
94
|
const pathnameConfig = pathnames[internalTemplateName];
|
|
94
|
-
const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig :
|
|
95
|
-
// @ts-expect-error -- This is fine
|
|
96
|
-
pathnameConfig[locale];
|
|
95
|
+
const localeTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[locale];
|
|
97
96
|
if (utils$1.matchesPathname(localeTemplate, unprefixedExternalPathname)) {
|
|
98
97
|
unprefixedInternalPathname = utils.formatTemplatePathname(unprefixedExternalPathname, localeTemplate, internalTemplateName);
|
|
99
98
|
} else {
|
|
100
99
|
let sourceTemplate;
|
|
101
100
|
if (resolvedTemplateLocale) {
|
|
102
101
|
// A localized pathname from another locale has matched
|
|
103
|
-
sourceTemplate = typeof pathnameConfig === 'string' ? pathnameConfig :
|
|
104
|
-
// @ts-expect-error -- This is fine
|
|
105
|
-
pathnameConfig[resolvedTemplateLocale];
|
|
102
|
+
sourceTemplate = typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[resolvedTemplateLocale];
|
|
106
103
|
} else {
|
|
107
104
|
// An internal pathname has matched that
|
|
108
105
|
// doesn't have a localized pathname
|
|
@@ -154,13 +151,13 @@ function createMiddleware(routing, options) {
|
|
|
154
151
|
}
|
|
155
152
|
}
|
|
156
153
|
}
|
|
157
|
-
if (
|
|
158
|
-
syncCookie.default(request, response, locale,
|
|
154
|
+
if (resolvedRouting.localeDetection && resolvedRouting.localeCookie) {
|
|
155
|
+
syncCookie.default(request, response, locale, resolvedRouting.localeCookie);
|
|
159
156
|
}
|
|
160
|
-
if (resolvedRouting.localePrefix.mode !== 'never' &&
|
|
157
|
+
if (resolvedRouting.localePrefix.mode !== 'never' && resolvedRouting.alternateLinks && resolvedRouting.locales.length > 1) {
|
|
161
158
|
response.headers.set('Link', getAlternateLinksHeaderValue.default({
|
|
162
159
|
routing: resolvedRouting,
|
|
163
|
-
localizedPathnames: internalTemplateName != null && pathnames ? pathnames
|
|
160
|
+
localizedPathnames: internalTemplateName != null && pathnames ? pathnames[internalTemplateName] : undefined,
|
|
164
161
|
request,
|
|
165
162
|
resolvedLocale: locale
|
|
166
163
|
}));
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var intlLocalematcher = require('@formatjs/intl-localematcher');
|
|
6
6
|
var Negotiator = require('negotiator');
|
|
7
|
-
var constants = require('../shared/constants.js');
|
|
8
7
|
var utils = require('./utils.js');
|
|
9
8
|
|
|
10
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -13,7 +12,7 @@ var Negotiator__default = /*#__PURE__*/_interopDefault(Negotiator);
|
|
|
13
12
|
|
|
14
13
|
function findDomainFromHost(requestHeaders, domains) {
|
|
15
14
|
const host = utils.getHost(requestHeaders);
|
|
16
|
-
if (host
|
|
15
|
+
if (host) {
|
|
17
16
|
return domains.find(cur => cur.domain === host);
|
|
18
17
|
}
|
|
19
18
|
return undefined;
|
|
@@ -32,59 +31,51 @@ function getAcceptLanguageLocale(requestHeaders, locales, defaultLocale) {
|
|
|
32
31
|
try {
|
|
33
32
|
const orderedLocales = orderLocales(locales);
|
|
34
33
|
locale = intlLocalematcher.match(languages, orderedLocales, defaultLocale);
|
|
35
|
-
} catch (
|
|
34
|
+
} catch (_unused) {
|
|
36
35
|
// Invalid language
|
|
37
36
|
}
|
|
38
37
|
return locale;
|
|
39
38
|
}
|
|
40
|
-
function getLocaleFromCookie(
|
|
41
|
-
if (requestCookies.has(
|
|
39
|
+
function getLocaleFromCookie(routing, requestCookies) {
|
|
40
|
+
if (routing.localeCookie && requestCookies.has(routing.localeCookie.name)) {
|
|
42
41
|
var _requestCookies$get;
|
|
43
|
-
const value = (_requestCookies$get = requestCookies.get(
|
|
44
|
-
if (value && locales.includes(value)) {
|
|
42
|
+
const value = (_requestCookies$get = requestCookies.get(routing.localeCookie.name)) === null || _requestCookies$get === void 0 ? void 0 : _requestCookies$get.value;
|
|
43
|
+
if (value && routing.locales.includes(value)) {
|
|
45
44
|
return value;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
function resolveLocaleFromPrefix(
|
|
50
|
-
let {
|
|
51
|
-
defaultLocale,
|
|
52
|
-
localePrefix,
|
|
53
|
-
locales
|
|
54
|
-
} = _ref;
|
|
55
|
-
let {
|
|
56
|
-
localeDetection
|
|
57
|
-
} = _ref2;
|
|
48
|
+
function resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname) {
|
|
58
49
|
let locale;
|
|
59
50
|
|
|
60
51
|
// Prio 1: Use route prefix
|
|
61
52
|
if (pathname) {
|
|
62
53
|
var _getPathnameMatch;
|
|
63
|
-
locale = (_getPathnameMatch = utils.getPathnameMatch(pathname, locales, localePrefix)) === null || _getPathnameMatch === void 0 ? void 0 : _getPathnameMatch.locale;
|
|
54
|
+
locale = (_getPathnameMatch = utils.getPathnameMatch(pathname, routing.locales, routing.localePrefix)) === null || _getPathnameMatch === void 0 ? void 0 : _getPathnameMatch.locale;
|
|
64
55
|
}
|
|
65
56
|
|
|
66
57
|
// Prio 2: Use existing cookie
|
|
67
|
-
if (!locale && localeDetection
|
|
68
|
-
locale = getLocaleFromCookie(
|
|
58
|
+
if (!locale && routing.localeDetection) {
|
|
59
|
+
locale = getLocaleFromCookie(routing, requestCookies);
|
|
69
60
|
}
|
|
70
61
|
|
|
71
62
|
// Prio 3: Use the `accept-language` header
|
|
72
|
-
if (!locale && localeDetection
|
|
73
|
-
locale = getAcceptLanguageLocale(requestHeaders, locales, defaultLocale);
|
|
63
|
+
if (!locale && routing.localeDetection) {
|
|
64
|
+
locale = getAcceptLanguageLocale(requestHeaders, routing.locales, routing.defaultLocale);
|
|
74
65
|
}
|
|
75
66
|
|
|
76
67
|
// Prio 4: Use default locale
|
|
77
68
|
if (!locale) {
|
|
78
|
-
locale = defaultLocale;
|
|
69
|
+
locale = routing.defaultLocale;
|
|
79
70
|
}
|
|
80
71
|
return locale;
|
|
81
72
|
}
|
|
82
|
-
function resolveLocaleFromDomain(routing,
|
|
73
|
+
function resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathname) {
|
|
83
74
|
const domains = routing.domains;
|
|
84
75
|
const domain = findDomainFromHost(requestHeaders, domains);
|
|
85
76
|
if (!domain) {
|
|
86
77
|
return {
|
|
87
|
-
locale: resolveLocaleFromPrefix(routing,
|
|
78
|
+
locale: resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname)
|
|
88
79
|
};
|
|
89
80
|
}
|
|
90
81
|
let locale;
|
|
@@ -107,8 +98,8 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
|
|
|
107
98
|
}
|
|
108
99
|
|
|
109
100
|
// Prio 2: Use existing cookie
|
|
110
|
-
if (!locale &&
|
|
111
|
-
const cookieLocale = getLocaleFromCookie(
|
|
101
|
+
if (!locale && routing.localeDetection) {
|
|
102
|
+
const cookieLocale = getLocaleFromCookie(routing, requestCookies);
|
|
112
103
|
if (cookieLocale) {
|
|
113
104
|
if (utils.isLocaleSupportedOnDomain(cookieLocale, domain)) {
|
|
114
105
|
locale = cookieLocale;
|
|
@@ -117,7 +108,7 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
|
|
|
117
108
|
}
|
|
118
109
|
|
|
119
110
|
// Prio 3: Use the `accept-language` header
|
|
120
|
-
if (!locale &&
|
|
111
|
+
if (!locale && routing.localeDetection) {
|
|
121
112
|
const headerLocale = getAcceptLanguageLocale(requestHeaders, domain.locales || routing.locales, domain.defaultLocale);
|
|
122
113
|
if (headerLocale) {
|
|
123
114
|
locale = headerLocale;
|
|
@@ -133,12 +124,12 @@ function resolveLocaleFromDomain(routing, options, requestHeaders, requestCookie
|
|
|
133
124
|
domain
|
|
134
125
|
};
|
|
135
126
|
}
|
|
136
|
-
function resolveLocale(routing,
|
|
127
|
+
function resolveLocale(routing, requestHeaders, requestCookies, pathname) {
|
|
137
128
|
if (routing.domains) {
|
|
138
|
-
return resolveLocaleFromDomain(routing,
|
|
129
|
+
return resolveLocaleFromDomain(routing, requestHeaders, requestCookies, pathname);
|
|
139
130
|
} else {
|
|
140
131
|
return {
|
|
141
|
-
locale: resolveLocaleFromPrefix(routing,
|
|
132
|
+
locale: resolveLocaleFromPrefix(routing, requestHeaders, requestCookies, pathname)
|
|
142
133
|
};
|
|
143
134
|
}
|
|
144
135
|
}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var constants = require('../shared/constants.js');
|
|
6
|
-
|
|
7
5
|
function syncCookie(request, response, locale, localeCookie) {
|
|
8
6
|
var _request$cookies$get;
|
|
9
|
-
const
|
|
7
|
+
const {
|
|
8
|
+
name,
|
|
9
|
+
...rest
|
|
10
|
+
} = localeCookie;
|
|
11
|
+
const hasOutdatedCookie = ((_request$cookies$get = request.cookies.get(name)) === null || _request$cookies$get === void 0 ? void 0 : _request$cookies$get.value) !== locale;
|
|
10
12
|
if (hasOutdatedCookie) {
|
|
11
|
-
response.cookies.set(
|
|
13
|
+
response.cookies.set(name, locale, {
|
|
12
14
|
path: request.nextUrl.basePath || undefined,
|
|
13
|
-
|
|
14
|
-
maxAge: constants.COOKIE_MAX_AGE,
|
|
15
|
-
...(typeof localeCookie === 'object' && localeCookie)
|
|
15
|
+
...rest
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -170,7 +170,10 @@ function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
|
|
|
170
170
|
|
|
171
171
|
// Prio 3: Use alternative domain with restricted matching locale
|
|
172
172
|
if (!domainConfig) {
|
|
173
|
-
domainConfig = domainsConfig.find(cur =>
|
|
173
|
+
domainConfig = domainsConfig.find(cur => {
|
|
174
|
+
var _cur$locales;
|
|
175
|
+
return (_cur$locales = cur.locales) === null || _cur$locales === void 0 ? void 0 : _cur$locales.includes(locale);
|
|
176
|
+
});
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
// Prio 4: Stay on the current domain if it supports all locales
|
|
@@ -17,10 +17,11 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
17
17
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @deprecated Consider switching to `createNavigation` (see https://
|
|
20
|
+
* @deprecated Consider switching to `createNavigation` (see https://next-intl-docs.vercel.app/blog/next-intl-3-22#create-navigation)
|
|
21
21
|
**/
|
|
22
22
|
function createLocalizedPathnamesNavigation(routing) {
|
|
23
23
|
const config$1 = config.receiveRoutingConfig(routing);
|
|
24
|
+
const localeCookie = config.receiveLocaleCookie(routing.localeCookie);
|
|
24
25
|
function useTypedLocale() {
|
|
25
26
|
const locale = useLocale.default();
|
|
26
27
|
const isValid = config$1.locales.includes(locale);
|
|
@@ -48,6 +49,7 @@ function createLocalizedPathnamesNavigation(routing) {
|
|
|
48
49
|
pathnames: config$1.pathnames
|
|
49
50
|
}),
|
|
50
51
|
locale: locale,
|
|
52
|
+
localeCookie: localeCookie,
|
|
51
53
|
localePrefix: config$1.localePrefix
|
|
52
54
|
}, rest));
|
|
53
55
|
}
|
|
@@ -84,7 +86,7 @@ function createLocalizedPathnamesNavigation(routing) {
|
|
|
84
86
|
}, ...args);
|
|
85
87
|
}
|
|
86
88
|
function useRouter() {
|
|
87
|
-
const baseRouter = useBaseRouter.default(config$1.localePrefix);
|
|
89
|
+
const baseRouter = useBaseRouter.default(config$1.localePrefix, localeCookie);
|
|
88
90
|
const defaultLocale = useTypedLocale();
|
|
89
91
|
return React.useMemo(() => ({
|
|
90
92
|
...baseRouter,
|
|
@@ -15,13 +15,15 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
15
15
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @deprecated Consider switching to `createNavigation` (see https://
|
|
18
|
+
* @deprecated Consider switching to `createNavigation` (see https://next-intl-docs.vercel.app/blog/next-intl-3-22#create-navigation)
|
|
19
19
|
**/
|
|
20
20
|
function createSharedPathnamesNavigation(routing) {
|
|
21
21
|
const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
|
|
22
|
+
const localeCookie = config.receiveLocaleCookie(routing === null || routing === void 0 ? void 0 : routing.localeCookie);
|
|
22
23
|
function Link(props, ref) {
|
|
23
24
|
return /*#__PURE__*/React__default.default.createElement(ClientLink.default, _rollupPluginBabelHelpers.extends({
|
|
24
25
|
ref: ref,
|
|
26
|
+
localeCookie: localeCookie,
|
|
25
27
|
localePrefix: localePrefix
|
|
26
28
|
}, props));
|
|
27
29
|
}
|
|
@@ -51,7 +53,7 @@ function createSharedPathnamesNavigation(routing) {
|
|
|
51
53
|
return result;
|
|
52
54
|
}
|
|
53
55
|
function useRouter() {
|
|
54
|
-
return useBaseRouter.default(localePrefix);
|
|
56
|
+
return useBaseRouter.default(localePrefix, localeCookie);
|
|
55
57
|
}
|
|
56
58
|
return {
|
|
57
59
|
Link: LinkWithRef,
|
|
@@ -28,7 +28,7 @@ var utils = require('../shared/utils.js');
|
|
|
28
28
|
* router.push('/about', {locale: 'de'});
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
function useBaseRouter(localePrefix) {
|
|
31
|
+
function useBaseRouter(localePrefix, localeCookie) {
|
|
32
32
|
const router = navigation.useRouter();
|
|
33
33
|
const locale = useLocale.default();
|
|
34
34
|
const pathname = navigation.usePathname();
|
|
@@ -50,7 +50,7 @@ function useBaseRouter(localePrefix) {
|
|
|
50
50
|
locale: nextLocale,
|
|
51
51
|
...rest
|
|
52
52
|
} = options || {};
|
|
53
|
-
syncLocaleCookie.default(pathname, locale, nextLocale);
|
|
53
|
+
syncLocaleCookie.default(localeCookie, pathname, locale, nextLocale);
|
|
54
54
|
const args = [localize(href, nextLocale)];
|
|
55
55
|
if (Object.keys(rest).length > 0) {
|
|
56
56
|
args.push(rest);
|
|
@@ -66,7 +66,7 @@ function useBaseRouter(localePrefix) {
|
|
|
66
66
|
replace: createHandler(router.replace),
|
|
67
67
|
prefetch: createHandler(router.prefetch)
|
|
68
68
|
};
|
|
69
|
-
}, [locale, localePrefix, pathname, router]);
|
|
69
|
+
}, [locale, localeCookie, localePrefix, pathname, router]);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
exports.default = useBaseRouter;
|
|
@@ -14,6 +14,7 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
14
14
|
|
|
15
15
|
function createSharedPathnamesNavigation(routing) {
|
|
16
16
|
const localePrefix = config.receiveLocalePrefixConfig(routing === null || routing === void 0 ? void 0 : routing.localePrefix);
|
|
17
|
+
const localeCookie = config.receiveLocaleCookie(routing === null || routing === void 0 ? void 0 : routing.localeCookie);
|
|
17
18
|
function notSupported(hookName) {
|
|
18
19
|
return () => {
|
|
19
20
|
throw new Error("`".concat(hookName, "` is not supported in Server Components. You can use this hook if you convert the component to a Client Component."));
|
|
@@ -21,6 +22,7 @@ function createSharedPathnamesNavigation(routing) {
|
|
|
21
22
|
}
|
|
22
23
|
function Link(props) {
|
|
23
24
|
return /*#__PURE__*/React__default.default.createElement(ServerLink.default, _rollupPluginBabelHelpers.extends({
|
|
25
|
+
localeCookie: localeCookie,
|
|
24
26
|
localePrefix: localePrefix
|
|
25
27
|
}, props));
|
|
26
28
|
}
|
|
@@ -20,6 +20,7 @@ function BaseLink(_ref, ref) {
|
|
|
20
20
|
defaultLocale,
|
|
21
21
|
href,
|
|
22
22
|
locale,
|
|
23
|
+
localeCookie,
|
|
23
24
|
onClick,
|
|
24
25
|
prefetch,
|
|
25
26
|
unprefixed,
|
|
@@ -45,7 +46,7 @@ function BaseLink(_ref, ref) {
|
|
|
45
46
|
// `useParams` can be called, but the return type is `null`.
|
|
46
47
|
const pathname = navigation.usePathname();
|
|
47
48
|
function onLinkClick(event) {
|
|
48
|
-
syncLocaleCookie.default(pathname, curLocale, locale);
|
|
49
|
+
syncLocaleCookie.default(localeCookie, pathname, curLocale, locale);
|
|
49
50
|
if (onClick) onClick(event);
|
|
50
51
|
}
|
|
51
52
|
if (isChangingLocale) {
|
|
@@ -18,6 +18,7 @@ function LegacyBaseLink(_ref, ref) {
|
|
|
18
18
|
let {
|
|
19
19
|
href,
|
|
20
20
|
locale,
|
|
21
|
+
localeCookie,
|
|
21
22
|
localePrefixMode,
|
|
22
23
|
prefix,
|
|
23
24
|
...rest
|
|
@@ -46,7 +47,8 @@ function LegacyBaseLink(_ref, ref) {
|
|
|
46
47
|
return /*#__PURE__*/React__default.default.createElement(BaseLink.default, _rollupPluginBabelHelpers.extends({
|
|
47
48
|
ref: ref,
|
|
48
49
|
href: localizedHref,
|
|
49
|
-
locale: locale
|
|
50
|
+
locale: locale,
|
|
51
|
+
localeCookie: localeCookie
|
|
50
52
|
}, rest));
|
|
51
53
|
}
|
|
52
54
|
const LegacyBaseLinkWithRef = /*#__PURE__*/React.forwardRef(LegacyBaseLink);
|
|
@@ -69,7 +69,8 @@ function createSharedNavigationFns(getLocale, routing) {
|
|
|
69
69
|
// @ts-expect-error -- This is ok
|
|
70
70
|
pathname: finalPathname
|
|
71
71
|
},
|
|
72
|
-
locale: locale
|
|
72
|
+
locale: locale,
|
|
73
|
+
localeCookie: config$1.localeCookie
|
|
73
74
|
// Provide the minimal relevant information to the client side in order
|
|
74
75
|
// to potentially remove the prefix in case of the `forcePrefixSsr` case
|
|
75
76
|
,
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var constants = require('../../shared/constants.js');
|
|
6
5
|
var utils = require('./utils.js');
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -10,9 +9,9 @@ var utils = require('./utils.js');
|
|
|
10
9
|
* skip a request to the server due to its router cache.
|
|
11
10
|
* See https://github.com/amannn/next-intl/issues/786.
|
|
12
11
|
*/
|
|
13
|
-
function syncLocaleCookie(pathname, locale, nextLocale) {
|
|
12
|
+
function syncLocaleCookie(localeCookie, pathname, locale, nextLocale) {
|
|
14
13
|
const isSwitchingLocale = nextLocale !== locale && nextLocale != null;
|
|
15
|
-
if (!isSwitchingLocale ||
|
|
14
|
+
if (!localeCookie || !isSwitchingLocale ||
|
|
16
15
|
// Theoretical case, we always have a pathname in a real app,
|
|
17
16
|
// only not when running e.g. in a simulated test environment
|
|
18
17
|
!pathname) {
|
|
@@ -20,11 +19,33 @@ function syncLocaleCookie(pathname, locale, nextLocale) {
|
|
|
20
19
|
}
|
|
21
20
|
const basePath = utils.getBasePath(pathname);
|
|
22
21
|
const hasBasePath = basePath !== '';
|
|
23
|
-
const
|
|
22
|
+
const defaultPath = hasBasePath ? basePath : '/';
|
|
23
|
+
const {
|
|
24
|
+
name,
|
|
25
|
+
...rest
|
|
26
|
+
} = localeCookie;
|
|
27
|
+
if (!rest.path) {
|
|
28
|
+
rest.path = defaultPath;
|
|
29
|
+
}
|
|
30
|
+
let localeCookieString = "".concat(name, "=").concat(nextLocale, ";");
|
|
31
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
32
|
+
// Map object properties to cookie properties.
|
|
33
|
+
// Interestingly, `maxAge` corresponds to `max-age`,
|
|
34
|
+
// while `sameSite` corresponds to `SameSite`.
|
|
35
|
+
// Also, keys are case-insensitive.
|
|
36
|
+
const targetKey = key === 'maxAge' ? 'max-age' : key;
|
|
37
|
+
localeCookieString += "".concat(targetKey);
|
|
38
|
+
if (typeof value !== 'boolean') {
|
|
39
|
+
localeCookieString += '=' + value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A trailing ";" is allowed by browsers
|
|
43
|
+
localeCookieString += ';';
|
|
44
|
+
}
|
|
24
45
|
|
|
25
46
|
// Note that writing to `document.cookie` doesn't overwrite all
|
|
26
47
|
// cookies, but only the ones referenced via the name here.
|
|
27
|
-
document.cookie =
|
|
48
|
+
document.cookie = localeCookieString;
|
|
28
49
|
}
|
|
29
50
|
|
|
30
51
|
exports.default = syncLocaleCookie;
|
|
@@ -13,6 +13,7 @@ var path__default = /*#__PURE__*/_interopDefault(path);
|
|
|
13
13
|
function withExtensions(localPath) {
|
|
14
14
|
return ["".concat(localPath, ".ts"), "".concat(localPath, ".tsx"), "".concat(localPath, ".js"), "".concat(localPath, ".jsx")];
|
|
15
15
|
}
|
|
16
|
+
let hasWarnedForDeprecatedI18nConfig = false;
|
|
16
17
|
function resolveI18nPath(providedPath, cwd) {
|
|
17
18
|
function resolvePath(pathname) {
|
|
18
19
|
const parts = [];
|
|
@@ -25,21 +26,30 @@ function resolveI18nPath(providedPath, cwd) {
|
|
|
25
26
|
}
|
|
26
27
|
if (providedPath) {
|
|
27
28
|
if (!pathExists(providedPath)) {
|
|
28
|
-
throw new Error("Could not find i18n config at ".concat(providedPath, ", please provide a valid path."));
|
|
29
|
+
throw new Error("[next-intl] Could not find i18n config at ".concat(providedPath, ", please provide a valid path."));
|
|
29
30
|
}
|
|
30
31
|
return providedPath;
|
|
31
32
|
} else {
|
|
32
|
-
for (const candidate of [...withExtensions('./i18n
|
|
33
|
+
for (const candidate of [...withExtensions('./i18n/request'), ...withExtensions('./src/i18n/request')]) {
|
|
33
34
|
if (pathExists(candidate)) {
|
|
34
35
|
return candidate;
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
for (const candidate of [...withExtensions('./i18n'), ...withExtensions('./src/i18n')]) {
|
|
39
|
+
if (pathExists(candidate)) {
|
|
40
|
+
if (!hasWarnedForDeprecatedI18nConfig) {
|
|
41
|
+
console.warn("\n[next-intl] Reading request configuration from ".concat(candidate, " is deprecated, please see https://next-intl-docs.vercel.app/blog/next-intl-3-22#i18n-request \u2014 you can either move your configuration to ./i18n/request.ts or provide a custom path in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(\n './path/to/i18n/request.tsx'\n);\n"));
|
|
42
|
+
hasWarnedForDeprecatedI18nConfig = true;
|
|
43
|
+
}
|
|
44
|
+
return candidate;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error("\n[next-intl] Could not locate request configuration module.\n\nThis path is supported by default: ./(src/)i18n/request.{js,jsx,ts,tsx}\n\nAlternatively, you can specify a custom location in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(\n './path/to/i18n/request.tsx'\n);\n");
|
|
38
48
|
}
|
|
39
49
|
}
|
|
40
50
|
function initPlugin(i18nPath, nextConfig) {
|
|
41
51
|
if ((nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.i18n) != null) {
|
|
42
|
-
console.warn("\
|
|
52
|
+
console.warn("\n[next-intl] An `i18n` property was found in your Next.js config. This likely causes conflicts and should therefore be removed if you use the App Router.\n\nIf you're in progress of migrating from the Pages Router, you can refer to this example: https://next-intl-docs.vercel.app/examples#app-router-migration\n");
|
|
43
53
|
}
|
|
44
54
|
const useTurbo = process.env.TURBOPACK != null;
|
|
45
55
|
const nextIntlConfig = {};
|
|
@@ -47,8 +57,8 @@ function initPlugin(i18nPath, nextConfig) {
|
|
|
47
57
|
// Assign alias for `next-intl/config`
|
|
48
58
|
if (useTurbo) {
|
|
49
59
|
var _nextConfig$experimen, _nextConfig$experimen2;
|
|
50
|
-
if (i18nPath && i18nPath.startsWith('/')) {
|
|
51
|
-
throw new Error("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: " + i18nPath + '\n');
|
|
60
|
+
if (i18nPath !== null && i18nPath !== void 0 && i18nPath.startsWith('/')) {
|
|
61
|
+
throw new Error("[next-intl] Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: " + i18nPath + '\n');
|
|
52
62
|
}
|
|
53
63
|
nextIntlConfig.experimental = {
|
|
54
64
|
...(nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental),
|
|
@@ -14,11 +14,13 @@ var useIntl = require('use-intl');
|
|
|
14
14
|
* supported in all Next.js versions that are supported.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
17
19
|
function callHook(name, hook) {
|
|
18
20
|
return function () {
|
|
19
21
|
try {
|
|
20
22
|
return hook(...arguments);
|
|
21
|
-
} catch (
|
|
23
|
+
} catch (_unused) {
|
|
22
24
|
throw new Error("Failed to call `".concat(name, "` because the context from `NextIntlClientProvider` was not found.\n\nThis can happen because:\n1) You intended to render this component as a Server Component, the render\n failed, and therefore React attempted to render the component on the client\n instead. If this is the case, check the console for server errors.\n2) You intended to render this component on the client side, but no context was found.\n Learn more about this error here: https://next-intl-docs.vercel.app/docs/environments/server-client-components#missing-context") );
|
|
23
25
|
}
|
|
24
26
|
};
|
|
@@ -3,16 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
function receiveRoutingConfig(input) {
|
|
6
|
+
var _input$localeDetectio, _input$alternateLinks;
|
|
6
7
|
return {
|
|
7
8
|
...input,
|
|
8
|
-
localePrefix: receiveLocalePrefixConfig(input
|
|
9
|
+
localePrefix: receiveLocalePrefixConfig(input.localePrefix),
|
|
10
|
+
localeCookie: receiveLocaleCookie(input.localeCookie),
|
|
11
|
+
localeDetection: (_input$localeDetectio = input.localeDetection) !== null && _input$localeDetectio !== void 0 ? _input$localeDetectio : true,
|
|
12
|
+
alternateLinks: (_input$alternateLinks = input.alternateLinks) !== null && _input$alternateLinks !== void 0 ? _input$alternateLinks : true
|
|
9
13
|
};
|
|
10
14
|
}
|
|
15
|
+
function receiveLocaleCookie(localeCookie) {
|
|
16
|
+
return (localeCookie !== null && localeCookie !== void 0 ? localeCookie : true) ? {
|
|
17
|
+
name: 'NEXT_LOCALE',
|
|
18
|
+
maxAge: 31536000,
|
|
19
|
+
// 1 year
|
|
20
|
+
sameSite: 'lax',
|
|
21
|
+
...(typeof localeCookie === 'object' && localeCookie)
|
|
22
|
+
|
|
23
|
+
// `path` needs to be provided based on a detected base path
|
|
24
|
+
// that depends on the environment when setting a cookie
|
|
25
|
+
} : false;
|
|
26
|
+
}
|
|
11
27
|
function receiveLocalePrefixConfig(localePrefix) {
|
|
12
28
|
return typeof localePrefix === 'object' ? localePrefix : {
|
|
13
29
|
mode: localePrefix || 'always'
|
|
14
30
|
};
|
|
15
31
|
}
|
|
16
32
|
|
|
33
|
+
exports.receiveLocaleCookie = receiveLocaleCookie;
|
|
17
34
|
exports.receiveLocalePrefixConfig = receiveLocalePrefixConfig;
|
|
18
35
|
exports.receiveRoutingConfig = receiveRoutingConfig;
|
|
@@ -29,6 +29,7 @@ const getLocale = notSupported('getLocale');
|
|
|
29
29
|
// anyway, therefore this is irrelevant.
|
|
30
30
|
const getTranslations = notSupported('getTranslations');
|
|
31
31
|
const unstable_setRequestLocale = notSupported('unstable_setRequestLocale');
|
|
32
|
+
const setRequestLocale = notSupported('setRequestLocale');
|
|
32
33
|
|
|
33
34
|
exports.getFormatter = getFormatter;
|
|
34
35
|
exports.getLocale = getLocale;
|
|
@@ -37,4 +38,5 @@ exports.getNow = getNow;
|
|
|
37
38
|
exports.getRequestConfig = getRequestConfig;
|
|
38
39
|
exports.getTimeZone = getTimeZone;
|
|
39
40
|
exports.getTranslations = getTranslations;
|
|
41
|
+
exports.setRequestLocale = setRequestLocale;
|
|
40
42
|
exports.unstable_setRequestLocale = unstable_setRequestLocale;
|
|
@@ -20,7 +20,7 @@ async function getLocaleFromHeaderImpl() {
|
|
|
20
20
|
locale = (await getHeaders()).get(constants.HEADER_LOCALE_NAME) || undefined;
|
|
21
21
|
} catch (error) {
|
|
22
22
|
if (error instanceof Error && error.digest === 'DYNAMIC_SERVER_USAGE') {
|
|
23
|
-
const wrappedError = new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `
|
|
23
|
+
const wrappedError = new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `setRequestLocale` API to enable static rendering, see https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#static-rendering', {
|
|
24
24
|
cause: error
|
|
25
25
|
});
|
|
26
26
|
wrappedError.digest = error.digest;
|
|
@@ -20,7 +20,7 @@ function getLocaleFromHeaderImpl() {
|
|
|
20
20
|
locale = getHeaders().get(constants.HEADER_LOCALE_NAME);
|
|
21
21
|
} catch (error) {
|
|
22
22
|
if (error instanceof Error && error.digest === 'DYNAMIC_SERVER_USAGE') {
|
|
23
|
-
throw new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `
|
|
23
|
+
throw new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `setRequestLocale` API to enable static rendering, see https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#static-rendering', {
|
|
24
24
|
cause: error
|
|
25
25
|
});
|
|
26
26
|
} else {
|
|
@@ -8,7 +8,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
8
8
|
|
|
9
9
|
var getRuntimeConfig__default = /*#__PURE__*/_interopDefault(getRuntimeConfig);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, "default", {
|
|
14
14
|
enumerable: true,
|
|
@@ -13,4 +13,5 @@ exports.getNow = index.getNow;
|
|
|
13
13
|
exports.getRequestConfig = index.getRequestConfig;
|
|
14
14
|
exports.getTimeZone = index.getTimeZone;
|
|
15
15
|
exports.getTranslations = index.getTranslations;
|
|
16
|
+
exports.setRequestLocale = index.setRequestLocale;
|
|
16
17
|
exports.unstable_setRequestLocale = index.unstable_setRequestLocale;
|