Skip to content

Commit

Permalink
Fix an Astro i18n → Starlight i18n config conversion issue (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Jul 10, 2024
1 parent 4442b56 commit 359a642
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-bananas-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes an i18n configuration issue for multilingual sites when using Astro’s `i18n` config with `prefixDefaultLocale` set to `false`.
4 changes: 2 additions & 2 deletions packages/starlight/__tests__/basics/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('processI18nConfig', () => {
locales: ['en', { codes: ['fr'], path: 'french' }],
},
expected: {
defaultLocale: { label: 'English', lang: 'en', dir: 'ltr', locale: 'en' },
defaultLocale: { label: 'English', lang: 'en', dir: 'ltr', locale: undefined },
locales: {
root: { label: 'English', lang: 'en', dir: 'ltr' },
french: { label: 'Français', lang: 'fr', dir: 'ltr' },
Expand All @@ -180,7 +180,7 @@ describe('processI18nConfig', () => {
routing: { prefixDefaultLocale: false },
},
expected: {
defaultLocale: { label: 'فارسی', lang: 'fa', dir: 'rtl', locale: 'fa' },
defaultLocale: { label: 'فارسی', lang: 'fa', dir: 'rtl', locale: undefined },
locales: {
root: { label: 'فارسی', lang: 'fa', dir: 'rtl' },
de: { label: 'Deutsch', lang: 'de', dir: 'ltr' },
Expand Down
11 changes: 6 additions & 5 deletions packages/starlight/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ function getStarlightI18nConfig(
locales,
defaultLocale: {
...inferStarlightLocaleFromAstroLocale(defaultAstroLocale),
locale: isMonolingualWithRootLocale
? undefined
: isAstroLocaleExtendedConfig(defaultAstroLocale)
? defaultAstroLocale.codes[0]
: defaultAstroLocale,
locale:
isMonolingualWithRootLocale || (isMultilingual && !prefixDefaultLocale)
? undefined
: isAstroLocaleExtendedConfig(defaultAstroLocale)
? defaultAstroLocale.codes[0]
: defaultAstroLocale,
},
};
}
Expand Down

0 comments on commit 359a642

Please sign in to comment.