Improve locale text direction detection mechanism#1987
Merged
delucis merged 3 commits intowithastro:mainfrom Jun 9, 2024
Merged
Improve locale text direction detection mechanism#1987delucis merged 3 commits intowithastro:mainfrom
delucis merged 3 commits intowithastro:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 53860e4 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 |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
delucis
approved these changes
Jun 9, 2024
packages/starlight/utils/i18n.ts
Outdated
| */ | ||
| function getLocaleDir(locale: Intl.Locale): 'ltr' | 'rtl' { | ||
| if ('textInfo' in locale) { | ||
| // @ts-expect-error - `textInfo` is typed but is available in v8 based environments. |
Member
There was a problem hiding this comment.
Missing word in this comment I think:
Suggested change
| // @ts-expect-error - `textInfo` is typed but is available in v8 based environments. | |
| // @ts-expect-error - `textInfo` is typed but is only available in v8 based environments. |
Member
Author
There was a problem hiding this comment.
Good catch, I think I removed a negation while trying to "simplify" the comment. Just added it back and I think this makes sense without the only but let me know if it's still confusing.
packages/starlight/utils/i18n.ts
Outdated
| // @ts-expect-error - `textInfo` is typed but is available in v8 based environments. | ||
| return locale.textInfo.direction; | ||
| } else if ('getTextInfo' in locale) { | ||
| // @ts-expect-error - `getTextInfo` is typed but is available in some non-v8 based environments. |
Member
There was a problem hiding this comment.
Here too? Now I’m doubting what you meant, but I think it’s this?
Suggested change
| // @ts-expect-error - `getTextInfo` is typed but is available in some non-v8 based environments. | |
| // @ts-expect-error - `getTextInfo` is typed but is only available in some non-v8 based environments. |
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
1 task
Merged
Yoxnear
pushed a commit
to Yoxnear/starlight-custom
that referenced
this pull request
Jul 23, 2025
Co-authored-by: Chris Swithinbank <357379+delucis@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The newly locale text direction detection mechanism introduced in Starlight
0.24.0is based on the v8 implementation ofgetTextInfo()where it is implemented as an accessor property (textInfo).#1961 and #1986 surfaced that this broke in Bun which respects the spec and implements
getTextInfo()as a method.This is also an issue when running Starlight in a WebContainers, e.g. StackBlitz, where the implementation can vary between browsers.
getTextInfo()as an accessor property.getTextInfo()as a method.getTextInfo()ortextInfo.To handle with all these cases, the new version will use the following mechanism to detect the text direction:
textInfoas an accessor property.getTextInfo()as a method.Here are some screenshots of the checks in the Node.js and Bun REPLs:
Regarding the list of well-known RTL locales, I picked all the RTL languages from this list of common primary language subtags.