Conversation
Translation systems are now created from a BCP 47 language tag instead of a locale which in Starlight represents a language path in the URL.
🦋 Changeset detectedLatest commit: 16cfb89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
|
I noticed that the file I hope it helps! |
|
Thanks for the feedback 🙌
This PR refactors |
|
What I meant is that the UI translation problem is still happening when I use this current pull request. I forked this repo and used as a local package to test on my own Astro project. However, that did not happen when I tried directly on the "docs" in the monorepo. When you log I made a video so you can better understand. At the bottom left is this current pull request. At the right is my own project, you can see it is not logging the wright locale: Recording.2024-10-18.171635.mp4 |
|
I see, I think there are 2 points here:
Always getting I tried reproducing the issue locally but I couldn't using the following config I assumed from your video: defaultLocale: "en",
locales: {
en: { label: "English", lang: "en" },
"pt-br": { label: "Português do Brasil", lang: "pt-BR" },
},Would you be able to share your Starlight config so I can investigate further?
This is expected with the current changes as |
|
I already tried different configs too. Using Astro's native i18n or with starlight. No luck so far. My current config: |
|
Oh, that just hit me, which version of Astro are you using? I had a similar issue a few days ago that was an issue in Astro which was fixed in Astro 4.16.4. Would you be able to test using the latest Astro version? |
|
Oh man... that was it! Thanks a lot. Also thanks for this PR! |
|
Amazing to hear, thanks for the follow-up and checking it out 🙌 And no problem, I had the same problem and it took me a while to figure it out, it's a bit tricky to spot an upstream i18n issue while working on another i18n issue 😅 |
delucis
left a comment
There was a problem hiding this comment.
Looks great! I noticed one tiny detail in a comment, but no other notes — will fix that and conflicts now so we can get a patch out with these important fixes.
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com> Co-authored-by: dreyfus92 <85648028+dreyfus92@users.noreply.github.com>
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>

Description
This PR includes the following changes:
Fix translations for languages with a region subtag
Languages with a region subtag (e.g.
zh-CN) are not properly translated in the current implementation. This is visible in the https://starlight.astro.build/zh-cn/components/cards/ page:This issue is due to the fact that
Astro.currentLocalereturns a BCP 47 language tag (usually called alangin Starlight) and that the translation system creation is expecting a language path from the URL (usually called alocalein Starlight) that is later converted to a BCP 47 language tag. Passing down alanginstead of alocalefails that conversion making the translation of languages with a region subtag not work.This PR changes the translation system creation to always use a BCP 47 language tag.
Use
Astro.locals.t()when possibleIn various places, we were still creating more translation systems than necessary instead of using the already configured
Astro.locals.t(). This PR replaces those instances withAstro.locals.t().Docs
The documentation "Accessing the current locale" example has been updated to use
getRelativeLocaleUrl()so that the generated link is always correct.