Skip to content

Commit

Permalink
fix(i18n): make i18n.routing fields optional (#10165)
Browse files Browse the repository at this point in the history
* fix(i18n): make `i18n.routing` fields optional

* update user config

* Update packages/astro/src/core/config/schema.ts

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>

---------

Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
  • Loading branch information
ematipico and delucis authored Feb 20, 2024
1 parent 9b78c99 commit d50dddb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-planets-kick.md
Original file line number Diff line number Diff line change
@@ -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`.
86 changes: 43 additions & 43 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1521,7 +1521,7 @@ export interface AstroUserConfig {
* })
*```
* */
redirectToDefaultLocale: boolean;
redirectToDefaultLocale?: boolean;

/**
* @name i18n.routing.strategy
Expand All @@ -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<string, string> }
* @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<string, string>;
strategy?: 'pathname';
};

/**
* @name i18n.domains
* @type {Record<string, string> }
* @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<string, string>;
};

/** ⚠️ WARNING: SUBJECT TO CHANGE */
Expand Down

0 comments on commit d50dddb

Please sign in to comment.