Skip to content
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

Block editor canvas should use site language and language direction #52777

Open
OmerQadirFM opened this issue Jul 20, 2023 · 15 comments · May be fixed by #63883
Open

Block editor canvas should use site language and language direction #52777

OmerQadirFM opened this issue Jul 20, 2023 · 15 comments · May be fixed by #63883
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts l10n Localization and translations best practices [Type] Bug An existing feature does not function as intended

Comments

@OmerQadirFM
Copy link

OmerQadirFM commented Jul 20, 2023

Description

when I'm making a Kurdish or Arabic website, my website shows from LTR in Gutenberg interface but when I visit my website it shows RTL, My user profile language is English and my website language is Kurdish, it is supposed to always shows RTL.

Step-by-step reproduction instructions

in Gutenberg interface
Change user profile language to English
Change website language to Kurdish or Arabic
then go to Appearance > Editor and you will see the issue

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress: 6.4-alpha-56272
  • PHP: 8.1.9
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.9)
  • Browser: Edge 114.0.1823.86 (Windows 10/11)
  • Theme: Twenty Twenty-Three 1.1
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.2

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@OmerQadirFM OmerQadirFM changed the title RTL for Kurdish, Arabic, ... RTL for Kurdish, Arabic, ... website, in Gutenberg interface Jul 20, 2023
@bph bph added l10n Localization and translations best practices Needs Testing Needs further testing to be confirmed. [Type] Bug An existing feature does not function as intended labels Jul 21, 2023
@github-actions
Copy link

Hi,
This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
Thanks for helping out.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 21, 2023
@OmerQadirFM
Copy link
Author

I still have a same problem with WordPress 6.3

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Aug 24, 2023
@sabernhardt
Copy link
Contributor

I thought this was a new bug with the iframe editor, but #44863 mentions needing to have (post) content in the site language when the profile language is different. I did not find a WordPress version that showed site (or post) content in the site language when the profile was different. Did it ever work?

@OmerQadirFM
Copy link
Author

  • WordPress: 6.6-RC2
  • PHP: 8.3.8
  • Server: Apache/2.4.43 (Win32) mod_fcgid/2.3.9a
  • Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.3.8)
  • Browser: Edge 126.0.0.0 (Windows 10/11)
  • Theme: Twenty Twenty-Four 1.1
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.6
2024-07-07.02-51-02.mp4

@ramonjd
Copy link
Member

ramonjd commented Jul 8, 2024

I'm not sure how to reproduce.

I was testing using WordPress 6.7-alpha-58576-src running Twenty Twenty-Four theme. And then with the Gutenberg plugin activated.

I switched to Arabic, then I did have to update the language packs:

/wp-admin/update-core.php?action=do-translation-upgrade

Site Editor menu Editor
Screenshot 2024-07-08 at 4 23 32 PM Screenshot 2024-07-08 at 4 23 53 PM

@OmerQadirFM
Copy link
Author

In this Example your Profile language same as your Site language means your profile and your Site language are same.
the issue happens when your Profile language is English, and your Site language is Arabic
try to change you profile language to English

@ramonjd
Copy link
Member

ramonjd commented Jul 8, 2024

In this Example your Profile language same as your Site language means your profile and your Site language are same.
the issue happens when your Profile language is English, and your Site language is Arabic

Apologies, thanks for setting me straight.

So, is the following an accurate summary?

  • the content in the editor canvas should match the site language (so the preview is the same as what you see on the website)
  • the editor itself (controls etc) should match the user profile language

@OmerQadirFM
Copy link
Author

In this Example your Profile language same as your Site language means your profile and your Site language are same.
the issue happens when your Profile language is English, and your Site language is Arabic

Apologies, thanks for setting me straight.

So, is the following an accurate summary?

  • the content in the editor canvas should match the site language (so the preview is the same as what you see on the website)
  • the editor itself (controls etc) should match the user profile language

Yes, for example, in my case I build Arabic and Kurdish websites and they are both RTL languages and my profile is always in English

When site language is Kurdish (RTL) should the Theme language be Kurdish too and the Editor canvas should shows from right to left (RTL)

the Admin dashboard and The Editor Dashboard should match the profile language

