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

Use i18next for UI strings and add new injectTranslations plugin callback #1923

Merged
merged 62 commits into from
Sep 18, 2024

Conversation

HiDeoo
Copy link
Member

@HiDeoo HiDeoo commented May 22, 2024

This PR is currently based on #1841.

Description

This PR:

  • Adds a new injectTranslations plugin callback for plugins to inject translations to Starlight.
  • Refactors the UI strings/translations to a middleware.
  • Refactors the UI strings/translations to use i18next.
  • Exposes UI strings/translations API to users and plugins.

Note that the links validation is failing a lot but this is expected as the links validator plugin does not support the configuration syntax based on #1841.

Remaining tasks

  • Figure out typings for plugins accessing their own custom injected translations (error in examples/custom-plugin/MarkdownContent.astro)
  • Improve the documentation which is currently a very rough draft just to document the available APIs
  • Bump peer dependencies
    • starlight: Astro 4.14.0 for injectTypes()
    • starlight-docsearch: Latest Starlight as it uses this new feature
  • Add a changeset
    • This would span across multiple packages, e.g. @astrojs/starlight-docsearch
  • See if some tests can be removed, e.g. the ones that used to check for Astro.props.labels which now checks that it's not defined anymore (useful during dev but maybe not worth keeping)
  • Address and remove all the // TODO(HiDeoo) comments
  • Remove debug content
    • docs/src/content/docs/guides/debug-i18next.mdx
    • docs/src/components/i18next-debug.astro
    • docs/src/content/i18n/**/*
    • examples/custom-plugin/**/*

HiDeoo added 24 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)
* main:
  i18n(zh-cn): Update `components.mdx` translation (withastro#1852)
* 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
  ...
Copy link

changeset-bot bot commented May 22, 2024

🦋 Changeset detected

Latest commit: 9dad875

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@astrojs/starlight Minor
@astrojs/starlight-docsearch Minor

Not sure what this means? Click here to learn what changesets are.

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

@github-actions github-actions bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package labels May 22, 2024

This comment was marked as outdated.

@astrobot-houston
Copy link
Collaborator

astrobot-houston commented May 22, 2024

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en guides/i18n.mdx Source changed, localizations will be marked as outdated.
en reference/overrides.md Source changed, localizations will be marked as outdated.
en reference/plugins.md Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@HiDeoo HiDeoo marked this pull request as draft May 22, 2024 14:24
.changeset/cool-experts-sort.md Outdated Show resolved Hide resolved
docs/src/content/docs/reference/plugins.md Outdated Show resolved Hide resolved
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y'all are just too good at this! I am so happy to see this accomplishment, and really proud to be associated with the quality of work in this project!

One tiny thought I had while reading the changeset, but the docs are fantastic.

'@astrojs/starlight': minor
---

Overhauls the built-in localization system which is now powered by the [`i18next`](https://www.i18next.com/) library and available to use anywhere in your documentation website.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If applicable, it might be worth a note re: if there is anyone who might have a multi-language site who does NOT need to do anything differently.

Does this only affect people who want to access/render the strings themselves, like in new UI elements they build? Is it possible that there are people with very basic sites with multiple languages where the built in "previous/next page" etc. is all they use and will still just work? Or is it assumed that EVERYONE with a multi-language site will need to update?

Overhauls the built-in localization system which is now powered by the [`i18next`](https://www.i18next.com/) library and available to use anywhere in your documentation website.

This update includes more features and potentially breaking changes for those who created custom, translated, UI elements. Starlight's built-in elements available by configuring support for a language have not changed.

Like, that may be totally wrong, but if there's a clean way of saying what people don't have to worry about/update, I think that's helpful to lead in here, especially when there is a breaking change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is already clear from the breaking change section? It says this only applies if you were using component overrides.

@github-actions github-actions bot added 🌟 tailwind Changes to Starlight’s Tailwind package 🌟 markdoc Changes to Starlight’s Markdoc package labels Sep 18, 2024
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me! This is a very exciting feature to be added. Excited to see what people do with and excited to see if we got anything wrong 😁

Thank you again @HiDeoo — all yours to merge! 🌟

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 🌟 markdoc Changes to Starlight’s Markdoc package 🌟 minor Change that triggers a minor release 🌟 tailwind Changes to Starlight’s Tailwind package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants