From d50dddb71d87ce5b7928920f10eb4946a5339f86 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 20 Feb 2024 10:17:40 +0000 Subject: [PATCH] fix(i18n): make `i18n.routing` fields optional (#10165) * fix(i18n): make `i18n.routing` fields optional * update user config * Update packages/astro/src/core/config/schema.ts Co-authored-by: Chris Swithinbank --------- Co-authored-by: Chris Swithinbank --- .changeset/large-planets-kick.md | 5 ++ packages/astro/src/@types/astro.ts | 86 +++++++++++++++--------------- 2 files changed, 48 insertions(+), 43 deletions(-) create mode 100644 .changeset/large-planets-kick.md diff --git a/.changeset/large-planets-kick.md b/.changeset/large-planets-kick.md new file mode 100644 index 0000000000..f1b58b5e5d --- /dev/null +++ b/.changeset/large-planets-kick.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where the `i18n.routing` object had all its fields defined as mandatory. Now they all are optionals and shouldn't break when using `astro.config.mts`. diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index c07dd0f653..53b4f28893 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -1492,7 +1492,7 @@ export interface AstroUserConfig { * URLs will be of the form `example.com/[locale]/content/` for every route, including the default language. * Localized folders are used for every language, including the default. */ - prefixDefaultLocale: boolean; + prefixDefaultLocale?: boolean; /** * @docs @@ -1521,7 +1521,7 @@ export interface AstroUserConfig { * }) *``` * */ - redirectToDefaultLocale: boolean; + redirectToDefaultLocale?: boolean; /** * @name i18n.routing.strategy @@ -1532,48 +1532,48 @@ export interface AstroUserConfig { * * - `"pathname": The strategy is applied to the pathname of the URLs */ - strategy: 'pathname'; - - /** - * @name i18n.domains - * @type {Record } - * @default '{}' - * @version 4.3.0 - * @description - * - * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain). - * - * 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`. - * - * 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`). - * - * ```js - * //astro.config.mjs - * export default defineConfig({ - * site: "https://example.com", - * output: "server", // required, with no prerendered pages - * adapter: node({ - * mode: 'standalone', - * }), - * i18n: { - * defaultLocale: "en", - * locales: ["en", "fr", "pt-br", "es"], - * prefixDefaultLocale: false, - * domains: { - * fr: "https://fr.example.com", - * es: "https://example.es" - * } - * }, - * }) - * ``` - * - * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`. - * - * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature. - */ - domains?: Record; + strategy?: 'pathname'; }; + + /** + * @name i18n.domains + * @type {Record } + * @default '{}' + * @version 4.3.0 + * @description + * + * Configures the URL pattern of one or more supported languages to use a custom domain (or sub-domain). + * + * 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`. + * + * 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`). + * + * ```js + * //astro.config.mjs + * export default defineConfig({ + * site: "https://example.com", + * output: "server", // required, with no prerendered pages + * adapter: node({ + * mode: 'standalone', + * }), + * i18n: { + * defaultLocale: "en", + * locales: ["en", "fr", "pt-br", "es"], + * prefixDefaultLocale: false, + * domains: { + * fr: "https://fr.example.com", + * es: "https://example.es" + * } + * }, + * }) + * ``` + * + * Both page routes built and URLs returned by the `astro:i18n` helper functions [`getAbsoluteLocaleUrl()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurl) and [`getAbsoluteLocaleUrlList()`](https://docs.astro.build/en/guides/internationalization/#getabsolutelocaleurllist) will use the options set in `i18n.domains`. + * + * See the [Internationalization Guide](https://docs.astro.build/en/guides/internationalization/#domains) for more details, including the limitations of this feature. + */ + domains?: Record; }; /** ⚠️ WARNING: SUBJECT TO CHANGE */