Skip to content

Commit be68ab4

Browse files
ematipicosarah11918
andauthoredMay 22, 2024··
feat: make i18n domains stable (#11022)
* feat: make i18n domains stable * update tst * Update .changeset/five-crabs-rhyme.md Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca> * fix regression --------- Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
1 parent a3675e5 commit be68ab4

File tree

9 files changed

+45
-79
lines changed

9 files changed

+45
-79
lines changed
 

‎.changeset/five-crabs-rhyme.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"astro": minor
3+
---
4+
5+
The `i18nDomains` routing feature introduced behind a flag in [v3.4.0](https://github.com/withastro/astro/blob/main/packages/astro/CHANGELOG.md#430) is no longer experimental and is available for general use.
6+
7+
This routing option allows you to configure different domains for individual locales in entirely server-rendered projects using the [@astrojs/node](https://docs.astro.build/en/guides/integrations-guide/node/) or [@astrojs/vercel](https://docs.astro.build/en/guides/integrations-guide/vercel/) adapter with a `site` configured.
8+
9+
If you were using this feature, please remove the experimental flag from your Astro config:
10+
11+
```diff
12+
import { defineConfig } from 'astro'
13+
14+
export default defineConfig({
15+
- experimental: {
16+
- i18nDomains: true,
17+
- }
18+
})
19+
```
20+
21+
If you have been waiting for stabilization before using this routing option, you can now do so.
22+
23+
Please see [the internationalization docs](https://docs.astro.build/en/guides/internationalization/#domains) for more about this feature.

‎packages/astro/src/@types/astro.ts

+1-44
Original file line numberDiff line numberDiff line change
@@ -1955,50 +1955,7 @@ export interface AstroUserConfig {
19551955
* In the event of route collisions, where two routes of equal route priority attempt to build the same URL, Astro will log a warning identifying the conflicting routes.
19561956
*/
19571957
globalRoutePriority?: boolean;
1958-
1959-
/**
1960-
* @docs
1961-
* @name experimental.i18nDomains
1962-
* @type {boolean}
1963-
* @default `false`
1964-
* @version 4.3.0
1965-
* @description
1966-
*
1967-
* Enables domain support for the [experimental `domains` routing strategy](https://docs.astro.build/en/guides/internationalization/#domains-experimental) which allows you to configure the URL pattern of one or more supported languages to use a custom domain (or sub-domain).
1968-
*
1969-
* When a locale is mapped to a domain, a `/[locale]/` path prefix will not be used. However, localized folders within `src/pages/` are still required, including for your configured `defaultLocale`.
1970-
*
1971-
* Any other locale not configured will default to a localized path-based URL according to your `prefixDefaultLocale` strategy (e.g. `https://example.com/[locale]/blog`).
1972-
*
1973-
* ```js
1974-
* //astro.config.mjs
1975-
* export default defineConfig({
1976-
* site: "https://example.com",
1977-
* output: "server", // required, with no prerendered pages
1978-
* adapter: node({
1979-
* mode: 'standalone',
1980-
* }),
1981-
* i18n: {
1982-
* defaultLocale: "en",
1983-
* locales: ["en", "fr", "pt-br", "es"],
1984-
* prefixDefaultLocale: false,
1985-
* domains: {
1986-
* fr: "https://fr.example.com",
1987-
* es: "https://example.es",
1988-
* },
1989-
* },
1990-
* experimental: {
1991-
* i18nDomains: true,
1992-
* },
1993-
* });
1994-
* ```
1995-
*
1996-
* Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/reference/api-reference/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/reference/api-reference/#getabsolutelocaleurllist) will use the options set in `i18n.domains`.
1997-
*
1998-
* See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains-experimental) for more details, including the limitations of this experimental feature.
1999-
*/
2000-
i18nDomains?: boolean;
2001-
1958+
20021959
/**
20031960
* @docs
20041961
* @name experimental.security

‎packages/astro/src/core/build/generate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export async function generatePages(options: StaticBuildOptions, internals: Buil
129129
if (ssr) {
130130
for (const [pageData, filePath] of pagesToGenerate) {
131131
if (pageData.route.prerender) {
132-
// i18n domains won't work with pre rendered routes at the moment, so we need to to throw an error
133-
if (config.experimental.i18nDomains) {
132+
// i18n domains won't work with pre rendered routes at the moment, so we need to throw an error
133+
if (config.i18n?.domains && Object.keys(config.i18n.domains).length > 0) {
134134
throw new AstroError({
135135
...NoPrerenderedRoutesWithDomains,
136136
message: NoPrerenderedRoutesWithDomains.message(pageData.component),
@@ -284,7 +284,7 @@ async function getPathsForRoute(
284284
const label = staticPaths.length === 1 ? 'page' : 'pages';
285285
logger.debug(
286286
'build',
287-
`├── ${bold(green(''))} ${route.component}${magenta(`[${staticPaths.length} ${label}]`)}`
287+
`├── ${bold(green(''))} ${route.component}${magenta(`[${staticPaths.length} ${label}]`)}`
288288
);
289289

290290
paths = staticPaths

‎packages/astro/src/core/build/plugins/plugin-manifest.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function buildManifest(
239239
* logic meant for i18n domain support, where we fill the lookup table
240240
*/
241241
const i18n = settings.config.i18n;
242-
if (settings.config.experimental.i18nDomains && i18n && i18n.domains) {
242+
if (i18n && i18n.domains) {
243243
for (const [locale, domainValue] of Object.entries(i18n.domains)) {
244244
domainLookupTable[domainValue] = normalizeTheLocale(locale);
245245
}

‎packages/astro/src/core/config/schema.ts

+14-18
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const ASTRO_CONFIG_DEFAULTS = {
8686
contentCollectionJsonSchema: false,
8787
clientPrerender: false,
8888
globalRoutePriority: false,
89-
i18nDomains: false,
9089
security: {},
9190
rewriting: false,
9291
},
@@ -527,7 +526,6 @@ export const AstroConfigSchema = z.object({
527526
})
528527
.optional()
529528
.default(ASTRO_CONFIG_DEFAULTS.experimental.security),
530-
i18nDomains: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.i18nDomains),
531529
rewriting: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.experimental.rewriting),
532530
})
533531
.strict(
@@ -668,22 +666,20 @@ export function createRelativeSchema(cmd: string, fileProtocolRoot: string) {
668666
})
669667
.superRefine((configuration, ctx) => {
670668
const { site, experimental, i18n, output } = configuration;
671-
if (experimental.i18nDomains) {
672-
const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
673-
if (hasDomains) {
674-
if (!site) {
675-
ctx.addIssue({
676-
code: z.ZodIssueCode.custom,
677-
message:
678-
"The option `site` isn't set. When using the 'domains' strategy for `i18n`, `site` is required to create absolute URLs for locales that aren't mapped to a domain.",
679-
});
680-
}
681-
if (output !== 'server') {
682-
ctx.addIssue({
683-
code: z.ZodIssueCode.custom,
684-
message: 'Domain support is only available when `output` is `"server"`.',
685-
});
686-
}
669+
const hasDomains = i18n?.domains ? Object.keys(i18n.domains).length > 0 : false;
670+
if (hasDomains) {
671+
if (!site) {
672+
ctx.addIssue({
673+
code: z.ZodIssueCode.custom,
674+
message:
675+
"The option `site` isn't set. When using the 'domains' strategy for `i18n`, `site` is required to create absolute URLs for locales that aren't mapped to a domain.",
676+
});
677+
}
678+
if (output !== 'server') {
679+
ctx.addIssue({
680+
code: z.ZodIssueCode.custom,
681+
message: 'Domain support is only available when `output` is `"server"`.',
682+
});
687683
}
688684
}
689685
});

‎packages/astro/src/integrations/features-validation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function validateSupportedFeatures(
7070
);
7171
validationResult.assets = validateAssetsFeature(assets, adapterName, config, logger);
7272

73-
if (i18nDomains && config?.experimental?.i18nDomains === true && !config.i18n?.domains) {
73+
if (!config.i18n?.domains) {
7474
validationResult.i18nDomains = validateSupportKind(
7575
i18nDomains,
7676
adapterName,

‎packages/astro/test/fixtures/i18n-routing-subdomain/astro.config.mjs

-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,5 @@ export default defineConfig({
1717
redirectToDefaultLocale: false
1818
}
1919
},
20-
experimental: {
21-
i18nDomains: true
22-
},
2320
site: "https://example.com",
2421
})

‎packages/astro/test/units/config/config-validate.test.js

-6
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ describe('Config Validation', () => {
319319
en: 'https://www.example.com/',
320320
},
321321
},
322-
experimental: {
323-
i18nDomains: true,
324-
},
325322
},
326323
process.cwd()
327324
).catch((err) => err);
@@ -343,9 +340,6 @@ describe('Config Validation', () => {
343340
en: 'https://www.example.com/',
344341
},
345342
},
346-
experimental: {
347-
i18nDomains: true,
348-
},
349343
site: 'https://foo.org',
350344
},
351345
process.cwd()

‎packages/astro/test/units/i18n/astro_i18n.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,7 @@ describe('getLocaleAbsoluteUrlList', () => {
15481548
const config = await validateConfig(
15491549
{
15501550
format: 'directory',
1551+
output: "server",
15511552
site: 'https://example.com/',
15521553
trailingSlash: 'always',
15531554
i18n: {
@@ -1587,7 +1588,6 @@ describe('getLocaleAbsoluteUrlList', () => {
15871588
* @type {import("../../../dist/@types").AstroUserConfig}
15881589
*/
15891590
const config = {
1590-
experimental: {
15911591
i18n: {
15921592
defaultLocale: 'en',
15931593
locales: [
@@ -1599,15 +1599,14 @@ describe('getLocaleAbsoluteUrlList', () => {
15991599
codes: ['it', 'it-VA'],
16001600
},
16011601
],
1602-
},
16031602
},
16041603
};
16051604
// directory format
16061605
assert.deepEqual(
16071606
getLocaleAbsoluteUrlList({
16081607
locale: 'en',
16091608
base: '/blog/',
1610-
...config.experimental.i18n,
1609+
...config.i18n,
16111610
trailingSlash: 'always',
16121611
format: 'file',
16131612
site: 'https://example.com',

0 commit comments

Comments
 (0)
Please sign in to comment.