-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
i18n: Add isRTL function #20298
i18n: Add isRTL function #20298
Conversation
- Better test isolation by re-requiring the module - Add `beforeEach` setting up default locale data - Add isRTL tests
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.
Code looks good, thanks for adding docs and improving tests!
I haven't tested this in any way other than confirming that tests run.
Interesting way of checking the rtl direction :) |
It seems to be the canonical way of specifying direction in WordPress. See https://github.com/WordPress/WordPress/blob/511a297fb4b89ad32e89ea0373347cf92367e1c3/wp-includes/class-wp-locale.php#L217-L219
That's what #19212 suggests. I agree that there's value in having a single, well-defined way of checking the text direction. |
Spotted here: gutenberg/packages/components/src/utils/rtl.js Lines 6 to 8 in 61e936c
|
yes, we also have a setting in the block-editor store I believe and another check in the Popover component. |
@youknowriad would you expect to see those uses updated in this PR or good for follow-ups? |
I'm totally fine if we merge this as is :) But I've been promised follow-ups in the past and sometimes they just don't happen :P |
I'll merge this in the next few days unless there are issues or there's a good reason to wait. I didn't plan to modify anything beyond |
Arriving to this late since I'm only recently returning from AFK, but seems like a reasonable addition to me 👍 |
I started to look at this and have some concerns. There's currently a mix of reactive (re-renders as necessary) and non-reactive RTL lookups. For example, this "hook" looks reactive, but isn't: gutenberg/packages/components/src/utils/rtl.js Lines 6 to 15 in a46cd2f
This is reactive, but doesn't know anything about RTL and is reading a value from a data store: gutenberg/packages/block-library/src/paragraph/edit.js Lines 37 to 39 in 67e2df7
Then there are straightforward cases like this:
Replacing the reactive RTL setting lookups with gutenberg/lib/edit-site-page.php Lines 65 to 71 in 320f460
I'd like to see RTL information come from the locale and be updated in a reactive way. Perhaps is worth waiting for #19210 to be resolved? |
I think it's fine, we just need to add a dev note about it. It's unlikely that anyone aside us is using that setting right now. |
I've started some work on using |
Description
Add
isRTL
function for checking whether the locale is right-to-left.This follows the implementation of
WP_Locale::is_rtl()
.https://developer.wordpress.org/reference/classes/wp_locale/is_rtl/
Part of #19212.
The unit tests have been slightly restructured to provide isolation of the
i18n
module between tests.How has this been tested?
Includes unit tests.
Types of changes
New feature (non-breaking change which adds functionality)
Add
isRTL
function to@wordpress/i18n
.Checklist: