New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Astro.currentLocale
#1841
base: main
Are you sure you want to change the base?
Conversation
* main: i18n(zh-cn): Update docs about synced-tabs (withastro#1834) i18n(zh-cn): Update some docs about withastro#1620 & withastro#1613 (withastro#1835) Add more diagnostic help to error messages thrown by `<Steps>` (withastro#1838) i18n(zh-cn): Update components.mdx (withastro#1836) i18n(zh-cn): Update community-content.mdx (withastro#1833) Improve type checking job (withastro#1831) [ci] format [ci] release (withastro#1832) i18n(ru): update ru.json (withastro#1826) Fix `<Tabs>` sync issue with inconsistent use of `icon` on `<TabItem>` components (withastro#1811) Enable `BASE_URL` tests (withastro#1828)
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
packages/starlight/package.json
Outdated
"vitest": "^1.3.1" | ||
"@vitest/coverage-v8": "^1.4.0", | ||
"astro": "^4.4.5", | ||
"vitest": "^1.4.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Vitest update is required due to withastro/astro#10120 shipped in Astro v4.4.0
.
@@ -4,7 +4,9 @@ import type { i18nSchemaOutput } from '../schemas/i18n'; | |||
import { createTranslationSystem } from './createTranslationSystem'; | |||
|
|||
type UserI18nSchema = 'i18n' extends DataCollectionKey | |||
? CollectionEntry<'i18n'>['data'] | |||
? CollectionEntry<'i18n'> extends { data: infer T } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new change is required to due this change in Astro v4.4.0
which makes CC types include collection names even when a matching directory is absent.
* main: i18n(zh-cn): Update `components.mdx` translation (withastro#1852)
Updated the PR, bumped the required Astro version to 4.8.0 to match #1846 and also updated the code to handle the Astro i18n manual routing strategy added in Astro 4.6.0. |
* main: (45 commits) i18n(tr): add `showcase.mdx` (withastro#1896) [ci] format i18n(zh-cn): Update `authoring-content.md` (withastro#1901) [ci] format [ci] release (withastro#1897) [ci] format i18n(tr): update `authoring-content.md` (withastro#1887) Micro-optimization: clean up `<details>` CSS (withastro#1892) [ci] format i18n(tr): update `components.md` file (withastro#1889) [ci] format i18n(tr): add css-and-tailwind (withastro#1893) [ci] format [ci] release (withastro#1890) Adds custom styles for `<details>` and `<summary>` elements in Markdown content (withastro#1735) Update @astrojs/mdx to v3 (withastro#1846) [ci] format [ci] release (withastro#1869) Add BlueSky social icon (withastro#1871) [ci] format ...
Description
This PR adds support for using
Astro.currentLocale
in Starlight, and also technically adds support for using an Astro i18n configuration instead of a Starlight i18n configuration.First, a new "concept" of Starlight built-in default locale has been introduced. This matches the current English one, except now it's something generated once, based on a BCP 47 tag, and can be used everywhere in the codebase instead of hardcoding
'en'
,'English'
or'ltr'
everywhere.Then, 4 main possibilities are supported when processing both i18n configurations:
A few additional details:
v4.4.5
v4.8.0
just like Update @astrojs/mdx to v3 #1846 so that the following PRs can also be relied upon:Astro.request.headers
is not available in "static" output mode astro#10196test.each
, etc. but I think considering it's a lot of data massaging with internal shapes, with pretty different and identified cases, I personally found that the extra verbosity was a bit better for readability in this case.Regarding the use of an Astro i18n configuration, some inference is done when it comes to locale data, such as labels and text direction. This is due to the fact that Astro doesn't provide a way to specify these in the configuration, so they are inferred using
Intl
features compatible with the minimum Node.js version supported by Astro.For comparison, in the Starlight documentation, here is a language selector labels comparison between the current Starlight i18n configuration and the equivalent inferred Astro i18n configuration:
There are some differences but the code is pretty similar to #1012 where we already got a lot of approvals, so I would think this should be fine, and if needed, people can always switch to the Starlight i18n configuration for more control.
Remaining tasks
Astro.currentLocale
debug infos inpackages/starlight/components/Banner.astro