summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiDeoo2025-07-11 19:24:33 +0200
committerGitHub2025-07-11 19:24:33 +0200
commit131371e0c897f9c7ea673d93e8f405200d04d312 (patch)
treead4edd4c22852ca7a5da06da4f201cf8b950a899
parent60e39e23359773af5c3cdbcda9f7d878b77a9e7e (diff)
downloadIT.starlight-131371e0c897f9c7ea673d93e8f405200d04d312.tar.gz
IT.starlight-131371e0c897f9c7ea673d93e8f405200d04d312.tar.bz2
IT.starlight-131371e0c897f9c7ea673d93e8f405200d04d312.zip
Fix Astro i18n config default locale issue (#3288)
-rw-r--r--.changeset/pretty-snakes-behave.md5
-rw-r--r--packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts3
-rw-r--r--packages/starlight/__tests__/i18n/i18n.test.ts3
-rw-r--r--packages/starlight/utils/i18n.ts5
4 files changed, 13 insertions, 3 deletions
diff --git a/.changeset/pretty-snakes-behave.md b/.changeset/pretty-snakes-behave.md
new file mode 100644
index 00000000..708b7264
--- /dev/null
+++ b/.changeset/pretty-snakes-behave.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/starlight': patch
+---
+
+Fixes a potential configuration issue for multilingual sites with a default language including a regional subtag.
diff --git a/packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts b/packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts
index b42d2a29..776c7177 100644
--- a/packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts
+++ b/packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts
@@ -7,7 +7,8 @@ describe('processI18nConfig', () => {
test('returns the Astro i18n config for a monolingual site with a non-root single locale', () => {
const { astroI18nConfig, starlightConfig } = processI18nConfig(config, undefined);
- expect(astroI18nConfig.defaultLocale).toBe('fr-CA');
+ // The default locale should match its associated custom locale `path`.
+ expect(astroI18nConfig.defaultLocale).toBe('fr');
expect(astroI18nConfig.locales).toMatchInlineSnapshot(`
[
{
diff --git a/packages/starlight/__tests__/i18n/i18n.test.ts b/packages/starlight/__tests__/i18n/i18n.test.ts
index 383e57ca..770cb379 100644
--- a/packages/starlight/__tests__/i18n/i18n.test.ts
+++ b/packages/starlight/__tests__/i18n/i18n.test.ts
@@ -7,7 +7,8 @@ describe('processI18nConfig', () => {
test('returns the Astro i18n config for a multilingual site with no root locale', () => {
const { astroI18nConfig, starlightConfig } = processI18nConfig(config, undefined);
- expect(astroI18nConfig.defaultLocale).toBe('en-US');
+ // The default locale should match its associated custom locale `path`.
+ expect(astroI18nConfig.defaultLocale).toBe('en');
expect(astroI18nConfig.locales).toMatchInlineSnapshot(`
[
{
diff --git a/packages/starlight/utils/i18n.ts b/packages/starlight/utils/i18n.ts
index 13f1335f..4b23c0a5 100644
--- a/packages/starlight/utils/i18n.ts
+++ b/packages/starlight/utils/i18n.ts
@@ -53,8 +53,11 @@ export function processI18nConfig(
/** Generate an Astro i18n configuration based on a Starlight configuration. */
function getAstroI18nConfig(config: StarlightConfig): NonNullable<AstroConfig['i18n']> {
return {
+ // When using custom locale `path`s, the default locale must match one of these paths.
+ // In Starlight, this matches the `locale` property if defined, and we fallback to the `lang`
+ // property if not (which would be set to the language’s directory name by default).
defaultLocale:
- config.defaultLocale.lang ?? config.defaultLocale.locale ?? BuiltInDefaultLocale.lang,
+ config.defaultLocale.locale ?? config.defaultLocale.lang ?? BuiltInDefaultLocale.lang,
locales: config.locales
? Object.entries(config.locales).map(([locale, localeConfig]) => {
return {