astro 4.4.1 → 4.4.2
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/core/app/index.js +1 -1
- package/dist/core/app/types.d.ts +2 -2
- package/dist/core/build/generate.js +2 -1
- package/dist/core/build/plugins/plugin-manifest.js +3 -2
- package/dist/core/config/schema.d.ts +37 -54
- package/dist/core/config/schema.js +10 -39
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +1 -1
- package/dist/core/errors/errors-data.d.ts +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/core/render/result.d.ts +2 -2
- package/dist/core/render/result.js +1 -1
- package/dist/core/render-context.js +4 -4
- package/dist/core/routing/manifest/create.js +5 -3
- package/dist/i18n/index.d.ts +4 -4
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/middleware.js +3 -3
- package/dist/i18n/utils.d.ts +3 -2
- package/dist/i18n/utils.js +29 -1
- package/dist/virtual-modules/i18n.js +7 -5
- package/dist/vite-plugin-astro-server/plugin.js +2 -1
- package/package.json +1 -1
package/dist/core/app/index.js
CHANGED
|
@@ -110,7 +110,7 @@ class App {
|
|
|
110
110
|
#computePathnameFromDomain(request) {
|
|
111
111
|
let pathname = void 0;
|
|
112
112
|
const url = new URL(request.url);
|
|
113
|
-
if (this.#manifest.i18n && (this.#manifest.i18n.
|
|
113
|
+
if (this.#manifest.i18n && (this.#manifest.i18n.strategy === "domains-prefix-always" || this.#manifest.i18n.strategy === "domains-prefix-other-locales" || this.#manifest.i18n.strategy === "domains-prefix-always-no-redirect")) {
|
|
114
114
|
let host = request.headers.get("X-Forwarded-Host");
|
|
115
115
|
let protocol = request.headers.get("X-Forwarded-Proto");
|
|
116
116
|
if (protocol) {
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Locales, MiddlewareHandler, RouteData, SerializedRouteData, SSRComponentMetadata, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js';
|
|
2
2
|
import type { SinglePageBuiltModule } from '../build/types.js';
|
|
3
|
-
import type { RoutingStrategies } from '
|
|
3
|
+
import type { RoutingStrategies } from '../../i18n/utils.js';
|
|
4
4
|
export type ComponentPath = string;
|
|
5
5
|
export type StylesheetAsset = {
|
|
6
6
|
type: 'inline';
|
|
@@ -50,7 +50,7 @@ export type SSRManifest = {
|
|
|
50
50
|
};
|
|
51
51
|
export type SSRManifestI18n = {
|
|
52
52
|
fallback?: Record<string, string>;
|
|
53
|
-
|
|
53
|
+
strategy: RoutingStrategies;
|
|
54
54
|
locales: Locales;
|
|
55
55
|
defaultLocale: string;
|
|
56
56
|
domainLookupTable: Record<string, string>;
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
|
|
41
41
|
import { NoPrerenderedRoutesWithDomains } from "../errors/errors-data.js";
|
|
42
42
|
import { RenderContext } from "../render-context.js";
|
|
43
|
+
import { toRoutingStrategy } from "../../i18n/utils.js";
|
|
43
44
|
function createEntryURL(filePath, outFolder) {
|
|
44
45
|
return new URL("./" + filePath + `?time=${Date.now()}`, outFolder);
|
|
45
46
|
}
|
|
@@ -409,7 +410,7 @@ function createBuildManifest(settings, internals, renderers, middleware) {
|
|
|
409
410
|
if (settings.config.i18n) {
|
|
410
411
|
i18nManifest = {
|
|
411
412
|
fallback: settings.config.i18n.fallback,
|
|
412
|
-
|
|
413
|
+
strategy: toRoutingStrategy(settings.config.i18n),
|
|
413
414
|
defaultLocale: settings.config.i18n.defaultLocale,
|
|
414
415
|
locales: settings.config.i18n.locales,
|
|
415
416
|
domainLookupTable: {}
|
|
@@ -9,6 +9,7 @@ import { addRollupInput } from "../add-rollup-input.js";
|
|
|
9
9
|
import { getOutFile, getOutFolder } from "../common.js";
|
|
10
10
|
import { cssOrder, mergeInlineCss } from "../internal.js";
|
|
11
11
|
import { normalizeTheLocale } from "../../../i18n/index.js";
|
|
12
|
+
import { toRoutingStrategy } from "../../../i18n/utils.js";
|
|
12
13
|
const manifestReplace = "@@ASTRO_MANIFEST_REPLACE@@";
|
|
13
14
|
const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, "g");
|
|
14
15
|
const SSR_MANIFEST_VIRTUAL_MODULE_ID = "@astrojs-manifest";
|
|
@@ -177,7 +178,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
177
178
|
});
|
|
178
179
|
}
|
|
179
180
|
const i18n = settings.config.i18n;
|
|
180
|
-
if (settings.config.experimental.i18nDomains && i18n && i18n.domains
|
|
181
|
+
if (settings.config.experimental.i18nDomains && i18n && i18n.domains) {
|
|
181
182
|
for (const [locale, domainValue] of Object.entries(i18n.domains)) {
|
|
182
183
|
domainLookupTable[domainValue] = normalizeTheLocale(locale);
|
|
183
184
|
}
|
|
@@ -189,7 +190,7 @@ function buildManifest(opts, internals, staticFiles) {
|
|
|
189
190
|
if (settings.config.i18n) {
|
|
190
191
|
i18nManifest = {
|
|
191
192
|
fallback: settings.config.i18n.fallback,
|
|
192
|
-
|
|
193
|
+
strategy: toRoutingStrategy(settings.config.i18n),
|
|
193
194
|
locales: settings.config.i18n.locales,
|
|
194
195
|
defaultLocale: settings.config.i18n.defaultLocale,
|
|
195
196
|
domainLookupTable
|
|
@@ -7,7 +7,6 @@ import { z } from 'zod';
|
|
|
7
7
|
import 'mdast-util-to-hast';
|
|
8
8
|
import 'shikiji-core';
|
|
9
9
|
type ShikiTheme = NonNullable<ShikiConfig['theme']>;
|
|
10
|
-
export type RoutingStrategies = 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
|
|
11
10
|
export declare const AstroConfigSchema: z.ZodObject<{
|
|
12
11
|
root: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
13
12
|
srcDir: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodString>>, URL, string | undefined>;
|
|
@@ -238,7 +237,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
238
237
|
smartypants?: boolean | undefined;
|
|
239
238
|
}>>;
|
|
240
239
|
vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
|
|
241
|
-
i18n: z.ZodOptional<z.ZodEffects<z.
|
|
240
|
+
i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
|
|
242
241
|
defaultLocale: z.ZodString;
|
|
243
242
|
locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
244
243
|
path: z.ZodString;
|
|
@@ -300,34 +299,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
300
299
|
strategy?: "pathname" | undefined;
|
|
301
300
|
} | undefined;
|
|
302
301
|
}>>, {
|
|
303
|
-
routing: RoutingStrategies;
|
|
304
|
-
defaultLocale: string;
|
|
305
|
-
locales: (string | {
|
|
306
|
-
path: string;
|
|
307
|
-
codes: [string, ...string[]];
|
|
308
|
-
})[];
|
|
309
|
-
domains?: Record<string, string> | undefined;
|
|
310
|
-
fallback?: Record<string, string> | undefined;
|
|
311
|
-
} | undefined, {
|
|
312
|
-
defaultLocale: string;
|
|
313
|
-
locales: (string | {
|
|
314
|
-
path: string;
|
|
315
|
-
codes: [string, ...string[]];
|
|
316
|
-
})[];
|
|
317
|
-
domains?: Record<string, string> | undefined;
|
|
318
|
-
fallback?: Record<string, string> | undefined;
|
|
319
|
-
routing?: {
|
|
320
|
-
prefixDefaultLocale?: boolean | undefined;
|
|
321
|
-
redirectToDefaultLocale?: boolean | undefined;
|
|
322
|
-
strategy?: "pathname" | undefined;
|
|
323
|
-
} | undefined;
|
|
324
|
-
} | undefined>, {
|
|
325
|
-
routing: RoutingStrategies;
|
|
326
302
|
defaultLocale: string;
|
|
327
303
|
locales: (string | {
|
|
328
304
|
path: string;
|
|
329
305
|
codes: [string, ...string[]];
|
|
330
306
|
})[];
|
|
307
|
+
routing: {
|
|
308
|
+
prefixDefaultLocale: boolean;
|
|
309
|
+
redirectToDefaultLocale: boolean;
|
|
310
|
+
strategy: "pathname";
|
|
311
|
+
};
|
|
331
312
|
domains?: Record<string, string> | undefined;
|
|
332
313
|
fallback?: Record<string, string> | undefined;
|
|
333
314
|
} | undefined, {
|
|
@@ -455,12 +436,16 @@ export declare const AstroConfigSchema: z.ZodObject<{
|
|
|
455
436
|
defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
|
|
456
437
|
} | undefined;
|
|
457
438
|
i18n?: {
|
|
458
|
-
routing: RoutingStrategies;
|
|
459
439
|
defaultLocale: string;
|
|
460
440
|
locales: (string | {
|
|
461
441
|
path: string;
|
|
462
442
|
codes: [string, ...string[]];
|
|
463
443
|
})[];
|
|
444
|
+
routing: {
|
|
445
|
+
prefixDefaultLocale: boolean;
|
|
446
|
+
redirectToDefaultLocale: boolean;
|
|
447
|
+
strategy: "pathname";
|
|
448
|
+
};
|
|
464
449
|
domains?: Record<string, string> | undefined;
|
|
465
450
|
fallback?: Record<string, string> | undefined;
|
|
466
451
|
} | undefined;
|
|
@@ -733,7 +718,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
733
718
|
smartypants?: boolean | undefined;
|
|
734
719
|
}>>;
|
|
735
720
|
vite: z.ZodDefault<z.ZodType<ViteUserConfig, z.ZodTypeDef, ViteUserConfig>>;
|
|
736
|
-
i18n: z.ZodOptional<z.ZodEffects<z.
|
|
721
|
+
i18n: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodObject<{
|
|
737
722
|
defaultLocale: z.ZodString;
|
|
738
723
|
locales: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
739
724
|
path: z.ZodString;
|
|
@@ -795,34 +780,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
795
780
|
strategy?: "pathname" | undefined;
|
|
796
781
|
} | undefined;
|
|
797
782
|
}>>, {
|
|
798
|
-
routing: RoutingStrategies;
|
|
799
|
-
defaultLocale: string;
|
|
800
|
-
locales: (string | {
|
|
801
|
-
path: string;
|
|
802
|
-
codes: [string, ...string[]];
|
|
803
|
-
})[];
|
|
804
|
-
domains?: Record<string, string> | undefined;
|
|
805
|
-
fallback?: Record<string, string> | undefined;
|
|
806
|
-
} | undefined, {
|
|
807
|
-
defaultLocale: string;
|
|
808
|
-
locales: (string | {
|
|
809
|
-
path: string;
|
|
810
|
-
codes: [string, ...string[]];
|
|
811
|
-
})[];
|
|
812
|
-
domains?: Record<string, string> | undefined;
|
|
813
|
-
fallback?: Record<string, string> | undefined;
|
|
814
|
-
routing?: {
|
|
815
|
-
prefixDefaultLocale?: boolean | undefined;
|
|
816
|
-
redirectToDefaultLocale?: boolean | undefined;
|
|
817
|
-
strategy?: "pathname" | undefined;
|
|
818
|
-
} | undefined;
|
|
819
|
-
} | undefined>, {
|
|
820
|
-
routing: RoutingStrategies;
|
|
821
783
|
defaultLocale: string;
|
|
822
784
|
locales: (string | {
|
|
823
785
|
path: string;
|
|
824
786
|
codes: [string, ...string[]];
|
|
825
787
|
})[];
|
|
788
|
+
routing: {
|
|
789
|
+
prefixDefaultLocale: boolean;
|
|
790
|
+
redirectToDefaultLocale: boolean;
|
|
791
|
+
strategy: "pathname";
|
|
792
|
+
};
|
|
826
793
|
domains?: Record<string, string> | undefined;
|
|
827
794
|
fallback?: Record<string, string> | undefined;
|
|
828
795
|
} | undefined, {
|
|
@@ -1010,12 +977,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1010
977
|
defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
|
|
1011
978
|
} | undefined;
|
|
1012
979
|
i18n?: {
|
|
1013
|
-
routing: RoutingStrategies;
|
|
1014
980
|
defaultLocale: string;
|
|
1015
981
|
locales: (string | {
|
|
1016
982
|
path: string;
|
|
1017
983
|
codes: [string, ...string[]];
|
|
1018
984
|
})[];
|
|
985
|
+
routing: {
|
|
986
|
+
prefixDefaultLocale: boolean;
|
|
987
|
+
redirectToDefaultLocale: boolean;
|
|
988
|
+
strategy: "pathname";
|
|
989
|
+
};
|
|
1019
990
|
domains?: Record<string, string> | undefined;
|
|
1020
991
|
fallback?: Record<string, string> | undefined;
|
|
1021
992
|
} | undefined;
|
|
@@ -1203,12 +1174,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1203
1174
|
defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
|
|
1204
1175
|
} | undefined;
|
|
1205
1176
|
i18n?: {
|
|
1206
|
-
routing: RoutingStrategies;
|
|
1207
1177
|
defaultLocale: string;
|
|
1208
1178
|
locales: (string | {
|
|
1209
1179
|
path: string;
|
|
1210
1180
|
codes: [string, ...string[]];
|
|
1211
1181
|
})[];
|
|
1182
|
+
routing: {
|
|
1183
|
+
prefixDefaultLocale: boolean;
|
|
1184
|
+
redirectToDefaultLocale: boolean;
|
|
1185
|
+
strategy: "pathname";
|
|
1186
|
+
};
|
|
1212
1187
|
domains?: Record<string, string> | undefined;
|
|
1213
1188
|
fallback?: Record<string, string> | undefined;
|
|
1214
1189
|
} | undefined;
|
|
@@ -1396,12 +1371,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1396
1371
|
defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
|
|
1397
1372
|
} | undefined;
|
|
1398
1373
|
i18n?: {
|
|
1399
|
-
routing: RoutingStrategies;
|
|
1400
1374
|
defaultLocale: string;
|
|
1401
1375
|
locales: (string | {
|
|
1402
1376
|
path: string;
|
|
1403
1377
|
codes: [string, ...string[]];
|
|
1404
1378
|
})[];
|
|
1379
|
+
routing: {
|
|
1380
|
+
prefixDefaultLocale: boolean;
|
|
1381
|
+
redirectToDefaultLocale: boolean;
|
|
1382
|
+
strategy: "pathname";
|
|
1383
|
+
};
|
|
1405
1384
|
domains?: Record<string, string> | undefined;
|
|
1406
1385
|
fallback?: Record<string, string> | undefined;
|
|
1407
1386
|
} | undefined;
|
|
@@ -1589,12 +1568,16 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: stri
|
|
|
1589
1568
|
defaultStrategy?: "tap" | "hover" | "viewport" | "load" | undefined;
|
|
1590
1569
|
} | undefined;
|
|
1591
1570
|
i18n?: {
|
|
1592
|
-
routing: RoutingStrategies;
|
|
1593
1571
|
defaultLocale: string;
|
|
1594
1572
|
locales: (string | {
|
|
1595
1573
|
path: string;
|
|
1596
1574
|
codes: [string, ...string[]];
|
|
1597
1575
|
})[];
|
|
1576
|
+
routing: {
|
|
1577
|
+
prefixDefaultLocale: boolean;
|
|
1578
|
+
redirectToDefaultLocale: boolean;
|
|
1579
|
+
strategy: "pathname";
|
|
1580
|
+
};
|
|
1598
1581
|
domains?: Record<string, string> | undefined;
|
|
1599
1582
|
fallback?: Record<string, string> | undefined;
|
|
1600
1583
|
} | undefined;
|
|
@@ -217,36 +217,7 @@ const AstroConfigSchema = z.object({
|
|
|
217
217
|
message: "The option `i18n.redirectToDefaultLocale` is only useful when the `i18n.prefixDefaultLocale` is set to `true`. Remove the option `i18n.redirectToDefaultLocale`, or change its value to `true`."
|
|
218
218
|
}
|
|
219
219
|
)
|
|
220
|
-
}).optional().
|
|
221
|
-
if (i18n) {
|
|
222
|
-
let { routing, domains } = i18n;
|
|
223
|
-
let strategy;
|
|
224
|
-
const hasDomains = domains ? Object.keys(domains).length > 0 : false;
|
|
225
|
-
if (!hasDomains) {
|
|
226
|
-
if (routing.prefixDefaultLocale === true) {
|
|
227
|
-
if (routing.redirectToDefaultLocale) {
|
|
228
|
-
strategy = "pathname-prefix-always";
|
|
229
|
-
} else {
|
|
230
|
-
strategy = "pathname-prefix-always-no-redirect";
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
strategy = "pathname-prefix-other-locales";
|
|
234
|
-
}
|
|
235
|
-
} else {
|
|
236
|
-
if (routing.prefixDefaultLocale === true) {
|
|
237
|
-
if (routing.redirectToDefaultLocale) {
|
|
238
|
-
strategy = "domains-prefix-always";
|
|
239
|
-
} else {
|
|
240
|
-
strategy = "domains-prefix-always-no-redirect";
|
|
241
|
-
}
|
|
242
|
-
} else {
|
|
243
|
-
strategy = "domains-prefix-other-locales";
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return { ...i18n, routing: strategy };
|
|
247
|
-
}
|
|
248
|
-
return void 0;
|
|
249
|
-
}).superRefine((i18n, ctx) => {
|
|
220
|
+
}).optional().superRefine((i18n, ctx) => {
|
|
250
221
|
if (i18n) {
|
|
251
222
|
const { defaultLocale, locales: _locales, fallback, domains, routing } = i18n;
|
|
252
223
|
const locales = _locales.map((locale) => {
|
|
@@ -286,15 +257,14 @@ const AstroConfigSchema = z.object({
|
|
|
286
257
|
}
|
|
287
258
|
if (domains) {
|
|
288
259
|
const entries = Object.entries(domains);
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
260
|
+
const hasDomains = domains ? Object.keys(domains).length > 0 : false;
|
|
261
|
+
if (entries.length > 0 && !hasDomains) {
|
|
262
|
+
ctx.addIssue({
|
|
263
|
+
code: z.ZodIssueCode.custom,
|
|
264
|
+
message: `When specifying some domains, the property \`i18n.routingStrategy\` must be set to \`"domains"\`.`
|
|
265
|
+
});
|
|
296
266
|
}
|
|
297
|
-
for (const [domainKey, domainValue] of
|
|
267
|
+
for (const [domainKey, domainValue] of entries) {
|
|
298
268
|
if (!locales.includes(domainKey)) {
|
|
299
269
|
ctx.addIssue({
|
|
300
270
|
code: z.ZodIssueCode.custom,
|
|
@@ -394,7 +364,8 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
|
|
|
394
364
|
}).superRefine((configuration, ctx) => {
|
|
395
365
|
const { site, experimental, i18n, output } = configuration;
|
|
396
366
|
if (experimental.i18nDomains) {
|
|
397
|
-
|
|
367
|
+
const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
|
|
368
|
+
if (hasDomains) {
|
|
398
369
|
if (!site) {
|
|
399
370
|
ctx.addIssue({
|
|
400
371
|
code: z.ZodIssueCode.custom,
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
|
|
|
23
23
|
base: restart.container.settings.config.base
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
|
-
const currentVersion = "4.4.
|
|
26
|
+
const currentVersion = "4.4.2";
|
|
27
27
|
if (currentVersion.includes("-")) {
|
|
28
28
|
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
|
|
29
29
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { APIContext, Locales, Params } from '../../@types/astro.js';
|
|
2
2
|
import type { AstroCookies } from '../cookies/index.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type RoutingStrategies } from '../../i18n/utils.js';
|
|
4
4
|
type CreateAPIContext = {
|
|
5
5
|
request: Request;
|
|
6
6
|
params: Params;
|
|
@@ -776,7 +776,7 @@ export declare const LocalImageUsedWrongly: {
|
|
|
776
776
|
* @see
|
|
777
777
|
* - [Astro.glob](https://docs.astro.build/en/reference/api-reference/#astroglob)
|
|
778
778
|
* @description
|
|
779
|
-
* `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to
|
|
779
|
+
* `Astro.glob()` can only be used in `.astro` files. You can use [`import.meta.glob()`](https://vitejs.dev/guide/features.html#glob-import) instead to achieve the same result.
|
|
780
780
|
*/
|
|
781
781
|
export declare const AstroGlobUsedOutside: {
|
|
782
782
|
name: string;
|
package/dist/core/messages.js
CHANGED
|
@@ -36,7 +36,7 @@ function serverStart({
|
|
|
36
36
|
host,
|
|
37
37
|
base
|
|
38
38
|
}) {
|
|
39
|
-
const version = "4.4.
|
|
39
|
+
const version = "4.4.2";
|
|
40
40
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
41
41
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
42
42
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -261,7 +261,7 @@ function printHelp({
|
|
|
261
261
|
message.push(
|
|
262
262
|
linebreak(),
|
|
263
263
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
264
|
-
`v${"4.4.
|
|
264
|
+
`v${"4.4.2"}`
|
|
265
265
|
)} ${headline}`
|
|
266
266
|
);
|
|
267
267
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Locales, Params, SSRElement, SSRLoadedRenderer, SSRResult } from '../../@types/astro.js';
|
|
2
2
|
import { AstroCookies } from '../cookies/index.js';
|
|
3
3
|
import type { Logger } from '../logger/core.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type RoutingStrategies } from '../../i18n/utils.js';
|
|
5
5
|
export interface CreateResultArgs {
|
|
6
6
|
/**
|
|
7
7
|
* Used to provide better error messages for `Astro.clientAddress`
|
|
@@ -34,6 +34,6 @@ export interface CreateResultArgs {
|
|
|
34
34
|
locales: Locales | undefined;
|
|
35
35
|
defaultLocale: string | undefined;
|
|
36
36
|
route: string;
|
|
37
|
-
|
|
37
|
+
strategy: RoutingStrategies | undefined;
|
|
38
38
|
}
|
|
39
39
|
export declare function createResult(args: CreateResultArgs): SSRResult;
|
|
@@ -159,7 +159,7 @@ class RenderContext {
|
|
|
159
159
|
} = pipeline;
|
|
160
160
|
const { links, scripts, styles } = await pipeline.headElements(routeData);
|
|
161
161
|
const componentMetadata = await pipeline.componentMetadata(routeData) ?? manifest.componentMetadata;
|
|
162
|
-
const { defaultLocale, locales,
|
|
162
|
+
const { defaultLocale, locales, strategy } = i18n ?? {};
|
|
163
163
|
const partial = Boolean(mod.partial);
|
|
164
164
|
return createResult({
|
|
165
165
|
adapterName,
|
|
@@ -179,7 +179,7 @@ class RenderContext {
|
|
|
179
179
|
resolve,
|
|
180
180
|
request,
|
|
181
181
|
route: routeData.route,
|
|
182
|
-
|
|
182
|
+
strategy,
|
|
183
183
|
site,
|
|
184
184
|
scripts,
|
|
185
185
|
ssr: serverLike,
|
|
@@ -206,9 +206,9 @@ class RenderContext {
|
|
|
206
206
|
preferredLocale: void 0,
|
|
207
207
|
preferredLocaleList: void 0
|
|
208
208
|
};
|
|
209
|
-
const { defaultLocale, locales,
|
|
209
|
+
const { defaultLocale, locales, strategy } = i18n;
|
|
210
210
|
return this.#i18nData = {
|
|
211
|
-
currentLocale: computeCurrentLocale(routeData.route, locales,
|
|
211
|
+
currentLocale: computeCurrentLocale(routeData.route, locales, strategy, defaultLocale),
|
|
212
212
|
preferredLocale: computePreferredLocale(request, locales),
|
|
213
213
|
preferredLocaleList: computePreferredLocaleList(request, locales)
|
|
214
214
|
};
|
|
@@ -10,6 +10,7 @@ import { AstroError } from "../../errors/index.js";
|
|
|
10
10
|
import { removeLeadingForwardSlash, slash } from "../../path.js";
|
|
11
11
|
import { resolvePages } from "../../util.js";
|
|
12
12
|
import { getRouteGenerator } from "./generator.js";
|
|
13
|
+
import { toRoutingStrategy } from "../../../i18n/utils.js";
|
|
13
14
|
const require2 = createRequire(import.meta.url);
|
|
14
15
|
function countOccurrences(needle, haystack) {
|
|
15
16
|
let count = 0;
|
|
@@ -423,7 +424,8 @@ function createRouteManifest(params, logger) {
|
|
|
423
424
|
}
|
|
424
425
|
const i18n = settings.config.i18n;
|
|
425
426
|
if (i18n) {
|
|
426
|
-
|
|
427
|
+
const strategy = toRoutingStrategy(i18n);
|
|
428
|
+
if (strategy === "pathname-prefix-always") {
|
|
427
429
|
let index = routes.find((route) => route.route === "/");
|
|
428
430
|
if (!index) {
|
|
429
431
|
let relativePath = path.relative(
|
|
@@ -475,7 +477,7 @@ function createRouteManifest(params, logger) {
|
|
|
475
477
|
}
|
|
476
478
|
setRoutes.delete(route);
|
|
477
479
|
}
|
|
478
|
-
if (
|
|
480
|
+
if (strategy === "pathname-prefix-always") {
|
|
479
481
|
const defaultLocaleRoutes = routesByLocale.get(i18n.defaultLocale);
|
|
480
482
|
if (defaultLocaleRoutes) {
|
|
481
483
|
const indexDefaultRoute = defaultLocaleRoutes.find(({ route }) => route === "/") ?? defaultLocaleRoutes.find(({ route }) => route === `/${i18n.defaultLocale}`);
|
|
@@ -523,7 +525,7 @@ function createRouteManifest(params, logger) {
|
|
|
523
525
|
if (!hasRoute) {
|
|
524
526
|
let pathname;
|
|
525
527
|
let route;
|
|
526
|
-
if (fallbackToLocale === i18n.defaultLocale &&
|
|
528
|
+
if (fallbackToLocale === i18n.defaultLocale && strategy === "pathname-prefix-other-locales") {
|
|
527
529
|
if (fallbackToRoute.pathname) {
|
|
528
530
|
pathname = `/${fallbackFromLocale}${fallbackToRoute.pathname}`;
|
|
529
531
|
}
|
package/dist/i18n/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { AstroConfig, Locales } from '../@types/astro.js';
|
|
2
|
-
import type { RoutingStrategies } from '
|
|
2
|
+
import type { RoutingStrategies } from './utils.js';
|
|
3
3
|
type GetLocaleRelativeUrl = GetLocaleOptions & {
|
|
4
4
|
locale: string;
|
|
5
5
|
base: string;
|
|
6
6
|
locales: Locales;
|
|
7
7
|
trailingSlash: AstroConfig['trailingSlash'];
|
|
8
8
|
format: AstroConfig['build']['format'];
|
|
9
|
-
|
|
9
|
+
strategy?: RoutingStrategies;
|
|
10
10
|
defaultLocale: string;
|
|
11
11
|
domains: Record<string, string> | undefined;
|
|
12
12
|
path?: string;
|
|
@@ -29,7 +29,7 @@ type GetLocaleAbsoluteUrl = GetLocaleRelativeUrl & {
|
|
|
29
29
|
/**
|
|
30
30
|
* The base URL
|
|
31
31
|
*/
|
|
32
|
-
export declare function getLocaleRelativeUrl({ locale, base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale,
|
|
32
|
+
export declare function getLocaleRelativeUrl({ locale, base, locales: _locales, trailingSlash, format, path, prependWith, normalizeLocale, strategy, defaultLocale, }: GetLocaleRelativeUrl): string;
|
|
33
33
|
/**
|
|
34
34
|
* The absolute URL
|
|
35
35
|
*/
|
|
@@ -40,7 +40,7 @@ interface GetLocalesRelativeUrlList extends GetLocaleOptions {
|
|
|
40
40
|
locales: Locales;
|
|
41
41
|
trailingSlash: AstroConfig['trailingSlash'];
|
|
42
42
|
format: AstroConfig['build']['format'];
|
|
43
|
-
|
|
43
|
+
strategy?: RoutingStrategies;
|
|
44
44
|
defaultLocale: string;
|
|
45
45
|
domains: Record<string, string> | undefined;
|
|
46
46
|
}
|
package/dist/i18n/index.js
CHANGED
|
@@ -11,7 +11,7 @@ function getLocaleRelativeUrl({
|
|
|
11
11
|
path,
|
|
12
12
|
prependWith,
|
|
13
13
|
normalizeLocale = true,
|
|
14
|
-
|
|
14
|
+
strategy = "pathname-prefix-other-locales",
|
|
15
15
|
defaultLocale
|
|
16
16
|
}) {
|
|
17
17
|
const codeToUse = peekCodePathToUse(_locales, locale);
|
|
@@ -23,7 +23,7 @@ function getLocaleRelativeUrl({
|
|
|
23
23
|
}
|
|
24
24
|
const pathsToJoin = [base, prependWith];
|
|
25
25
|
const normalizedLocale = normalizeLocale ? normalizeTheLocale(codeToUse) : codeToUse;
|
|
26
|
-
if (
|
|
26
|
+
if (strategy === "pathname-prefix-always" || strategy === "pathname-prefix-always-no-redirect" || strategy === "domains-prefix-always" || strategy === "domains-prefix-always-no-redirect") {
|
|
27
27
|
pathsToJoin.push(normalizedLocale);
|
|
28
28
|
} else if (locale !== defaultLocale) {
|
|
29
29
|
pathsToJoin.push(normalizedLocale);
|
package/dist/i18n/middleware.js
CHANGED
|
@@ -70,8 +70,8 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
|
|
|
70
70
|
return response;
|
|
71
71
|
}
|
|
72
72
|
const { url, currentLocale } = context;
|
|
73
|
-
const { locales, defaultLocale, fallback,
|
|
74
|
-
switch (i18n.
|
|
73
|
+
const { locales, defaultLocale, fallback, strategy } = i18n;
|
|
74
|
+
switch (i18n.strategy) {
|
|
75
75
|
case "domains-prefix-other-locales": {
|
|
76
76
|
if (localeHasntDomain(i18n, currentLocale)) {
|
|
77
77
|
const result = prefixOtherLocales(url, response);
|
|
@@ -140,7 +140,7 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
|
|
|
140
140
|
const fallbackLocale = fallback[urlLocale];
|
|
141
141
|
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
142
142
|
let newPathname;
|
|
143
|
-
if (pathFallbackLocale === defaultLocale &&
|
|
143
|
+
if (pathFallbackLocale === defaultLocale && strategy === "pathname-prefix-other-locales") {
|
|
144
144
|
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
145
145
|
} else {
|
|
146
146
|
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
package/dist/i18n/utils.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Locales } from '../@types/astro.js';
|
|
2
|
-
import type { RoutingStrategies } from '../core/config/schema.js';
|
|
1
|
+
import type { AstroConfig, Locales } from '../@types/astro.js';
|
|
3
2
|
type BrowserLocale = {
|
|
4
3
|
locale: string;
|
|
5
4
|
qualityValue: number | undefined;
|
|
@@ -22,4 +21,6 @@ export declare function parseLocale(header: string): BrowserLocale[];
|
|
|
22
21
|
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
|
|
23
22
|
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
|
|
24
23
|
export declare function computeCurrentLocale(pathname: string, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
|
|
24
|
+
export type RoutingStrategies = 'pathname-prefix-always' | 'pathname-prefix-other-locales' | 'pathname-prefix-always-no-redirect' | 'domains-prefix-always' | 'domains-prefix-other-locales' | 'domains-prefix-always-no-redirect';
|
|
25
|
+
export declare function toRoutingStrategy(i18n: NonNullable<AstroConfig['i18n']>): RoutingStrategies;
|
|
25
26
|
export {};
|
package/dist/i18n/utils.js
CHANGED
|
@@ -136,9 +136,37 @@ function computeCurrentLocale(pathname, locales, routingStrategy, defaultLocale)
|
|
|
136
136
|
}
|
|
137
137
|
return void 0;
|
|
138
138
|
}
|
|
139
|
+
function toRoutingStrategy(i18n) {
|
|
140
|
+
let { routing, domains } = i18n;
|
|
141
|
+
let strategy;
|
|
142
|
+
const hasDomains = domains ? Object.keys(domains).length > 0 : false;
|
|
143
|
+
if (!hasDomains) {
|
|
144
|
+
if (routing?.prefixDefaultLocale === true) {
|
|
145
|
+
if (routing.redirectToDefaultLocale) {
|
|
146
|
+
strategy = "pathname-prefix-always";
|
|
147
|
+
} else {
|
|
148
|
+
strategy = "pathname-prefix-always-no-redirect";
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
strategy = "pathname-prefix-other-locales";
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
if (routing?.prefixDefaultLocale === true) {
|
|
155
|
+
if (routing.redirectToDefaultLocale) {
|
|
156
|
+
strategy = "domains-prefix-always";
|
|
157
|
+
} else {
|
|
158
|
+
strategy = "domains-prefix-always-no-redirect";
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
strategy = "domains-prefix-other-locales";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return strategy;
|
|
165
|
+
}
|
|
139
166
|
export {
|
|
140
167
|
computeCurrentLocale,
|
|
141
168
|
computePreferredLocale,
|
|
142
169
|
computePreferredLocaleList,
|
|
143
|
-
parseLocale
|
|
170
|
+
parseLocale,
|
|
171
|
+
toRoutingStrategy
|
|
144
172
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as I18nInternals from "../i18n/index.js";
|
|
2
|
+
import { toRoutingStrategy } from "../i18n/utils.js";
|
|
2
3
|
import { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js";
|
|
3
4
|
const { trailingSlash, format, site, i18n, isBuild } = (
|
|
4
5
|
// @ts-expect-error
|
|
5
6
|
__ASTRO_INTERNAL_I18N_CONFIG__
|
|
6
7
|
);
|
|
7
|
-
const { defaultLocale, locales,
|
|
8
|
+
const { defaultLocale, locales, domains } = i18n;
|
|
8
9
|
const base = import.meta.env.BASE_URL;
|
|
10
|
+
const routing = toRoutingStrategy(i18n);
|
|
9
11
|
const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleRelativeUrl({
|
|
10
12
|
locale,
|
|
11
13
|
path,
|
|
@@ -14,7 +16,7 @@ const getRelativeLocaleUrl = (locale, path, options) => I18nInternals.getLocaleR
|
|
|
14
16
|
format,
|
|
15
17
|
defaultLocale,
|
|
16
18
|
locales,
|
|
17
|
-
routing,
|
|
19
|
+
strategy: routing,
|
|
18
20
|
domains,
|
|
19
21
|
...options
|
|
20
22
|
});
|
|
@@ -27,7 +29,7 @@ const getAbsoluteLocaleUrl = (locale, path, options) => I18nInternals.getLocaleA
|
|
|
27
29
|
site,
|
|
28
30
|
defaultLocale,
|
|
29
31
|
locales,
|
|
30
|
-
routing,
|
|
32
|
+
strategy: routing,
|
|
31
33
|
domains,
|
|
32
34
|
isBuild,
|
|
33
35
|
...options
|
|
@@ -39,7 +41,7 @@ const getRelativeLocaleUrlList = (path, options) => I18nInternals.getLocaleRelat
|
|
|
39
41
|
format,
|
|
40
42
|
defaultLocale,
|
|
41
43
|
locales,
|
|
42
|
-
routing,
|
|
44
|
+
strategy: routing,
|
|
43
45
|
domains,
|
|
44
46
|
...options
|
|
45
47
|
});
|
|
@@ -51,7 +53,7 @@ const getAbsoluteLocaleUrlList = (path, options) => I18nInternals.getLocaleAbsol
|
|
|
51
53
|
format,
|
|
52
54
|
defaultLocale,
|
|
53
55
|
locales,
|
|
54
|
-
routing,
|
|
56
|
+
strategy: routing,
|
|
55
57
|
domains,
|
|
56
58
|
isBuild,
|
|
57
59
|
...options
|
|
@@ -11,6 +11,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
11
11
|
import { IncomingMessage } from "node:http";
|
|
12
12
|
import { setRouteError } from "./server-state.js";
|
|
13
13
|
import { recordServerError } from "./error.js";
|
|
14
|
+
import { toRoutingStrategy } from "../i18n/utils.js";
|
|
14
15
|
function createVitePluginAstroServer({
|
|
15
16
|
settings,
|
|
16
17
|
logger,
|
|
@@ -88,7 +89,7 @@ function createDevelopmentManifest(settings) {
|
|
|
88
89
|
if (settings.config.i18n) {
|
|
89
90
|
i18nManifest = {
|
|
90
91
|
fallback: settings.config.i18n.fallback,
|
|
91
|
-
|
|
92
|
+
strategy: toRoutingStrategy(settings.config.i18n),
|
|
92
93
|
defaultLocale: settings.config.i18n.defaultLocale,
|
|
93
94
|
locales: settings.config.i18n.locales,
|
|
94
95
|
domainLookupTable: {}
|