@ramonjd
Copy link
Member

ramonjd commented Jul 10, 2024

I can reproduce now, thanks!

The TL;DR is that the iframed editor needs access to the site locale to set lang and dir attributes on the html element.

What's happening now is that, if a user locale is set in /wp-admin/profile.php the block editor will use it to display the site contents. This is despite whether the site locale is set to another locale.

I had a quick look and there are a few things to investigate here.

The editor iframe

The editor iframe assumes that the editor language direction is the same as the parent frame language direction, and copies the attribute to the iframed html element:

contentDocument.dir = ownerDocument.dir;

If the user locale is en_US but the site locale is something else, we'd prefer the editor iframe to use the site locale to accurately reflect the site's contents.

However, the editor iframe doesn't know what the site locale is, because it's looking at the parent frame, which is set to the user locale of en_US.

Editor settings

We could fetch the right values from the editor iframe via the settings... the interesting task will be returning accurate values for language direction.

Here's what I'm seeing:

In the editor, the "current" locale is set to the user locale. So, en_US in our example.

That means is_rtl() looks at the current, global locale.

What we want is the site locale however, and I'm not yet sure how to grab that. There's probably a way, I just ran out of time.

// Site locale
get_locale(); // ar

// User locale (current)
get_user_locale(); // en_US

// Current site language dir
is_rtl(); // ltr from the current locale.

// Current user language dir
?? // How to get this?

CSS

I'm not sure yet, but I'm also wondering if different CSS needs to be loaded if the iframed editor's language direction differs from the parent.

I'd wager "yes", but I haven't looked into it.

@ramonjd ramonjd changed the title RTL for Kurdish, Arabic, ... website, in Gutenberg interface Block editor canvas should use site language and language direction Jul 10, 2024
@OmerQadirFM
Copy link
Author

Environment

  • WordPress: 6.6
  • PHP: 8.3.8
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 10.4.32-MariaDB / Client: mysqlnd 8.3.8)
  • Browser: Edge 126.0.0.0 (Windows 11)
  • Theme: Twenty Twenty-Four 1.2
  • MU-Plugins: None activated

Screenshot 2024-07-17 233920

@noisysocks noisysocks removed the Needs Testing Needs further testing to be confirmed. label Jul 23, 2024
@swissspidy
Copy link
Member

What we want is the site locale however, and I'm not yet sure how to grab that. There's probably a way, I just ran out of time.

You'll need to switch to the locale first to find out. e.g.

$switched_locale = switch_to_locale( get_locale() );
$is_rtl = is_rtl();
if ( $is_switched ) {
if ( $switched_locale ) {
	restore_previous_locale();
}

I'm not sure yet, but I'm also wondering if different CSS needs to be loaded if the iframed editor's language direction differs from the parent.

I'd imagine you need to load all the blocks' RTL stylesheets.

Maybe some different translations too.

@OmerQadirFM
Copy link
Author

I updated to 6.6.1 but still there is same issue

Environment

  • WordPress: 6.6.1
  • PHP: 8.1.29
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.29)
  • Browser: Edge 126.0.0.0 (Windows 11)
  • Theme: Twenty Twenty-Four 1.2
  • MU-Plugins: None activated
  • Plugins:
    • WordPress Beta Tester 3.5.6

@swissspidy
Copy link
Member

@OmerQadirFM This is expected, as this issue is still open :-)

@ramonjd ramonjd linked a pull request Jul 24, 2024 that will close this issue
@ramonjd
Copy link
Member

ramonjd commented Jul 24, 2024

Thanks @swissspidy - I'd totally overlooked switch_to_locale(), thanks for the nudge.

I have a proof of concept:

It probably raises more questions than answers, most notably how to handle block CSS and block placeholder text direction. There are without doubt many more that I've not thought of.

@ramonjd
Copy link
Member

ramonjd commented Jul 26, 2024

A bit of history: a bug was reported about similar behaviour in the classic editor:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internationalization (i18n) Issues or PRs related to internationalization efforts l10n Localization and translations best practices [Type] Bug An existing feature does not function as intended
Projects
Status: 📥 Todo
Development

Successfully merging a pull request may close this issue.

7 participants