fix: use region-specific translations for default locale#3759
Conversation
…ase language override When a monolingual site uses a region-specific locale as the default (e.g., `zh-TW`), `buildResources` for the default locale was loading both `builtinTranslations['zh-TW']` and `builtinTranslations['zh']` as separate layers. Since `buildResources` applies later layers over earlier ones, the base language (`zh` → Simplified Chinese) was overwriting the region-specific translations (`zh-TW` → Traditional Chinese). This fix aligns the default locale behavior with the locales loop (line 37), using `||` so `stripLangRegion` result is only used as a fallback when the specific locale has no built-in translations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: ba86e01 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 |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hello! Thank you for opening your first PR to Starlight! ✨ Here’s what will happen next:
|
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Thank you @MilesChou! This change makes sense to me.
I initially wondered if it should only flip the order of the two resources (so you’d e.g. apply zh-TW on top of zh instead of the reverse like it is currently). That way e.g. a partial en-US dictionary could be combined with a complete en dictionary.
But I think your change is the right call:
- These are our built-in translations and we require complete dictionaries for these, so there is no possibility of a “partial” dictionary.
- While the
en+en-USexample might make sense, there are cases likezh+zh-TWwhere combining the dictionaries would not make sense.
It’s also what we already do for all other locales, so I think it was just an oversight that we didn’t for the default locale.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [@astrojs/starlight](https://starlight.astro.build) ([source](https://github.com/withastro/starlight/tree/HEAD/packages/starlight)) | [`0.38.1` → `0.38.2`](https://renovatebot.com/diffs/npm/@astrojs%2fstarlight/0.38.1/0.38.2) |  |  | --- ### Release Notes <details> <summary>withastro/starlight (@​astrojs/starlight)</summary> ### [`v0.38.2`](https://github.com/withastro/starlight/blob/HEAD/packages/starlight/CHANGELOG.md#0382) [Compare Source](https://github.com/withastro/starlight/compare/@astrojs/starlight@0.38.1...@astrojs/starlight@0.38.2) ##### Patch Changes - [#​3759](withastro/starlight#3759) [`f24ce99`](withastro/starlight@f24ce99) Thanks [@​MilesChou](https://github.com/MilesChou)! - Fixes an issue where monolingual sites using a region-specific locale (e.g., `zh-TW`) as the default would incorrectly display base language translations (e.g., `zh` Simplified Chinese) instead of the region-specific ones (e.g., `zh-TW` Traditional Chinese). - [#​3768](withastro/starlight#3768) [`a4c6c20`](withastro/starlight@a4c6c20) Thanks [@​delucis](https://github.com/delucis)! - Improves performance of sidebar generation for sites with very large sidebars </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44Ni4wIiwidXBkYXRlZEluVmVyIjoiNDMuODYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==--> Co-authored-by: Renovate Bot <renovate@zarantonello.dev> Co-committed-by: Renovate Bot <renovate@zarantonello.dev>

Summary
buildResourcesusingstripLangRegionresult as a separate layer that overwrites region-specific translationslang: 'zh-TW'gets Simplified Chinese (zh) UI strings instead of Traditional Chinese (zh-TW)Root Cause
In
createTranslationSystem.ts, the default locale translation loading passes bothbuiltinTranslations[defaultLocale]andbuiltinTranslations[stripLangRegion(defaultLocale)]as separate arguments tobuildResources. SincebuildResourcesapplies later layers over earlier ones,zh(Simplified Chinese) overwriteszh-TW(Traditional Chinese).The locales loop (line 37) correctly uses
||as a fallback, but the default locale path (line 25-26) does not.Fix
Align the default locale behavior with the locales loop by using
||so thestripLangRegionresult is only used as a fallback when the specific locale has no built-in translations:Test plan
zh-TWmonolingual site verifyingsearch.labelreturns搜尋(Traditional Chinese) instead of搜索(Simplified Chinese)Reproduction
The UI strings (search, theme selector, etc.) incorrectly show Simplified Chinese instead of Traditional Chinese.
🤖 Generated with Claude Code