Skip to content
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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented May 8, 2024

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:

  • If no Astro and Starlight i18n configurations are provided, the built-in default locale is used in Starlight and a matching Astro i18n configuration is generated/used.
  • If only a Starlight i18n configuration is provided, an equivalent Astro i18n configuration is generated/used.
  • If only an Astro i18n configuration is provided, the Starlight i18n configuration is updated to match it.
  • If both an Astro and Starlight i18n configurations are provided, an error is thrown.

A few additional details:

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:

Starlight i18n config Astro i18n config
SCR-20240508-jgwp SCR-20240508-jhmh

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

  • Switch back to the Starlight i18n configuration in the documentation
  • Remove the Astro.currentLocale debug infos in packages/starlight/components/Banner.astro
  • Figure out what and how much should be documented
  • Write the documentation
  • Add a changeset

HiDeoo added 7 commits May 5, 2024 10:54
* 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)
Copy link

changeset-bot bot commented May 8, 2024

⚠️ No Changeset found

Latest commit: b079bd7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented May 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview May 20, 2024 1:18pm

@github-actions github-actions bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package 🌟 tailwind Changes to Starlight’s Tailwind package labels May 8, 2024
"vitest": "^1.3.1"
"@vitest/coverage-v8": "^1.4.0",
"astro": "^4.4.5",
"vitest": "^1.4.0"
Copy link
Member Author

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 }
Copy link
Member Author

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.

@HiDeoo
Copy link
Member Author

HiDeoo commented May 14, 2024

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
  ...
@github-actions github-actions bot removed the 🌟 tailwind Changes to Starlight’s Tailwind package label May 20, 2024
@HiDeoo HiDeoo marked this pull request as ready for review May 20, 2024 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package 📚 docs Documentation website changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant