Skip to content

Commit 131371e

Browse files
authored
Fix Astro i18n config default locale issue (#3288)
1 parent 60e39e2 commit 131371e

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

.changeset/pretty-snakes-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/starlight': patch
3+
---
4+
5+
Fixes a potential configuration issue for multilingual sites with a default language including a regional subtag.

packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ describe('processI18nConfig', () => {
77
test('returns the Astro i18n config for a monolingual site with a non-root single locale', () => {
88
const { astroI18nConfig, starlightConfig } = processI18nConfig(config, undefined);
99

10-
expect(astroI18nConfig.defaultLocale).toBe('fr-CA');
10+
// The default locale should match its associated custom locale `path`.
11+
expect(astroI18nConfig.defaultLocale).toBe('fr');
1112
expect(astroI18nConfig.locales).toMatchInlineSnapshot(`
1213
[
1314
{

packages/starlight/__tests__/i18n/i18n.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ describe('processI18nConfig', () => {
77
test('returns the Astro i18n config for a multilingual site with no root locale', () => {
88
const { astroI18nConfig, starlightConfig } = processI18nConfig(config, undefined);
99

10-
expect(astroI18nConfig.defaultLocale).toBe('en-US');
10+
// The default locale should match its associated custom locale `path`.
11+
expect(astroI18nConfig.defaultLocale).toBe('en');
1112
expect(astroI18nConfig.locales).toMatchInlineSnapshot(`
1213
[
1314
{

packages/starlight/utils/i18n.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ export function processI18nConfig(
5353
/** Generate an Astro i18n configuration based on a Starlight configuration. */
5454
function getAstroI18nConfig(config: StarlightConfig): NonNullable<AstroConfig['i18n']> {
5555
return {
56+
// When using custom locale `path`s, the default locale must match one of these paths.
57+
// In Starlight, this matches the `locale` property if defined, and we fallback to the `lang`
58+
// property if not (which would be set to the language’s directory name by default).
5659
defaultLocale:
57-
config.defaultLocale.lang ?? config.defaultLocale.locale ?? BuiltInDefaultLocale.lang,
60+
config.defaultLocale.locale ?? config.defaultLocale.lang ?? BuiltInDefaultLocale.lang,
5861
locales: config.locales
5962
? Object.entries(config.locales).map(([locale, localeConfig]) => {
6063
return {

0 commit comments

Comments
 (0)