-
-
Notifications
You must be signed in to change notification settings - Fork 585
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
Improve locale text direction detection mechanism #1987
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 ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for diving into this @HiDeoo. Left a couple of comments but should be good to merge with or without addressing these if you want.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing word in this comment I think:
// @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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too? Now I’m doubting what you meant, but I think it’s this?
// @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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments make sense to me now! Thanks again @HiDeoo 🙌
Description
The newly locale text direction detection mechanism introduced in Starlight
0.24.0
is 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:
textInfo
as 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.