-
-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
Astro.currentLocale
(#1841)
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com> Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
- Loading branch information
1 parent
dd64836
commit ee0cd38
Showing
15 changed files
with
619 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@astrojs/starlight": minor | ||
--- | ||
|
||
Adds support for `Astro.currentLocale` and Astro’s i18n routing. | ||
|
||
⚠️ **Potentially breaking change:** Starlight now configures Astro’s `i18n` option for you based on its `locales` config. | ||
|
||
If you are currently using Astro’s `i18n` option as well as Starlight’s `locales` option, you will need to remove one of these. | ||
In general we recommend using Starlight’s `locales`, but if you have a more advanced configuration you may choose to keep Astro’s `i18n` config instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/starlight/__tests__/i18n-non-root-single-locale/i18n.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { assert, describe, expect, test } from 'vitest'; | ||
import type { AstroConfig } from 'astro'; | ||
import config from 'virtual:starlight/user-config'; | ||
import { processI18nConfig } from '../../utils/i18n'; | ||
|
||
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'); | ||
expect(astroI18nConfig.locales).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"codes": [ | ||
"fr-CA", | ||
], | ||
"path": "fr", | ||
}, | ||
] | ||
`); | ||
assert(typeof astroI18nConfig.routing !== 'string'); | ||
expect(astroI18nConfig.routing?.prefixDefaultLocale).toBe(true); | ||
|
||
// The Starlight configuration should not be modified. | ||
expect(config).toStrictEqual(starlightConfig); | ||
}); | ||
|
||
test('throws an error when an Astro i18n config is also provided', () => { | ||
expect(() => | ||
processI18nConfig(config, { defaultLocale: 'en', locales: ['en'] } as AstroConfig['i18n']) | ||
).toThrowErrorMatchingInlineSnapshot(` | ||
"[AstroUserError]: | ||
Cannot provide both an Astro \`i18n\` configuration and a Starlight \`locales\` configuration. | ||
Hint: | ||
Remove one of the two configurations. | ||
See more at https://starlight.astro.build/guides/i18n/" | ||
`); | ||
}); | ||
}); |
Oops, something went wrong.