Opened 4 years ago
Closed 4 years ago
#52441 closed defect (bug) (fixed)
Fix wp.i18n.isRTL() returning false in RTL languages
Reported by: | noisysocks | Owned by: | noisysocks |
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | I18N | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
Currently wp.i18n.isRTL()
will return false
in RTL languages such as Arabic and Hebrew. This was fixed in GB28279. The fix needs to be added to Core for 5.7.
Change History (11)
This ticket was mentioned in PR #977 on WordPress/wordpress-develop by noisysocks.
4 years ago
#2
- Keywords has-patch has-unit-tests added
#4
@
4 years ago
I tried to fix this bug properly by fixing #46089 but it is not enough because then we have a different problem which is that WordPress will print a script’s translations before it prints the script. This means that wp-i18n
’s translations will try to call wp.i18n.setLocaleData()
before wp.i18n
is defined.
So this is just the workaround that's in GB28279.
#5
@
4 years ago
I've tested https://github.com/WordPress/wordpress-develop/pull/977 with WordPress 5.6.1 by:
- Set RTL language
- Enter post editor
- Console log
wp.i18n.isRTL()
(should betrue
) - Without the patch, it's
false
- Manually apply the patch and the result is then
true
as it should be.
The patch seems to work and is very similar to the solution used in Gutenberg.
This does seem like more of a workaround to me, I understand the solution to https://core.trac.wordpress.org/ticket/46089 is complex but I'd really like to see a solution for that. This has the limitation that it still doesn't add wp-i18n
translations, it just adds a specific translation that we know is required.
What about adding a condition to WP_Scripts::print_translations
to print the localization after if the script is the wp-i18n
script?
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#7
@
4 years ago
Thanks for testing!
This does seem like more of a workaround to me, I understand the solution to https://core.trac.wordpress.org/ticket/46089 is complex but I'd really like to see a solution for that. This has the limitation that it still doesn't add wp-i18n translations, it just adds a specific translation that we know is required.
Looking at the source for for wp-i18n
, it seems that "ltr"
is the only localised string that that module has. I agree that this is hacky, but is making print_translations
treat wp-i18n
specially any less hacky? Both solutions feel not ideal to me...
Really I am thinking that wp-i18n
should not have any localised strings at all. It doesn't make intuitive sense to me that a module which is used to implement localisation should require localisation. I wonder if there's another way of implementing isRTL
?
#8
@
4 years ago
i18n is special enough (it's the package responsible for the translations) that I don't mind using the same solution used in Gutenberg. Maybe later we could have some linting protection forbidding new strings there.
Currently
wp.i18n.isRTL()
will return false in RTL languages such as Arabic and Hebrew. This was fixed in https://github.com/WordPress/gutenberg/pull/28279. The fix needs to be added to Core for 5.7.Trac ticket: https://core.trac.wordpress.org/ticket/52441