next-intl 3.15.3 → 3.15.4
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/middleware.js +4 -4
- package/dist/development/middleware/utils.js +4 -4
- package/dist/types/src/middleware/resolveLocale.d.ts +1 -1
- package/dist/types/src/middleware/utils.d.ts +2 -2
- package/dist/types/src/routing/config.d.ts +2 -2
- package/dist/types/src/routing/index.d.ts +1 -2
- package/dist/types/src/routing/types.d.ts +2 -1
- package/package.json +3 -3
|
@@ -22,7 +22,7 @@ function createMiddleware(input) {
|
|
|
22
22
|
locale
|
|
23
23
|
} = resolveLocale.default(config$1, request.headers, request.cookies, externalPathname);
|
|
24
24
|
const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === config$1.defaultLocale;
|
|
25
|
-
const
|
|
25
|
+
const domainsConfig = ((_config$domains = config$1.domains) === null || _config$domains === void 0 ? void 0 : _config$domains.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
|
|
26
26
|
const hasUnknownHost = config$1.domains != null && !domain;
|
|
27
27
|
function rewrite(url) {
|
|
28
28
|
const urlObj = new URL(url, request.url);
|
|
@@ -39,8 +39,8 @@ function createMiddleware(input) {
|
|
|
39
39
|
}
|
|
40
40
|
function redirect(url, redirectDomain) {
|
|
41
41
|
const urlObj = new URL(utils.normalizeTrailingSlash(url), request.url);
|
|
42
|
-
if (
|
|
43
|
-
const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale,
|
|
42
|
+
if (domainsConfig.length > 0 && !redirectDomain) {
|
|
43
|
+
const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainsConfig);
|
|
44
44
|
if (bestMatchingDomain) {
|
|
45
45
|
redirectDomain = bestMatchingDomain.domain;
|
|
46
46
|
if (bestMatchingDomain.defaultLocale === locale && config$1.localePrefix.mode === 'as-needed') {
|
|
@@ -114,7 +114,7 @@ function createMiddleware(input) {
|
|
|
114
114
|
response = redirect(utils.formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
|
|
115
115
|
} else {
|
|
116
116
|
if (config$1.domains) {
|
|
117
|
-
const pathDomain = utils.getBestMatchingDomain(domain, pathnameMatch.locale,
|
|
117
|
+
const pathDomain = utils.getBestMatchingDomain(domain, pathnameMatch.locale, domainsConfig);
|
|
118
118
|
if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
|
|
119
119
|
response = redirect(externalHref, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
|
|
120
120
|
} else {
|
|
@@ -143,7 +143,7 @@ function getHost(requestHeaders) {
|
|
|
143
143
|
function isLocaleSupportedOnDomain(locale, domain) {
|
|
144
144
|
return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
|
|
145
145
|
}
|
|
146
|
-
function getBestMatchingDomain(curHostDomain, locale,
|
|
146
|
+
function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
|
|
147
147
|
let domainConfig;
|
|
148
148
|
|
|
149
149
|
// Prio 1: Stay on current domain
|
|
@@ -153,12 +153,12 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
|
|
|
153
153
|
|
|
154
154
|
// Prio 2: Use alternative domain with matching default locale
|
|
155
155
|
if (!domainConfig) {
|
|
156
|
-
domainConfig =
|
|
156
|
+
domainConfig = domainsConfig.find(cur => cur.defaultLocale === locale);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
// Prio 3: Use alternative domain with restricted matching locale
|
|
160
160
|
if (!domainConfig) {
|
|
161
|
-
domainConfig =
|
|
161
|
+
domainConfig = domainsConfig.find(cur => cur.locales != null && cur.locales.includes(locale));
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// Prio 4: Stay on the current domain if it supports all locales
|
|
@@ -168,7 +168,7 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
|
|
|
168
168
|
|
|
169
169
|
// Prio 5: Use alternative domain that supports all locales
|
|
170
170
|
if (!domainConfig) {
|
|
171
|
-
domainConfig =
|
|
171
|
+
domainConfig = domainsConfig.find(cur => !cur.locales);
|
|
172
172
|
}
|
|
173
173
|
return domainConfig;
|
|
174
174
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
|
|
2
|
-
import { Locales,
|
|
2
|
+
import { Locales, Pathnames, DomainConfig } from '../routing/types';
|
|
3
3
|
import { MiddlewareRoutingConfig } from './config';
|
|
4
4
|
export declare function getAcceptLanguageLocale<AppLocales extends Locales>(requestHeaders: Headers, locales: AppLocales, defaultLocale: string): string | undefined;
|
|
5
5
|
export default function resolveLocale<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(config: MiddlewareRoutingConfig<AppLocales, AppPathnames>, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Locales, LocalePrefixConfigVerbose, DomainConfig, Pathnames } from '../routing/types';
|
|
1
|
+
import { Locales, LocalePrefixConfigVerbose, DomainConfig, Pathnames, DomainsConfig } from '../routing/types';
|
|
2
2
|
export declare function getFirstPathnameSegment(pathname: string): string;
|
|
3
3
|
export declare function getInternalTemplate<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(pathnames: AppPathnames, pathname: string, locale: AppLocales[number]): [AppLocales[number] | undefined, keyof AppPathnames | undefined];
|
|
4
4
|
export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, prefix?: string): string;
|
|
@@ -19,7 +19,7 @@ export declare function formatPathnameTemplate(template: string, params?: object
|
|
|
19
19
|
export declare function formatPathname(pathname: string, prefix: string | undefined, search: string | undefined): string;
|
|
20
20
|
export declare function getHost(requestHeaders: Headers): string | undefined;
|
|
21
21
|
export declare function isLocaleSupportedOnDomain<AppLocales extends Locales>(locale: string, domain: DomainConfig<AppLocales>): boolean;
|
|
22
|
-
export declare function getBestMatchingDomain<AppLocales extends Locales>(curHostDomain: DomainConfig<AppLocales> | undefined, locale: string,
|
|
22
|
+
export declare function getBestMatchingDomain<AppLocales extends Locales>(curHostDomain: DomainConfig<AppLocales> | undefined, locale: string, domainsConfig: DomainsConfig<AppLocales>): DomainConfig<AppLocales> | undefined;
|
|
23
23
|
export declare function applyBasePath(pathname: string, basePath: string): string;
|
|
24
24
|
export declare function normalizeTrailingSlash(pathname: string): string;
|
|
25
25
|
export declare function getLocaleAsPrefix<AppLocales extends Locales>(locale: AppLocales[number]): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Locales,
|
|
1
|
+
import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Maintainer note: The config that is accepted by the middleware, the shared
|
|
4
4
|
* and the localized pathnames navigation factory function is slightly
|
|
@@ -9,6 +9,6 @@ export type RoutingBaseConfigInput<AppLocales extends Locales> = {
|
|
|
9
9
|
/** @see https://next-intl-docs.vercel.app/docs/routing#locale-prefix */
|
|
10
10
|
localePrefix?: LocalePrefix<AppLocales>;
|
|
11
11
|
/** Can be used to change the locale handling per domain. */
|
|
12
|
-
domains?:
|
|
12
|
+
domains?: DomainsConfig<AppLocales>;
|
|
13
13
|
};
|
|
14
14
|
export declare function receiveLocalePrefixConfig<AppLocales extends Locales>(localePrefix?: LocalePrefix<AppLocales>): LocalePrefixConfigVerbose<AppLocales>;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export type { LocalePrefix } from './types';
|
|
2
|
-
export type { Pathnames } from './types';
|
|
1
|
+
export type { Pathnames, LocalePrefix, DomainsConfig } from './types';
|
|
@@ -18,6 +18,7 @@ export type DomainConfig<AppLocales extends Locales> = {
|
|
|
18
18
|
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
19
19
|
domain: string;
|
|
20
20
|
/** Optionally restrict which locales are available on this domain. */
|
|
21
|
-
locales?: AppLocales
|
|
21
|
+
locales?: Array<AppLocales[number]>;
|
|
22
22
|
};
|
|
23
|
+
export type DomainsConfig<AppLocales extends Locales> = Array<DomainConfig<AppLocales>>;
|
|
23
24
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"author": "Jan Amann <jan@amann.work>",
|
|
6
6
|
"funding": [
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"dependencies": {
|
|
88
88
|
"@formatjs/intl-localematcher": "^0.2.32",
|
|
89
89
|
"negotiator": "^0.6.3",
|
|
90
|
-
"use-intl": "^3.15.
|
|
90
|
+
"use-intl": "^3.15.4"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"limit": "0 KB"
|
|
128
128
|
}
|
|
129
129
|
],
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "cb005a5680d06a6d78cef974b9b9e4deec3d2488"
|
|
131
131
|
}
|