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

Expose localized UI strings in route data #1135

Merged
merged 11 commits into from
Nov 29, 2023
Merged

Conversation

delucis
Copy link
Member

@delucis delucis commented Nov 24, 2023

Description

  • Closes Allow useTranslations in overridden components #1060 and also partially addresses Cannot access certain imports - Overriding components #860.
  • Exposes a new labels property in Starlight’s route data object for each page.
  • This object includes all localized UI strings that up to now were retrieved using useTranslations() and the t() helper it returned.
  • This enables components overriding Starlight’s defaults to easily reuse the built-in UI strings.
  • This PR also refactors all our built-in components to use labels instead of calling useTranslations() themselves.
  • Removes the t.pick() helper previously returned by useTranslations() is it is no longer used.

Copy link

changeset-bot bot commented Nov 24, 2023

🦋 Changeset detected

Latest commit: 6d9e44d

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

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight 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

Copy link

vercel bot commented Nov 24, 2023

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

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Nov 29, 2023 7:24pm

@github-actions github-actions bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package labels Nov 24, 2023
@astrobot-houston
Copy link
Collaborator

astrobot-houston commented Nov 24, 2023

size-limit report 📦

Path Size
/index.html 5.12 KB (0%)
/_astro/*.js 20.11 KB (0%)
/_astro/*.css 13 KB (0%)

Copy link
Member

@HiDeoo HiDeoo left a comment

Choose a reason for hiding this comment

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

The changes look good to me and I think this properly address the linked issues.

One thing I want to note tho is that with this approach, if we ever move to i18next or something similar with a more advanced t(), we would not be able to use some of the advanced features like interpolation, formatting, plurals, context, etc. I don't really see us needing those features in the near future, but I just wanted to point that out.

@delucis
Copy link
Member Author

delucis commented Nov 24, 2023

if we ever move to i18next or something similar with a more advanced t(), we would not be able to use some of the advanced features like interpolation, formatting, plurals, context, etc.

I think if we ever do that, we could still expose those functions on the route data object. Technically this API could have just added t() to the route data object, but I decided to go the plain data route because it fits better with the rest of our route data story for now.

@HiDeoo
Copy link
Member

HiDeoo commented Nov 24, 2023

I think if we ever do that, we could still expose those functions on the route data object. Technically this API could have just added t() to the route data object, but I decided to go the plain data route because it fits better with the rest of our route data story for now.

Oh definitely, I meant "we would not be able to use some of the advanced features" while keeping the same API without additional changes like exposing t(). Should have been more clear about that, my bad.

delucis added a commit that referenced this pull request Nov 24, 2023
Formatting is intentionally weird in this file to help simplify merging with #1135
@delucis delucis added the 🌟 minor Change that triggers a minor release label Nov 24, 2023
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 🌟 minor Change that triggers a minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants