next-intl 3.16.0-dc8fb0d.0 → 3.16.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 +2 -0
- package/dist/development/middleware/middleware.js +5 -5
- package/dist/development/middleware/utils.js +19 -68
- package/dist/development/navigation/react-client/createLocalizedPathnamesNavigation.js +1 -5
- package/dist/development/navigation/shared/redirects.js +1 -1
- package/dist/development/navigation/shared/utils.js +15 -15
- package/dist/development/plugin.js +29 -25
- package/dist/development/shared/utils.js +72 -4
- package/dist/esm/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/esm/middleware/middleware.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/shared/redirects.js +1 -1
- package/dist/esm/navigation/shared/utils.js +1 -1
- package/dist/esm/plugin.js +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/production/middleware/getAlternateLinksHeaderValue.js +1 -1
- package/dist/production/middleware/middleware.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/shared/redirects.js +1 -1
- package/dist/production/navigation/shared/utils.js +1 -1
- package/dist/production/plugin.js +1 -1
- package/dist/production/shared/utils.js +1 -1
- package/dist/types/src/middleware/resolveLocale.d.ts +1 -1
- package/dist/types/src/middleware/utils.d.ts +2 -5
- package/dist/types/src/navigation/react-client/ClientLink.d.ts +3 -39
- package/dist/types/src/navigation/shared/utils.d.ts +1 -5
- 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/dist/types/src/shared/utils.d.ts +2 -2
- package/package.json +7 -7
- /package/dist/types/{test → src}/middleware/getAlternateLinksHeaderValue.test.d.ts +0 -0
- /package/dist/types/{test → src}/middleware/middleware.test.d.ts +0 -0
- /package/dist/types/{test → src}/middleware/resolveLocale.test.d.ts +0 -0
- /package/dist/types/{test → src}/middleware/utils.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/createLocalizedPathnamesNavigation.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/createSharedPathnamesNavigation.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/react-client/ClientLink.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/react-client/createLocalizedPathnamesNavigation.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/react-client/createSharedPathnamesNavigation.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/react-client/useBasePathname.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/react-client/useBaseRouter.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/shared/redirects.test.d.ts +0 -0
- /package/dist/types/{test → src}/navigation/shared/utils.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-client/useFormatter.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-client/useLocale.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-client/useNow.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-client/useTimeZone.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-client/useTranslations.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-server/NextIntlClientProviderServer.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-server/index.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-server/useTranslations.test.d.ts +0 -0
- /package/dist/types/{test → src}/react-server/utils.d.ts +0 -0
- /package/dist/types/{test → src}/routing/types.test.d.ts +0 -0
- /package/dist/types/{test → src}/server/react-client/index.test.d.ts +0 -0
- /package/dist/types/{test → src}/server/react-server/index.test.d.ts +0 -0
- /package/dist/types/{test → src}/shared/NextIntlClientProvider.test.d.ts +0 -0
- /package/dist/types/{test → src}/shared/utils.test.d.ts +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var utils$1 = require('../shared/utils.js');
|
|
5
6
|
var utils = require('./utils.js');
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -24,6 +25,7 @@ function getAlternateLinksHeaderValue(_ref) {
|
|
|
24
25
|
normalizedUrl.protocol = (_request$headers$get = request.headers.get('x-forwarded-proto')) !== null && _request$headers$get !== void 0 ? _request$headers$get : normalizedUrl.protocol;
|
|
25
26
|
normalizedUrl.pathname = utils.getNormalizedPathname(normalizedUrl.pathname, config.locales, config.localePrefix);
|
|
26
27
|
function getAlternateEntry(url, locale) {
|
|
28
|
+
url.pathname = utils$1.normalizeTrailingSlash(url.pathname);
|
|
27
29
|
if (request.nextUrl.basePath) {
|
|
28
30
|
url = new URL(url);
|
|
29
31
|
url.pathname = utils.applyBasePath(url.pathname, request.nextUrl.basePath);
|
|
@@ -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);
|
|
@@ -38,9 +38,9 @@ function createMiddleware(input) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
function redirect(url, redirectDomain) {
|
|
41
|
-
const urlObj = new URL(utils.normalizeTrailingSlash(url), request.url);
|
|
42
|
-
if (
|
|
43
|
-
const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale,
|
|
41
|
+
const urlObj = new URL(utils$1.normalizeTrailingSlash(url), request.url);
|
|
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 {
|
|
@@ -4,54 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('../shared/utils.js');
|
|
6
6
|
|
|
7
|
-
function isOptionalCatchAllSegment(pathname) {
|
|
8
|
-
return pathname.includes('[[...');
|
|
9
|
-
}
|
|
10
|
-
function isCatchAllSegment(pathname) {
|
|
11
|
-
return pathname.includes('[...');
|
|
12
|
-
}
|
|
13
|
-
function isDynamicSegment(pathname) {
|
|
14
|
-
return pathname.includes('[');
|
|
15
|
-
}
|
|
16
|
-
function comparePathnamePairs(a, b) {
|
|
17
|
-
const pathA = a.split('/');
|
|
18
|
-
const pathB = b.split('/');
|
|
19
|
-
const maxLength = Math.max(pathA.length, pathB.length);
|
|
20
|
-
for (let i = 0; i < maxLength; i++) {
|
|
21
|
-
const segmentA = pathA[i];
|
|
22
|
-
const segmentB = pathB[i];
|
|
23
|
-
|
|
24
|
-
// If one of the paths ends, prioritize the shorter path
|
|
25
|
-
if (!segmentA && segmentB) return -1;
|
|
26
|
-
if (segmentA && !segmentB) return 1;
|
|
27
|
-
|
|
28
|
-
// Prioritize static segments over dynamic segments
|
|
29
|
-
if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
|
|
30
|
-
if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
|
|
31
|
-
|
|
32
|
-
// Prioritize non-catch-all segments over catch-all segments
|
|
33
|
-
if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
|
|
34
|
-
if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
|
|
35
|
-
|
|
36
|
-
// Prioritize non-optional catch-all segments over optional catch-all segments
|
|
37
|
-
if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
|
|
38
|
-
return -1;
|
|
39
|
-
}
|
|
40
|
-
if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
|
|
41
|
-
return 1;
|
|
42
|
-
}
|
|
43
|
-
if (segmentA === segmentB) continue;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Both pathnames are completely static
|
|
47
|
-
return 0;
|
|
48
|
-
}
|
|
49
|
-
function getSortedPathnames(pathnames) {
|
|
50
|
-
const sortedPathnames = pathnames.sort(comparePathnamePairs);
|
|
51
|
-
return sortedPathnames;
|
|
52
|
-
}
|
|
53
7
|
function getInternalTemplate(pathnames, pathname, locale) {
|
|
54
|
-
const sortedPathnames = getSortedPathnames(Object.keys(pathnames));
|
|
8
|
+
const sortedPathnames = utils.getSortedPathnames(Object.keys(pathnames));
|
|
55
9
|
|
|
56
10
|
// Try to find a localized pathname that matches
|
|
57
11
|
for (const internalPathname of sortedPathnames) {
|
|
@@ -81,7 +35,7 @@ function getInternalTemplate(pathnames, pathname, locale) {
|
|
|
81
35
|
}
|
|
82
36
|
|
|
83
37
|
// Try to find an internal pathname that matches (this can be the case
|
|
84
|
-
// if all localized pathnames are different from the internal pathnames)
|
|
38
|
+
// if all localized pathnames are different from the internal pathnames)
|
|
85
39
|
for (const internalPathname of Object.keys(pathnames)) {
|
|
86
40
|
if (utils.matchesPathname(internalPathname, pathname)) {
|
|
87
41
|
return [undefined, internalPathname];
|
|
@@ -95,7 +49,11 @@ function formatTemplatePathname(sourcePathname, sourceTemplate, targetTemplate,
|
|
|
95
49
|
const params = getRouteParams(sourceTemplate, sourcePathname);
|
|
96
50
|
let targetPathname = '';
|
|
97
51
|
targetPathname += formatPathnameTemplate(targetTemplate, params);
|
|
98
|
-
|
|
52
|
+
|
|
53
|
+
// A pathname with an optional catchall like `/categories/[[...slug]]`
|
|
54
|
+
// should be normalized to `/categories` if the catchall is not present
|
|
55
|
+
// and no trailing slash is configured
|
|
56
|
+
targetPathname = utils.normalizeTrailingSlash(targetPathname);
|
|
99
57
|
return targetPathname;
|
|
100
58
|
}
|
|
101
59
|
|
|
@@ -116,7 +74,7 @@ function getNormalizedPathname(pathname, locales, localePrefix) {
|
|
|
116
74
|
const match = pathname.match(regex);
|
|
117
75
|
let result = match ? '/' + match[2] : pathname;
|
|
118
76
|
if (result !== '/') {
|
|
119
|
-
result = normalizeTrailingSlash(result);
|
|
77
|
+
result = utils.normalizeTrailingSlash(result);
|
|
120
78
|
}
|
|
121
79
|
return result;
|
|
122
80
|
}
|
|
@@ -148,13 +106,15 @@ function getPathnameMatch(pathname, locales, localePrefix) {
|
|
|
148
106
|
}
|
|
149
107
|
}
|
|
150
108
|
function getRouteParams(template, pathname) {
|
|
151
|
-
const
|
|
152
|
-
const
|
|
109
|
+
const normalizedPathname = utils.normalizeTrailingSlash(pathname);
|
|
110
|
+
const normalizedTemplate = utils.normalizeTrailingSlash(template);
|
|
111
|
+
const regex = utils.templateToRegex(normalizedTemplate);
|
|
112
|
+
const match = regex.exec(normalizedPathname);
|
|
153
113
|
if (!match) return undefined;
|
|
154
114
|
const params = {};
|
|
155
115
|
for (let i = 1; i < match.length; i++) {
|
|
156
|
-
var
|
|
157
|
-
const key = (
|
|
116
|
+
var _normalizedTemplate$m;
|
|
117
|
+
const key = (_normalizedTemplate$m = normalizedTemplate.match(/\[([^\]]+)\]/g)) === null || _normalizedTemplate$m === void 0 ? void 0 : _normalizedTemplate$m[i - 1].replace(/[[\]]/g, '');
|
|
158
118
|
if (key) params[key] = match[i];
|
|
159
119
|
}
|
|
160
120
|
return params;
|
|
@@ -189,7 +149,7 @@ function getHost(requestHeaders) {
|
|
|
189
149
|
function isLocaleSupportedOnDomain(locale, domain) {
|
|
190
150
|
return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
|
|
191
151
|
}
|
|
192
|
-
function getBestMatchingDomain(curHostDomain, locale,
|
|
152
|
+
function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
|
|
193
153
|
let domainConfig;
|
|
194
154
|
|
|
195
155
|
// Prio 1: Stay on current domain
|
|
@@ -199,12 +159,12 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
|
|
|
199
159
|
|
|
200
160
|
// Prio 2: Use alternative domain with matching default locale
|
|
201
161
|
if (!domainConfig) {
|
|
202
|
-
domainConfig =
|
|
162
|
+
domainConfig = domainsConfig.find(cur => cur.defaultLocale === locale);
|
|
203
163
|
}
|
|
204
164
|
|
|
205
165
|
// Prio 3: Use alternative domain with restricted matching locale
|
|
206
166
|
if (!domainConfig) {
|
|
207
|
-
domainConfig =
|
|
167
|
+
domainConfig = domainsConfig.find(cur => cur.locales != null && cur.locales.includes(locale));
|
|
208
168
|
}
|
|
209
169
|
|
|
210
170
|
// Prio 4: Stay on the current domain if it supports all locales
|
|
@@ -214,25 +174,18 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
|
|
|
214
174
|
|
|
215
175
|
// Prio 5: Use alternative domain that supports all locales
|
|
216
176
|
if (!domainConfig) {
|
|
217
|
-
domainConfig =
|
|
177
|
+
domainConfig = domainsConfig.find(cur => !cur.locales);
|
|
218
178
|
}
|
|
219
179
|
return domainConfig;
|
|
220
180
|
}
|
|
221
181
|
function applyBasePath(pathname, basePath) {
|
|
222
|
-
return normalizeTrailingSlash(basePath + pathname);
|
|
223
|
-
}
|
|
224
|
-
function normalizeTrailingSlash(pathname) {
|
|
225
|
-
if (pathname !== '/' && pathname.endsWith('/')) {
|
|
226
|
-
pathname = pathname.slice(0, -1);
|
|
227
|
-
}
|
|
228
|
-
return pathname;
|
|
182
|
+
return utils.normalizeTrailingSlash(basePath + pathname);
|
|
229
183
|
}
|
|
230
184
|
function getLocaleAsPrefix(locale) {
|
|
231
185
|
return "/".concat(locale);
|
|
232
186
|
}
|
|
233
187
|
|
|
234
188
|
exports.applyBasePath = applyBasePath;
|
|
235
|
-
exports.comparePathnamePairs = comparePathnamePairs;
|
|
236
189
|
exports.formatPathname = formatPathname;
|
|
237
190
|
exports.formatPathnameTemplate = formatPathnameTemplate;
|
|
238
191
|
exports.formatTemplatePathname = formatTemplatePathname;
|
|
@@ -244,6 +197,4 @@ exports.getLocalePrefixes = getLocalePrefixes;
|
|
|
244
197
|
exports.getNormalizedPathname = getNormalizedPathname;
|
|
245
198
|
exports.getPathnameMatch = getPathnameMatch;
|
|
246
199
|
exports.getRouteParams = getRouteParams;
|
|
247
|
-
exports.getSortedPathnames = getSortedPathnames;
|
|
248
200
|
exports.isLocaleSupportedOnDomain = isLocaleSupportedOnDomain;
|
|
249
|
-
exports.normalizeTrailingSlash = normalizeTrailingSlash;
|
|
@@ -125,11 +125,7 @@ function createLocalizedPathnamesNavigation(input) {
|
|
|
125
125
|
const locale = useTypedLocale();
|
|
126
126
|
|
|
127
127
|
// @ts-expect-error -- Mirror the behavior from Next.js, where `null` is returned when `usePathname` is used outside of Next, but the types indicate that a string is always returned.
|
|
128
|
-
return pathname ? utils.getRoute(
|
|
129
|
-
pathname,
|
|
130
|
-
locale,
|
|
131
|
-
pathnames: config$1.pathnames
|
|
132
|
-
}) : pathname;
|
|
128
|
+
return pathname ? utils.getRoute(locale, pathname, config$1.pathnames) : pathname;
|
|
133
129
|
}
|
|
134
130
|
function getPathname(_ref2) {
|
|
135
131
|
let {
|
|
@@ -8,7 +8,7 @@ var utils = require('../../shared/utils.js');
|
|
|
8
8
|
function createRedirectFn(redirectFn) {
|
|
9
9
|
return function baseRedirect(params) {
|
|
10
10
|
const prefix = utils.getLocalePrefix(params.locale, params.localePrefix);
|
|
11
|
-
const localizedPathname = params.localePrefix.mode === 'never' || !utils.
|
|
11
|
+
const localizedPathname = params.localePrefix.mode === 'never' || !utils.isLocalizableHref(params.pathname) ? params.pathname : utils.prefixPathname(prefix, params.pathname);
|
|
12
12
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
13
13
|
args[_key - 1] = arguments[_key];
|
|
14
14
|
}
|
|
@@ -84,23 +84,23 @@ function compileLocalizedPathname(_ref) {
|
|
|
84
84
|
return result;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function getRoute(
|
|
88
|
-
|
|
89
|
-
let {
|
|
90
|
-
locale,
|
|
91
|
-
pathname,
|
|
92
|
-
pathnames
|
|
93
|
-
} = _ref3;
|
|
87
|
+
function getRoute(locale, pathname, pathnames) {
|
|
88
|
+
const sortedPathnames = utils.getSortedPathnames(Object.keys(pathnames));
|
|
94
89
|
const decoded = decodeURI(pathname);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
for (const internalPathname of sortedPathnames) {
|
|
91
|
+
const localizedPathnamesOrPathname = pathnames[internalPathname];
|
|
92
|
+
if (typeof localizedPathnamesOrPathname === 'string') {
|
|
93
|
+
const localizedPathname = localizedPathnamesOrPathname;
|
|
94
|
+
if (utils.matchesPathname(localizedPathname, decoded)) {
|
|
95
|
+
return internalPathname;
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
if (utils.matchesPathname(localizedPathnamesOrPathname[locale], decoded)) {
|
|
99
|
+
return internalPathname;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
102
|
}
|
|
103
|
-
return
|
|
103
|
+
return pathname;
|
|
104
104
|
}
|
|
105
105
|
function getBasePath(pathname) {
|
|
106
106
|
let windowPathname = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.location.pathname;
|
|
@@ -36,45 +36,49 @@ function resolveI18nPath(providedPath, cwd) {
|
|
|
36
36
|
}
|
|
37
37
|
function initPlugin(i18nPath, nextConfig) {
|
|
38
38
|
if ((nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.i18n) != null) {
|
|
39
|
-
console.warn("\nnext-intl has found an `i18n` config in your next.config.js. 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` folder, you can refer to this example: https://
|
|
39
|
+
console.warn("\nnext-intl has found an `i18n` config in your next.config.js. 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` folder, you can refer to this example: https://next-intl-docs.vercel.app/examples#app-router-migration\n");
|
|
40
40
|
}
|
|
41
41
|
const useTurbo = process.env.TURBOPACK != null;
|
|
42
|
-
|
|
42
|
+
const nextIntlConfig = {};
|
|
43
|
+
|
|
44
|
+
// Assign alias for `next-intl/config`
|
|
43
45
|
if (useTurbo) {
|
|
44
46
|
var _nextConfig$experimen, _nextConfig$experimen2;
|
|
45
47
|
if (i18nPath && i18nPath.startsWith('/')) {
|
|
46
48
|
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');
|
|
47
49
|
}
|
|
48
|
-
nextIntlConfig = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
'next-intl/config': resolveI18nPath(i18nPath)
|
|
58
|
-
}
|
|
50
|
+
nextIntlConfig.experimental = {
|
|
51
|
+
...(nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.experimental),
|
|
52
|
+
turbo: {
|
|
53
|
+
...(nextConfig === null || nextConfig === void 0 || (_nextConfig$experimen = nextConfig.experimental) === null || _nextConfig$experimen === void 0 ? void 0 : _nextConfig$experimen.turbo),
|
|
54
|
+
resolveAlias: {
|
|
55
|
+
...(nextConfig === null || nextConfig === void 0 || (_nextConfig$experimen2 = nextConfig.experimental) === null || _nextConfig$experimen2 === void 0 || (_nextConfig$experimen2 = _nextConfig$experimen2.turbo) === null || _nextConfig$experimen2 === void 0 ? void 0 : _nextConfig$experimen2.resolveAlias),
|
|
56
|
+
// Turbo aliases don't work with absolute
|
|
57
|
+
// paths (see error handling above)
|
|
58
|
+
'next-intl/config': resolveI18nPath(i18nPath)
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
} else {
|
|
63
|
-
nextIntlConfig = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_ref[_key] = arguments[_key];
|
|
67
|
-
}
|
|
68
|
-
let [config, options] = _ref;
|
|
69
|
-
// Webpack requires absolute paths
|
|
70
|
-
config.resolve.alias['next-intl/config'] = path__default.default.resolve(config.context, resolveI18nPath(i18nPath, config.context));
|
|
71
|
-
if (typeof (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.webpack) === 'function') {
|
|
72
|
-
return nextConfig.webpack(config, options);
|
|
73
|
-
}
|
|
74
|
-
return config;
|
|
63
|
+
nextIntlConfig.webpack = function webpack() {
|
|
64
|
+
for (var _len = arguments.length, _ref = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
65
|
+
_ref[_key] = arguments[_key];
|
|
75
66
|
}
|
|
67
|
+
let [config, options] = _ref;
|
|
68
|
+
// Webpack requires absolute paths
|
|
69
|
+
config.resolve.alias['next-intl/config'] = path__default.default.resolve(config.context, resolveI18nPath(i18nPath, config.context));
|
|
70
|
+
if (typeof (nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.webpack) === 'function') {
|
|
71
|
+
return nextConfig.webpack(config, options);
|
|
72
|
+
}
|
|
73
|
+
return config;
|
|
76
74
|
};
|
|
77
75
|
}
|
|
76
|
+
|
|
77
|
+
// Forward config
|
|
78
|
+
nextIntlConfig.env = {
|
|
79
|
+
...(nextConfig === null || nextConfig === void 0 ? void 0 : nextConfig.env),
|
|
80
|
+
_next_intl_trailing_slash: nextConfig !== null && nextConfig !== void 0 && nextConfig.trailingSlash ? 'true' : undefined
|
|
81
|
+
};
|
|
78
82
|
return Object.assign({}, nextConfig, nextIntlConfig);
|
|
79
83
|
}
|
|
80
84
|
module.exports = function createNextIntlPlugin(i18nPath) {
|
|
@@ -62,11 +62,33 @@ function prefixPathname(prefix, pathname) {
|
|
|
62
62
|
function hasPathnamePrefixed(prefix, pathname) {
|
|
63
63
|
return pathname === prefix || pathname.startsWith("".concat(prefix, "/"));
|
|
64
64
|
}
|
|
65
|
+
function hasTrailingSlash() {
|
|
66
|
+
try {
|
|
67
|
+
// Provided via `env` setting in `next.config.js` via the plugin
|
|
68
|
+
return process.env._next_intl_trailing_slash === 'true';
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function normalizeTrailingSlash(pathname) {
|
|
74
|
+
const trailingSlash = hasTrailingSlash();
|
|
75
|
+
if (pathname !== '/') {
|
|
76
|
+
const pathnameEndsWithSlash = pathname.endsWith('/');
|
|
77
|
+
if (trailingSlash && !pathnameEndsWithSlash) {
|
|
78
|
+
pathname += '/';
|
|
79
|
+
} else if (!trailingSlash && pathnameEndsWithSlash) {
|
|
80
|
+
pathname = pathname.slice(0, -1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return pathname;
|
|
84
|
+
}
|
|
65
85
|
function matchesPathname( /** E.g. `/users/[userId]-[userName]` */
|
|
66
86
|
template, /** E.g. `/users/23-jane` */
|
|
67
87
|
pathname) {
|
|
68
|
-
const
|
|
69
|
-
|
|
88
|
+
const normalizedTemplate = normalizeTrailingSlash(template);
|
|
89
|
+
const normalizedPathname = normalizeTrailingSlash(pathname);
|
|
90
|
+
const regex = templateToRegex(normalizedTemplate);
|
|
91
|
+
return regex.test(normalizedPathname);
|
|
70
92
|
}
|
|
71
93
|
function getLocalePrefix(locale, localePrefix) {
|
|
72
94
|
var _localePrefix$prefixe;
|
|
@@ -85,14 +107,60 @@ function templateToRegex(template) {
|
|
|
85
107
|
.replace(/\[([^\]]+)\]/g, '([^/]+)');
|
|
86
108
|
return new RegExp("^".concat(regexPattern, "$"));
|
|
87
109
|
}
|
|
110
|
+
function isOptionalCatchAllSegment(pathname) {
|
|
111
|
+
return pathname.includes('[[...');
|
|
112
|
+
}
|
|
113
|
+
function isCatchAllSegment(pathname) {
|
|
114
|
+
return pathname.includes('[...');
|
|
115
|
+
}
|
|
116
|
+
function isDynamicSegment(pathname) {
|
|
117
|
+
return pathname.includes('[');
|
|
118
|
+
}
|
|
119
|
+
function comparePathnamePairs(a, b) {
|
|
120
|
+
const pathA = a.split('/');
|
|
121
|
+
const pathB = b.split('/');
|
|
122
|
+
const maxLength = Math.max(pathA.length, pathB.length);
|
|
123
|
+
for (let i = 0; i < maxLength; i++) {
|
|
124
|
+
const segmentA = pathA[i];
|
|
125
|
+
const segmentB = pathB[i];
|
|
126
|
+
|
|
127
|
+
// If one of the paths ends, prioritize the shorter path
|
|
128
|
+
if (!segmentA && segmentB) return -1;
|
|
129
|
+
if (segmentA && !segmentB) return 1;
|
|
130
|
+
if (!segmentA && !segmentB) continue;
|
|
131
|
+
|
|
132
|
+
// Prioritize static segments over dynamic segments
|
|
133
|
+
if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
|
|
134
|
+
if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
|
|
135
|
+
|
|
136
|
+
// Prioritize non-catch-all segments over catch-all segments
|
|
137
|
+
if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
|
|
138
|
+
if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
|
|
139
|
+
|
|
140
|
+
// Prioritize non-optional catch-all segments over optional catch-all segments
|
|
141
|
+
if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
|
|
142
|
+
return -1;
|
|
143
|
+
}
|
|
144
|
+
if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
|
|
145
|
+
return 1;
|
|
146
|
+
}
|
|
147
|
+
if (segmentA === segmentB) continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Both pathnames are completely static
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
function getSortedPathnames(pathnames) {
|
|
154
|
+
return pathnames.sort(comparePathnamePairs);
|
|
155
|
+
}
|
|
88
156
|
|
|
89
157
|
exports.getLocalePrefix = getLocalePrefix;
|
|
158
|
+
exports.getSortedPathnames = getSortedPathnames;
|
|
90
159
|
exports.hasPathnamePrefixed = hasPathnamePrefixed;
|
|
91
|
-
exports.isLocalHref = isLocalHref;
|
|
92
160
|
exports.isLocalizableHref = isLocalizableHref;
|
|
93
|
-
exports.isRelativeHref = isRelativeHref;
|
|
94
161
|
exports.localizeHref = localizeHref;
|
|
95
162
|
exports.matchesPathname = matchesPathname;
|
|
163
|
+
exports.normalizeTrailingSlash = normalizeTrailingSlash;
|
|
96
164
|
exports.prefixHref = prefixHref;
|
|
97
165
|
exports.prefixPathname = prefixPathname;
|
|
98
166
|
exports.templateToRegex = templateToRegex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getHost as
|
|
1
|
+
import{normalizeTrailingSlash as e}from"../shared/utils.js";import{getHost as a,getNormalizedPathname as t,getLocalePrefixes as o,isLocaleSupportedOnDomain as n,applyBasePath as l,formatTemplatePathname as r}from"./utils.js";function c(c){var m;let{config:p,localizedPathnames:s,request:f,resolvedLocale:i}=c;const h=f.nextUrl.clone(),d=a(f.headers);function u(a,t){return a.pathname=e(a.pathname),f.nextUrl.basePath&&((a=new URL(a)).pathname=l(a.pathname,f.nextUrl.basePath)),"<".concat(a.toString(),'>; rel="alternate"; hreflang="').concat(t,'"')}function x(e,a){return s&&"object"==typeof s?r(e,s[i],s[a]):e}d&&(h.port="",h.host=d),h.protocol=null!==(m=f.headers.get("x-forwarded-proto"))&&void 0!==m?m:h.protocol,h.pathname=t(h.pathname,p.locales,p.localePrefix);const w=o(p.locales,p.localePrefix).flatMap((e=>{let a,[t,o]=e;function l(e){return"/"===e?o:o+e}if(p.domains){return(p.domains.filter((e=>n(t,e)))||[]).map((e=>(a=new URL(h),a.port="",a.host=e.domain,a.pathname=x(h.pathname,t),t===e.defaultLocale&&"always"!==p.localePrefix.mode||(a.pathname=l(a.pathname)),u(a,t))))}{let e;e=s&&"object"==typeof s?x(h.pathname,t):h.pathname,t===p.defaultLocale&&"always"!==p.localePrefix.mode||(e=l(e)),a=new URL(e,h)}return u(a,t)}));if(!p.domains&&("always"!==p.localePrefix.mode||"/"===h.pathname)){const e=new URL(x(h.pathname,p.defaultLocale),h);w.push(u(e,"x-default"))}return w.join(", ")}export{c as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NextResponse as e}from"next/server";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as l,getLocalePrefix as
|
|
1
|
+
import{NextResponse as e}from"next/server";import{HEADER_LOCALE_NAME as o}from"../shared/constants.js";import{matchesPathname as l,normalizeTrailingSlash as r,getLocalePrefix as t}from"../shared/utils.js";import{receiveConfig as a}from"./config.js";import n from"./getAlternateLinksHeaderValue.js";import s from"./resolveLocale.js";import i from"./syncCookie.js";import{isLocaleSupportedOnDomain as c,getNormalizedPathname as d,getPathnameMatch as f,getInternalTemplate as m,formatTemplatePathname as h,formatPathname as x,getBestMatchingDomain as u,applyBasePath as p,getLocaleAsPrefix as v}from"./utils.js";function U(U){const P=a(U);return function(a){var U;const g=decodeURI(a.nextUrl.pathname),{domain:L,locale:j}=s(P,a.headers,a.cookies,g),w=L?L.defaultLocale===j:j===P.defaultLocale,k=(null===(U=P.domains)||void 0===U?void 0:U.filter((e=>c(j,e))))||[],b=null!=P.domains&&!L;function y(l){const r=new URL(l,a.url);a.nextUrl.basePath&&(r.pathname=p(r.pathname,a.nextUrl.basePath));const t=new Headers(a.headers);return t.set(o,j),e.rewrite(r,{request:{headers:t}})}function R(o,l){const t=new URL(r(o),a.url);if(k.length>0&&!l){const e=u(L,j,k);e&&(l=e.domain,e.defaultLocale===j&&"as-needed"===P.localePrefix.mode&&(t.pathname=d(t.pathname,P.locales,P.localePrefix)))}var n,s;l&&(t.host=l,a.headers.get("x-forwarded-host")&&(t.protocol=null!==(n=a.headers.get("x-forwarded-proto"))&&void 0!==n?n:a.nextUrl.protocol,t.port=null!==(s=a.headers.get("x-forwarded-port"))&&void 0!==s?s:""));return a.nextUrl.basePath&&(t.pathname=p(t.pathname,a.nextUrl.basePath)),e.redirect(t.toString())}const q=d(g,P.locales,P.localePrefix),H=f(g,P.locales,P.localePrefix),z=null!=H,A="never"===P.localePrefix.mode||w&&"as-needed"===P.localePrefix.mode;let C,D,I=q;if(P.pathnames){let e;if([e,D]=m(P.pathnames,q,j),D){const o=P.pathnames[D],r="string"==typeof o?o:o[j];if(l(r,q))I=h(q,r,D);else{let l;l=e?"string"==typeof o?o:o[e]:D;const n=A?void 0:t(j,P.localePrefix),s=h(q,l,r);C=R(x(s,n,a.nextUrl.search))}}}if(!C)if("/"!==I||z){const e=x(I,v(j),a.nextUrl.search);if(z){const o=x(q,H.prefix,a.nextUrl.search);if("never"===P.localePrefix.mode)C=R(x(q,void 0,a.nextUrl.search));else if(H.exact)if(w&&A)C=R(x(q,void 0,a.nextUrl.search));else if(P.domains){const l=u(L,H.locale,k);C=(null==L?void 0:L.domain)===(null==l?void 0:l.domain)||b?y(e):R(o,null==l?void 0:l.domain)}else C=y(e);else C=R(o)}else C=A?y(e):R(x(q,t(j,P.localePrefix),a.nextUrl.search))}else C=A?y(x(I,v(j),a.nextUrl.search)):R(x(q,t(j,P.localePrefix),a.nextUrl.search));var S;(P.localeDetection&&i(a,C,j),"never"!==P.localePrefix.mode&&P.alternateLinks&&P.locales.length>1)&&C.headers.set("Link",n({config:P,localizedPathnames:null!=D?null===(S=P.pathnames)||void 0===S?void 0:S[D]:void 0,request:a,resolvedLocale:j}));return C}}export{U as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getSortedPathnames as t,matchesPathname as e,normalizeTrailingSlash as n,getLocalePrefix as o,templateToRegex as r,prefixPathname as c}from"../shared/utils.js";function l(n,o,r){const c=t(Object.keys(n));for(const t of c){const c=n[t];if("string"==typeof c){if(e(c,o))return[void 0,t]}else{const n=Object.entries(c),l=n.findIndex((t=>{let[e]=t;return e===r}));l>0&&n.unshift(n.splice(l,1)[0]);for(const[r,c]of n)if(e(c,o))return[r,t]}}for(const t of Object.keys(n))if(e(t,o))return[void 0,t];return[void 0,void 0]}function i(t,e,o,r){let c="";return c+=d(o,a(e,t)),c=n(c),c}function u(t,e,o){t.endsWith("/")||(t+="/");const r=f(e,o),c=new RegExp("^(".concat(r.map((t=>{let[,e]=t;return e.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),l=t.match(c);let i=l?"/"+l[2]:t;return"/"!==i&&(i=n(i)),i}function f(t,e){return t.map((t=>[t,o(t,e)]))}function s(t,e,n){const o=f(e,n);for(const[e,n]of o){let o,r;if(t===n||t.startsWith(n+"/"))o=r=!0;else{const e=t.toLowerCase(),c=n.toLowerCase();(e===c||e.startsWith(c+"/"))&&(o=!1,r=!0)}if(r)return{locale:e,prefix:n,matchedPrefix:t.slice(0,n.length),exact:o}}}function a(t,e){const o=n(e),c=n(t),l=r(c).exec(o);if(!l)return;const i={};for(let t=1;t<l.length;t++){var u;const e=null===(u=c.match(/\[([^\]]+)\]/g))||void 0===u?void 0:u[t-1].replace(/[[\]]/g,"");e&&(i[e]=l[t])}return i}function d(t,e){if(!e)return t;let n=t=t.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(e).forEach((t=>{let[e,o]=t;n=n.replace("[".concat(e,"]"),o)})),n}function h(t,e,n){let o=t;return e&&(o=c(e,o)),n&&(o+=n),o}function p(t){var e,n;return null!==(e=null!==(n=t.get("x-forwarded-host"))&&void 0!==n?n:t.get("host"))&&void 0!==e?e:void 0}function v(t,e){return e.defaultLocale===t||!e.locales||e.locales.includes(t)}function g(t,e,n){let o;return t&&v(e,t)&&(o=t),o||(o=n.find((t=>t.defaultLocale===e))),o||(o=n.find((t=>null!=t.locales&&t.locales.includes(e)))),o||null!=(null==t?void 0:t.locales)||(o=t),o||(o=n.find((t=>!t.locales))),o}function x(t,e){return n(e+t)}function m(t){return"/".concat(t)}export{x as applyBasePath,h as formatPathname,d as formatPathnameTemplate,i as formatTemplatePathname,g as getBestMatchingDomain,p as getHost,l as getInternalTemplate,m as getLocaleAsPrefix,f as getLocalePrefixes,u as getNormalizedPathname,s as getPathnameMatch,a as getRouteParams,v as isLocaleSupportedOnDomain};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import t from"../../react-client/useLocale.js";import{receiveLocalizedNavigationRoutingConfig as
|
|
1
|
+
import{extends as e}from"../../_virtual/_rollupPluginBabelHelpers.js";import r,{forwardRef as o}from"react";import t from"../../react-client/useLocale.js";import{receiveLocalizedNavigationRoutingConfig as n}from"../shared/config.js";import{getRoute as a,compileLocalizedPathname as l,normalizeNameOrNameWithParams as c}from"../shared/utils.js";import i from"./ClientLink.js";import{clientRedirect as s,clientPermanentRedirect as f}from"./redirects.js";import u from"./useBasePathname.js";import m from"./useBaseRouter.js";function h(h){const p=n(h);function d(){const e=t();if(!p.locales.includes(e))throw new Error('Unknown locale encountered: "'.concat(e,'". Make sure to validate the locale in `i18n.ts`.'));return e}function v(o,t){let{href:n,locale:a,...c}=o;const s=d(),f=a||s;return r.createElement(i,e({ref:t,href:l({locale:f,pathname:n,params:"object"==typeof n?n.params:void 0,pathnames:p.pathnames}),locale:a,localePrefix:p.localePrefix},c))}const P=o(v);function x(e){let{href:r,locale:o}=e;return l({...c(r),locale:o,pathnames:p.pathnames})}return P.displayName="Link",{Link:P,redirect:function(e){const r=x({href:e,locale:d()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return s({pathname:r,localePrefix:p.localePrefix},...t)},permanentRedirect:function(e){const r=x({href:e,locale:d()});for(var o=arguments.length,t=new Array(o>1?o-1:0),n=1;n<o;n++)t[n-1]=arguments[n];return f({pathname:r,localePrefix:p.localePrefix},...t)},usePathname:function(){const e=u(p.localePrefix),r=d();return e?a(r,e,p.pathnames):e},useRouter:function(){const e=m(p.localePrefix),r=d();return{...e,push(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...a)},replace(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...a)},prefetch(o){for(var t,n=arguments.length,a=new Array(n>1?n-1:0),l=1;l<n;l++)a[l-1]=arguments[l];const c=x({href:o,locale:(null===(t=a[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...a)}}},getPathname:x}}export{h as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{redirect as e,permanentRedirect as n}from"next/navigation";import{getLocalePrefix as r,
|
|
1
|
+
import{redirect as e,permanentRedirect as n}from"next/navigation";import{getLocalePrefix as r,isLocalizableHref as t,prefixPathname as o}from"../../shared/utils.js";function a(e){return function(n){const a=r(n.locale,n.localePrefix),i="never"!==n.localePrefix.mode&&t(n.pathname)?o(a,n.pathname):n.pathname;for(var l=arguments.length,m=new Array(l>1?l-1:0),c=1;c<l;c++)m[c-1]=arguments[c];return e(i,...m)}}const i=a(e),l=a(n);export{l as basePermanentRedirect,i as baseRedirect};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{matchesPathname as
|
|
1
|
+
import{getSortedPathnames as t,matchesPathname as n}from"../../shared/utils.js";function r(t){return"string"==typeof t?{pathname:t}:t}function e(t){function n(t){return String(t)}const r=new URLSearchParams;for(const[e,o]of Object.entries(t))Array.isArray(o)?o.forEach((t=>{r.append(e,n(t))})):r.set(e,n(o));return"?"+r.toString()}function o(t){let{pathname:n,locale:r,params:o,pathnames:a,query:c}=t;function i(t){let n=a[t];return n||(n=t),n}function s(t){const n="string"==typeof t?t:t[r];let a=n;if(o&&Object.entries(o).forEach((t=>{let[n,r]=t;a=Array.isArray(r)?a.replace(new RegExp("(\\[)?\\[...".concat(n,"\\](\\])?"),"g"),r.map((t=>String(t))).join("/")):a.replace("[".concat(n,"]"),String(r))})),a.includes("["))throw new Error("Insufficient params provided for localized pathname.\nTemplate: ".concat(n,"\nParams: ").concat(JSON.stringify(o)));return c&&(a+=e(c)),a}if("string"==typeof n){return s(i(n))}{const{pathname:t,...r}=n;return{...r,pathname:s(i(t))}}}function a(r,e,o){const a=t(Object.keys(o)),c=decodeURI(e);for(const t of a){const e=o[t];if("string"==typeof e){if(n(e,c))return t}else if(n(e[r],c))return t}return e}function c(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===t?n:n.replace(t,"")}export{o as compileLocalizedPathname,c as getBasePath,a as getRoute,r as normalizeNameOrNameWithParams,e as serializeSearchParams};
|
package/dist/esm/plugin.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import n from"fs";import e from"path";function t(t,o){function r(t){return n.existsSync(function(n){const t=[];return o&&t.push(o),t.push(n),e.resolve(...t)}(t))}if(t){if(!r(t))throw new Error("Could not find i18n config at ".concat(t,", please provide a valid path."));return t}for(const n of["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"])if(r(n))return n;throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n")}module.exports=function(n){return function(o){return function(n,o){
|
|
1
|
+
import n from"fs";import e from"path";function t(t,o){function r(t){return n.existsSync(function(n){const t=[];return o&&t.push(o),t.push(n),e.resolve(...t)}(t))}if(t){if(!r(t))throw new Error("Could not find i18n config at ".concat(t,", please provide a valid path."));return t}for(const n of["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"])if(r(n))return n;throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n")}module.exports=function(n){return function(o){return function(n,o){null!=(null==o?void 0:o.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. 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` folder, you can refer to this example: https://next-intl-docs.vercel.app/examples#app-router-migration\n");const r={};if(null!=process.env.TURBOPACK){var i,s;if(n&&n.startsWith("/"))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: "+n+"\n");r.experimental={...null==o?void 0:o.experimental,turbo:{...null==o||null===(i=o.experimental)||void 0===i?void 0:i.turbo,resolveAlias:{...null==o||null===(s=o.experimental)||void 0===s||null===(s=s.turbo)||void 0===s?void 0:s.resolveAlias,"next-intl/config":t(n)}}}}else r.webpack=function(){for(var r=arguments.length,i=new Array(r),s=0;s<r;s++)i[s]=arguments[s];let[l,u]=i;return l.resolve.alias["next-intl/config"]=e.resolve(l.context,t(n,l.context)),"function"==typeof(null==o?void 0:o.webpack)?o.webpack(l,u):l};return r.env={...null==o?void 0:o.env,_next_intl_trailing_slash:null!=o&&o.trailingSlash?"true":void 0},Object.assign({},o,r)}(n,o)}};
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,c=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(o,c);return(f||l)&&null!=o?e(t,o):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function c(n){const t=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(n){return!1}}();if("/"!==n){const e=n.endsWith("/");t&&!e?n+="/":!t&&e&&(n=n.slice(0,-1))}return n}function o(n,t){const e=c(n),r=c(t);return l(e).test(r)}function f(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||"/"+n}function l(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function s(n){return n.includes("[[...")}function a(n){return n.includes("[...")}function p(n){return n.includes("[")}function h(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(t||u){if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!s(t)&&s(u))return-1;if(s(t)&&!s(u))return 1}}return 0}function g(n){return n.sort(h)}export{f as getLocalePrefix,g as getSortedPathnames,i as hasPathnamePrefixed,n as isLocalizableHref,t as localizeHref,o as matchesPathname,c as normalizeTrailingSlash,e as prefixHref,u as prefixPathname,l as templateToRegex,r as unprefixPathname};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./utils.js");exports.default=function(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js"),a=require("./utils.js");exports.default=function(t){var o;let{config:n,localizedPathnames:l,request:r,resolvedLocale:s}=t;const i=r.nextUrl.clone(),c=a.getHost(r.headers);function p(t,o){return t.pathname=e.normalizeTrailingSlash(t.pathname),r.nextUrl.basePath&&((t=new URL(t)).pathname=a.applyBasePath(t.pathname,r.nextUrl.basePath)),"<".concat(t.toString(),'>; rel="alternate"; hreflang="').concat(o,'"')}function m(e,t){return l&&"object"==typeof l?a.formatTemplatePathname(e,l[s],l[t]):e}c&&(i.port="",i.host=c),i.protocol=null!==(o=r.headers.get("x-forwarded-proto"))&&void 0!==o?o:i.protocol,i.pathname=a.getNormalizedPathname(i.pathname,n.locales,n.localePrefix);const h=a.getLocalePrefixes(n.locales,n.localePrefix).flatMap((e=>{let t,[o,r]=e;function s(e){return"/"===e?r:r+e}if(n.domains){return(n.domains.filter((e=>a.isLocaleSupportedOnDomain(o,e)))||[]).map((e=>(t=new URL(i),t.port="",t.host=e.domain,t.pathname=m(i.pathname,o),o===e.defaultLocale&&"always"!==n.localePrefix.mode||(t.pathname=s(t.pathname)),p(t,o))))}{let e;e=l&&"object"==typeof l?m(i.pathname,o):i.pathname,o===n.defaultLocale&&"always"!==n.localePrefix.mode||(e=s(e)),t=new URL(e,i)}return p(t,o)}));if(!n.domains&&("always"!==n.localePrefix.mode||"/"===i.pathname)){const e=new URL(m(i.pathname,n.defaultLocale),i);h.push(p(e,"x-default"))}return h.join(", ")};
|
|
@@ -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"),r=require("./config.js"),l=require("./getAlternateLinksHeaderValue.js"),o=require("./resolveLocale.js"),n=require("./syncCookie.js"),s=require("./utils.js");exports.default=function(i){const c=r.receiveConfig(i);return function(r){var i;const d=decodeURI(r.nextUrl.pathname),{domain:f,locale:m}=o.default(c,r.headers,r.cookies,d),h=f?f.defaultLocale===m:m===c.defaultLocale,u=(null===(i=c.domains)||void 0===i?void 0:i.filter((e=>s.isLocaleSupportedOnDomain(m,e))))||[],x=null!=c.domains&&!f;function P(t){const l=new URL(t,r.url);r.nextUrl.basePath&&(l.pathname=s.applyBasePath(l.pathname,r.nextUrl.basePath));const o=new Headers(r.headers);return o.set(a.HEADER_LOCALE_NAME,m),e.NextResponse.rewrite(l,{request:{headers:o}})}function p(a,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/server"),a=require("../shared/constants.js"),t=require("../shared/utils.js"),r=require("./config.js"),l=require("./getAlternateLinksHeaderValue.js"),o=require("./resolveLocale.js"),n=require("./syncCookie.js"),s=require("./utils.js");exports.default=function(i){const c=r.receiveConfig(i);return function(r){var i;const d=decodeURI(r.nextUrl.pathname),{domain:f,locale:m}=o.default(c,r.headers,r.cookies,d),h=f?f.defaultLocale===m:m===c.defaultLocale,u=(null===(i=c.domains)||void 0===i?void 0:i.filter((e=>s.isLocaleSupportedOnDomain(m,e))))||[],x=null!=c.domains&&!f;function P(t){const l=new URL(t,r.url);r.nextUrl.basePath&&(l.pathname=s.applyBasePath(l.pathname,r.nextUrl.basePath));const o=new Headers(r.headers);return o.set(a.HEADER_LOCALE_NAME,m),e.NextResponse.rewrite(l,{request:{headers:o}})}function p(a,l){const o=new URL(t.normalizeTrailingSlash(a),r.url);if(u.length>0&&!l){const e=s.getBestMatchingDomain(f,m,u);e&&(l=e.domain,e.defaultLocale===m&&"as-needed"===c.localePrefix.mode&&(o.pathname=s.getNormalizedPathname(o.pathname,c.locales,c.localePrefix)))}var n,i;l&&(o.host=l,r.headers.get("x-forwarded-host")&&(o.protocol=null!==(n=r.headers.get("x-forwarded-proto"))&&void 0!==n?n:r.nextUrl.protocol,o.port=null!==(i=r.headers.get("x-forwarded-port"))&&void 0!==i?i:""));return r.nextUrl.basePath&&(o.pathname=s.applyBasePath(o.pathname,r.nextUrl.basePath)),e.NextResponse.redirect(o.toString())}const g=s.getNormalizedPathname(d,c.locales,c.localePrefix),v=s.getPathnameMatch(d,c.locales,c.localePrefix),L=null!=v,U="never"===c.localePrefix.mode||h&&"as-needed"===c.localePrefix.mode;let q,j,w=g;if(c.pathnames){let e;if([e,j]=s.getInternalTemplate(c.pathnames,g,m),j){const a=c.pathnames[j],l="string"==typeof a?a:a[m];if(t.matchesPathname(l,g))w=s.formatTemplatePathname(g,l,j);else{let o;o=e?"string"==typeof a?a:a[e]:j;const n=U?void 0:t.getLocalePrefix(m,c.localePrefix),i=s.formatTemplatePathname(g,o,l);q=p(s.formatPathname(i,n,r.nextUrl.search))}}}if(!q)if("/"!==w||L){const e=s.formatPathname(w,s.getLocaleAsPrefix(m),r.nextUrl.search);if(L){const a=s.formatPathname(g,v.prefix,r.nextUrl.search);if("never"===c.localePrefix.mode)q=p(s.formatPathname(g,void 0,r.nextUrl.search));else if(v.exact)if(h&&U)q=p(s.formatPathname(g,void 0,r.nextUrl.search));else if(c.domains){const t=s.getBestMatchingDomain(f,v.locale,u);q=(null==f?void 0:f.domain)===(null==t?void 0:t.domain)||x?P(e):p(a,null==t?void 0:t.domain)}else q=P(e);else q=p(a)}else q=U?P(e):p(s.formatPathname(g,t.getLocalePrefix(m,c.localePrefix),r.nextUrl.search))}else q=U?P(s.formatPathname(w,s.getLocaleAsPrefix(m),r.nextUrl.search)):p(s.formatPathname(g,t.getLocalePrefix(m,c.localePrefix),r.nextUrl.search));var y;(c.localeDetection&&n.default(r,q,m),"never"!==c.localePrefix.mode&&c.alternateLinks&&c.locales.length>1)&&q.headers.set("Link",l.default({config:c,localizedPathnames:null!=j?null===(y=c.pathnames)||void 0===y?void 0:y[j]:void 0,request:r,resolvedLocale:m}));return q}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../shared/utils.js");function t(t,n){return t.map((t=>[t,e.getLocalePrefix(t,n)]))}function n(t,n){const r=e.normalizeTrailingSlash(n),o=e.normalizeTrailingSlash(t),a=e.templateToRegex(o).exec(r);if(!a)return;const l={};for(let e=1;e<a.length;e++){var i;const t=null===(i=o.match(/\[([^\]]+)\]/g))||void 0===i?void 0:i[e-1].replace(/[[\]]/g,"");t&&(l[t]=a[e])}return l}function r(e,t){if(!t)return e;let n=e=e.replace(/\[\[/g,"[").replace(/\]\]/g,"]");return Object.entries(t).forEach((e=>{let[t,r]=e;n=n.replace("[".concat(t,"]"),r)})),n}function o(e,t){return t.defaultLocale===e||!t.locales||t.locales.includes(e)}exports.applyBasePath=function(t,n){return e.normalizeTrailingSlash(n+t)},exports.formatPathname=function(t,n,r){let o=t;return n&&(o=e.prefixPathname(n,o)),r&&(o+=r),o},exports.formatPathnameTemplate=r,exports.formatTemplatePathname=function(t,o,a,l){let i="";return i+=r(a,n(o,t)),i=e.normalizeTrailingSlash(i),i},exports.getBestMatchingDomain=function(e,t,n){let r;return e&&o(t,e)&&(r=e),r||(r=n.find((e=>e.defaultLocale===t))),r||(r=n.find((e=>null!=e.locales&&e.locales.includes(t)))),r||null!=(null==e?void 0:e.locales)||(r=e),r||(r=n.find((e=>!e.locales))),r},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,r){const o=e.getSortedPathnames(Object.keys(t));for(const a of o){const o=t[a];if("string"==typeof o){const t=o;if(e.matchesPathname(t,n))return[void 0,a]}else{const t=Object.entries(o),l=t.findIndex((e=>{let[t]=e;return t===r}));l>0&&t.unshift(t.splice(l,1)[0]);for(const[r,o]of t)if(e.matchesPathname(o,n))return[r,a]}}for(const r of Object.keys(t))if(e.matchesPathname(r,n))return[void 0,r];return[void 0,void 0]},exports.getLocaleAsPrefix=function(e){return"/".concat(e)},exports.getLocalePrefixes=t,exports.getNormalizedPathname=function(n,r,o){n.endsWith("/")||(n+="/");const a=t(r,o),l=new RegExp("^(".concat(a.map((e=>{let[,t]=e;return t.replaceAll("/","\\/")})).join("|"),")/(.*)"),"i"),i=n.match(l);let s=i?"/"+i[2]:n;return"/"!==s&&(s=e.normalizeTrailingSlash(s)),s},exports.getPathnameMatch=function(e,n,r){const o=t(n,r);for(const[t,n]of o){let r,o;if(e===n||e.startsWith(n+"/"))r=o=!0;else{const t=e.toLowerCase(),a=n.toLowerCase();(t===a||t.startsWith(a+"/"))&&(r=!1,o=!0)}if(o)return{locale:t,prefix:n,matchedPrefix:e.slice(0,n.length),exact:r}}},exports.getRouteParams=n,exports.isLocaleSupportedOnDomain=o;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveLocalizedNavigationRoutingConfig(u);function h(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,a){let{href:t,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const p=r.forwardRef(d);function m(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),r=h();return e?l.getRoute(
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../_virtual/_rollupPluginBabelHelpers.js"),r=require("react"),a=require("../../react-client/useLocale.js"),t=require("../shared/config.js"),l=require("../shared/utils.js"),n=require("./ClientLink.js"),o=require("./redirects.js"),c=require("./useBasePathname.js"),i=require("./useBaseRouter.js");function u(e){return e&&e.__esModule?e:{default:e}}var s=u(r);exports.default=function(u){const f=t.receiveLocalizedNavigationRoutingConfig(u);function h(){const e=a.default();if(!f.locales.includes(e))throw new Error(void 0);return e}function d(r,a){let{href:t,locale:o,...c}=r;const i=h(),u=o||i;return s.default.createElement(n.default,e.extends({ref:a,href:l.compileLocalizedPathname({locale:u,pathname:t,params:"object"==typeof t?t.params:void 0,pathnames:f.pathnames}),locale:o,localePrefix:f.localePrefix},c))}const p=r.forwardRef(d);function m(e){let{href:r,locale:a}=e;return l.compileLocalizedPathname({...l.normalizeNameOrNameWithParams(r),locale:a,pathnames:f.pathnames})}return p.displayName="Link",{Link:p,redirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientRedirect({pathname:r,localePrefix:f.localePrefix},...t)},permanentRedirect:function(e){const r=m({href:e,locale:h()});for(var a=arguments.length,t=new Array(a>1?a-1:0),l=1;l<a;l++)t[l-1]=arguments[l];return o.clientPermanentRedirect({pathname:r,localePrefix:f.localePrefix},...t)},usePathname:function(){const e=c.default(f.localePrefix),r=h();return e?l.getRoute(r,e,f.pathnames):e},useRouter:function(){const e=i.default(f.localePrefix),r=h();return{...e,push(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.push(c,...n)},replace(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.replace(c,...n)},prefetch(a){for(var t,l=arguments.length,n=new Array(l>1?l-1:0),o=1;o<l;o++)n[o-1]=arguments[o];const c=m({href:a,locale:(null===(t=n[0])||void 0===t?void 0:t.locale)||r});return e.prefetch(c,...n)}}},getPathname:m}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("../../shared/utils.js");function t(e){return function(t){const a=r.getLocalePrefix(t.locale,t.localePrefix),n="never"!==t.localePrefix.mode&&r.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("../../shared/utils.js");function t(e){return function(t){const a=r.getLocalePrefix(t.locale,t.localePrefix),n="never"!==t.localePrefix.mode&&r.isLocalizableHref(t.pathname)?r.prefixPathname(a,t.pathname):t.pathname;for(var i=arguments.length,o=new Array(i>1?i-1:0),c=1;c<i;c++)o[c-1]=arguments[c];return e(n,...o)}}const a=t(e.redirect),n=t(e.permanentRedirect);exports.basePermanentRedirect=n,exports.baseRedirect=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../shared/utils.js");function t(e){function t(e){return String(e)}const r=new URLSearchParams;for(const[n,a]of Object.entries(e))Array.isArray(a)?a.forEach((e=>{r.append(n,t(e))})):r.set(n,t(a));return"?"+r.toString()}exports.compileLocalizedPathname=function(e){let{pathname:r,locale:n,params:a,pathnames:o,query:s}=e;function c(e){let t=o[e];return t||(t=e),t}function i(e){let r="string"==typeof e?e:e[n];return a&&Object.entries(a).forEach((e=>{let[t,n]=e;r=Array.isArray(n)?r.replace(new RegExp("(\\[)?\\[...".concat(t,"\\](\\])?"),"g"),n.map((e=>String(e))).join("/")):r.replace("[".concat(t,"]"),String(n))})),s&&(r+=t(s)),r}if("string"==typeof r){return i(c(r))}{const{pathname:e,...t}=r;return{...t,pathname:i(c(e))}}},exports.getBasePath=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window.location.pathname;return"/"===e?t:t.replace(e,"")},exports.getRoute=function(t,r,n){const a=e.getSortedPathnames(Object.keys(n)),o=decodeURI(r);for(const r of a){const a=n[r];if("string"==typeof a){const t=a;if(e.matchesPathname(t,o))return r}else if(e.matchesPathname(a[t],o))return r}return r},exports.normalizeNameOrNameWithParams=function(e){return"string"==typeof e?{pathname:e}:e},exports.serializeSearchParams=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=require("fs"),e=require("path");function t(n){return n&&n.__esModule?n:{default:n}}var
|
|
1
|
+
"use strict";var n=require("fs"),e=require("path");function t(n){return n&&n.__esModule?n:{default:n}}var o=t(n),r=t(e);function i(n,e){function t(n){return o.default.existsSync(function(n){const t=[];return e&&t.push(e),t.push(n),r.default.resolve(...t)}(n))}if(n){if(!t(n))throw new Error("Could not find i18n config at ".concat(n,", please provide a valid path."));return n}for(const n of["./i18n.tsx","./i18n.ts","./i18n.js","./i18n.jsx","./src/i18n.tsx","./src/i18n.ts","./src/i18n.js","./src/i18n.jsx"])if(t(n))return n;throw new Error("\n\nCould not locate i18n config. Create one at `./(src/)i18n.{js,jsx,ts,tsx}` or specify a custom location:\n\nconst withNextIntl = require('next-intl/plugin')(\n './path/to/i18n.tsx'\n);\n\nmodule.exports = withNextIntl({\n // Other Next.js configuration ...\n});\n")}module.exports=function(n){return function(e){return function(n,e){null!=(null==e?void 0:e.i18n)&&console.warn("\nnext-intl has found an `i18n` config in your next.config.js. 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` folder, you can refer to this example: https://next-intl-docs.vercel.app/examples#app-router-migration\n");const t={};if(null!=process.env.TURBOPACK){var o,l;if(n&&n.startsWith("/"))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: "+n+"\n");t.experimental={...null==e?void 0:e.experimental,turbo:{...null==e||null===(o=e.experimental)||void 0===o?void 0:o.turbo,resolveAlias:{...null==e||null===(l=e.experimental)||void 0===l||null===(l=l.turbo)||void 0===l?void 0:l.resolveAlias,"next-intl/config":i(n)}}}}else t.webpack=function(){for(var t=arguments.length,o=new Array(t),l=0;l<t;l++)o[l]=arguments[l];let[s,u]=o;return s.resolve.alias["next-intl/config"]=r.default.resolve(s.context,i(n,s.context)),"function"==typeof(null==e?void 0:e.webpack)?e.webpack(s,u):s};return t.env={...null==e?void 0:e.env,_next_intl_trailing_slash:null!=e&&e.trailingSlash?"true":void 0},Object.assign({},e,t)}(n,e)}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function t(t){return function(t){return"object"==typeof t?null==t.host&&null==t.hostname:!/^[a-z]+:/i.test(t)}(t)&&!function(t){const e="object"==typeof t?t.pathname:t;return null!=e&&!e.startsWith("/")}(t)}function e(t,e){let r;return"string"==typeof t?r=n(e,t):(r={...t},t.pathname&&(r.pathname=n(e,t.pathname))),r}function n(t,e){let n=t;return/^\/(\?.*)?$/.test(e)&&(e=e.slice(1)),n+=e,n}function r(t,e){return e===t||e.startsWith("".concat(t,"/"))}function o(t){const e=function(){try{return"true"===process.env._next_intl_trailing_slash}catch(t){return!1}}();if("/"!==t){const n=t.endsWith("/");e&&!n?t+="/":!e&&n&&(t=t.slice(0,-1))}return t}function i(t){const e=t.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(e,"$"))}function u(t){return t.includes("[[...")}function c(t){return t.includes("[...")}function s(t){return t.includes("[")}function a(t,e){const n=t.split("/"),r=e.split("/"),o=Math.max(n.length,r.length);for(let t=0;t<o;t++){const e=n[t],o=r[t];if(!e&&o)return-1;if(e&&!o)return 1;if(e||o){if(!s(e)&&s(o))return-1;if(s(e)&&!s(o))return 1;if(!c(e)&&c(o))return-1;if(c(e)&&!c(o))return 1;if(!u(e)&&u(o))return-1;if(u(e)&&!u(o))return 1}}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalePrefix=function(t,e){var n;return"never"!==e.mode&&(null===(n=e.prefixes)||void 0===n?void 0:n[t])||"/"+t},exports.getSortedPathnames=function(t){return t.sort(a)},exports.hasPathnamePrefixed=r,exports.isLocalizableHref=t,exports.localizeHref=function(n,o){let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,u=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!t(n))return n;const s=o!==i,a=r(c,u);return(s||a)&&null!=c?e(n,c):n},exports.matchesPathname=function(t,e){const n=o(t),r=o(e);return i(n).test(r)},exports.normalizeTrailingSlash=o,exports.prefixHref=e,exports.prefixPathname=n,exports.templateToRegex=i,exports.unprefixPathname=function(t,e){return t.replace(new RegExp("^".concat(e)),"")||"/"};
|
|
@@ -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,7 +1,5 @@
|
|
|
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
|
-
export declare function comparePathnamePairs(a: string, b: string): number;
|
|
4
|
-
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
5
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];
|
|
6
4
|
export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, prefix?: string): string;
|
|
7
5
|
/**
|
|
@@ -21,7 +19,6 @@ export declare function formatPathnameTemplate(template: string, params?: object
|
|
|
21
19
|
export declare function formatPathname(pathname: string, prefix: string | undefined, search: string | undefined): string;
|
|
22
20
|
export declare function getHost(requestHeaders: Headers): string | undefined;
|
|
23
21
|
export declare function isLocaleSupportedOnDomain<AppLocales extends Locales>(locale: string, domain: DomainConfig<AppLocales>): boolean;
|
|
24
|
-
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;
|
|
25
23
|
export declare function applyBasePath(pathname: string, basePath: string): string;
|
|
26
|
-
export declare function normalizeTrailingSlash(pathname: string): string;
|
|
27
24
|
export declare function getLocaleAsPrefix<AppLocales extends Locales>(locale: AppLocales[number]): string;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { ComponentProps, ReactElement } from 'react';
|
|
1
|
+
import { ComponentProps, ReactElement } from 'react';
|
|
3
2
|
import { Locales, LocalePrefixConfigVerbose } from '../../routing/types';
|
|
4
3
|
import BaseLink from '../shared/BaseLink';
|
|
5
4
|
type Props<AppLocales extends Locales> = Omit<ComponentProps<typeof BaseLink>, 'locale' | 'prefix' | 'localePrefixMode'> & {
|
|
@@ -26,42 +25,7 @@ type Props<AppLocales extends Locales> = Omit<ComponentProps<typeof BaseLink>, '
|
|
|
26
25
|
* the `set-cookie` response header would cause the locale cookie on the current
|
|
27
26
|
* page to be overwritten before the user even decides to change the locale.
|
|
28
27
|
*/
|
|
29
|
-
declare const ClientLinkWithRef: <AppLocales extends Locales>(props:
|
|
30
|
-
|
|
31
|
-
as?: (string | import("url").UrlObject) | undefined;
|
|
32
|
-
replace?: boolean | undefined;
|
|
33
|
-
scroll?: boolean | undefined;
|
|
34
|
-
shallow?: boolean | undefined;
|
|
35
|
-
passHref?: boolean | undefined;
|
|
36
|
-
prefetch?: boolean | undefined;
|
|
37
|
-
locale?: string | false | undefined;
|
|
38
|
-
legacyBehavior?: boolean | undefined;
|
|
39
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
40
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
41
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
42
|
-
}> & {
|
|
43
|
-
href: string | import("url").UrlObject;
|
|
44
|
-
as?: (string | import("url").UrlObject) | undefined;
|
|
45
|
-
replace?: boolean | undefined;
|
|
46
|
-
scroll?: boolean | undefined;
|
|
47
|
-
shallow?: boolean | undefined;
|
|
48
|
-
passHref?: boolean | undefined;
|
|
49
|
-
prefetch?: boolean | undefined;
|
|
50
|
-
locale?: string | false | undefined;
|
|
51
|
-
legacyBehavior?: boolean | undefined;
|
|
52
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
53
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
54
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
55
|
-
} & {
|
|
56
|
-
children?: React.ReactNode;
|
|
57
|
-
} & React.RefAttributes<HTMLAnchorElement>, "locale"> & {
|
|
58
|
-
locale: string;
|
|
59
|
-
prefix: string;
|
|
60
|
-
localePrefixMode: import("../../routing/types").LocalePrefixMode;
|
|
61
|
-
}, "ref"> & React.RefAttributes<HTMLAnchorElement>, "locale" | "prefix" | "localePrefixMode"> & {
|
|
62
|
-
locale?: AppLocales[number] | undefined;
|
|
63
|
-
localePrefix: LocalePrefixConfigVerbose<AppLocales>;
|
|
64
|
-
} & {
|
|
65
|
-
ref?: React.LegacyRef<HTMLAnchorElement> | undefined;
|
|
28
|
+
declare const ClientLinkWithRef: <AppLocales extends Locales>(props: Props<AppLocales> & {
|
|
29
|
+
ref?: Props<AppLocales>['ref'];
|
|
66
30
|
}) => ReactElement;
|
|
67
31
|
export default ClientLinkWithRef;
|
|
@@ -43,10 +43,6 @@ export declare function compileLocalizedPathname<AppLocales extends Locales, Pat
|
|
|
43
43
|
pathnames: Pathnames<AppLocales>;
|
|
44
44
|
query?: Record<string, SearchParamValue>;
|
|
45
45
|
}): UrlObject;
|
|
46
|
-
export declare function getRoute<AppLocales extends Locales>(
|
|
47
|
-
locale: AppLocales[number];
|
|
48
|
-
pathname: string;
|
|
49
|
-
pathnames: Pathnames<AppLocales>;
|
|
50
|
-
}): string;
|
|
46
|
+
export declare function getRoute<AppLocales extends Locales>(locale: AppLocales[number], pathname: string, pathnames: Pathnames<AppLocales>): keyof Pathnames<AppLocales>;
|
|
51
47
|
export declare function getBasePath(pathname: string, windowPathname?: string): string;
|
|
52
48
|
export {};
|
|
@@ -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 {};
|
|
@@ -4,8 +4,6 @@ import NextLink from 'next/link';
|
|
|
4
4
|
import { ComponentProps } from 'react';
|
|
5
5
|
import { Locales, LocalePrefixConfigVerbose } from '../routing/types';
|
|
6
6
|
type Href = ComponentProps<typeof NextLink>['href'];
|
|
7
|
-
export declare function isRelativeHref(href: Href): boolean;
|
|
8
|
-
export declare function isLocalHref(href: Href): boolean;
|
|
9
7
|
export declare function isLocalizableHref(href: Href): boolean;
|
|
10
8
|
export declare function localizeHref(href: string, locale: string, curLocale: string, curPathname: string, prefix: string): string;
|
|
11
9
|
export declare function localizeHref(href: UrlObject | string, locale: string, curLocale: string, curPathname: string, prefix: string): UrlObject | string;
|
|
@@ -14,6 +12,7 @@ export declare function prefixHref(href: UrlObject | string, prefix: string): Ur
|
|
|
14
12
|
export declare function unprefixPathname(pathname: string, prefix: string): string;
|
|
15
13
|
export declare function prefixPathname(prefix: string, pathname: string): string;
|
|
16
14
|
export declare function hasPathnamePrefixed(prefix: string, pathname: string): boolean;
|
|
15
|
+
export declare function normalizeTrailingSlash(pathname: string): string;
|
|
17
16
|
export declare function matchesPathname(
|
|
18
17
|
/** E.g. `/users/[userId]-[userName]` */
|
|
19
18
|
template: string,
|
|
@@ -21,4 +20,5 @@ template: string,
|
|
|
21
20
|
pathname: string): boolean;
|
|
22
21
|
export declare function getLocalePrefix<AppLocales extends Locales>(locale: AppLocales[number], localePrefix: LocalePrefixConfigVerbose<AppLocales>): string;
|
|
23
22
|
export declare function templateToRegex(template: string): RegExp;
|
|
23
|
+
export declare function getSortedPathnames(pathnames: Array<string>): string[];
|
|
24
24
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intl",
|
|
3
|
-
"version": "3.16.0
|
|
3
|
+
"version": "3.16.0",
|
|
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.16.0
|
|
90
|
+
"use-intl": "^3.16.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"size-limit": [
|
|
97
97
|
{
|
|
98
98
|
"path": "dist/production/index.react-client.js",
|
|
99
|
-
"limit": "15.
|
|
99
|
+
"limit": "15.785 KB"
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
"path": "dist/production/index.react-server.js",
|
|
@@ -104,11 +104,11 @@
|
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"path": "dist/production/navigation.react-client.js",
|
|
107
|
-
"limit": "3.
|
|
107
|
+
"limit": "3.465 KB"
|
|
108
108
|
},
|
|
109
109
|
{
|
|
110
110
|
"path": "dist/production/navigation.react-server.js",
|
|
111
|
-
"limit": "
|
|
111
|
+
"limit": "18.075 KB"
|
|
112
112
|
},
|
|
113
113
|
{
|
|
114
114
|
"path": "dist/production/server.react-client.js",
|
|
@@ -120,12 +120,12 @@
|
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
"path": "dist/production/middleware.js",
|
|
123
|
-
"limit": "6.
|
|
123
|
+
"limit": "6.485 KB"
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"path": "dist/production/routing.js",
|
|
127
127
|
"limit": "0 KB"
|
|
128
128
|
}
|
|
129
129
|
],
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "44a87a4ff07e779df8ac929c0edcf22fb398f576"
|
|
131
131
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/types/{test → src}/navigation/react-client/createSharedPathnamesNavigation.test.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|