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

WordPress.com Features: Calypso Locale Sync from wp-admin to Calypso #37316

Merged
merged 17 commits into from
May 14, 2024

Conversation

miksansegundo
Copy link
Contributor

@miksansegundo miksansegundo commented May 9, 2024

Related #37352 #19525 pfsHM7-Va-p2

Fixes https://github.com/Automattic/dotcom-forge/issues/6812

Proposed changes:

Calypso Locale Sync from wp-admin to Calypso:

  • Use the hook profile_update to get the wp-admin user profile locale update
  • The locale is received in the format en_US, it's formatted as a language code en-us, and when that code doesn't exist, the language variation is removed en.
  • When the user selects "Site Default", the locale is coming from the option WPLANG
  • Request to /wpcom/v2/me/locale to update Calypso locale (user meta locale in wpcom database)
  • When the user changes the "Site language" from /wp-admin/options-general.php and "Site Default" option is selected as the user locale, the hook update_option_WPLANG triggers the Calypso locale sync to the new Site language.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Test with the API from D148231-code

  • Go to /wp-admin/profile.php on your Atomic test site, change and save the language.

    • Try also with language variations such as "English (UK)" or "Español de Mexico"
      image
  • You should see the language change reflected on https://wordpress.com/sites

  • Repeat the test, but this time choose the option "Site Default", which will use the Site language selected in /wp-admin/options-general.php

  • Leave selected the option "Site Default" and change the "Site language" from /wp-admin/options-general.php to verify the Calypso locale is updated to the new Site language.

wp-admin Calypso
Screenshot 2567-05-10 at 18 31 38 Screenshot 2567-05-10 at 18 31 28
Screenshot 2567-05-10 at 18 32 16 Screenshot 2567-05-10 at 18 32 09
Screenshot 2567-05-10 at 19 14 20Screenshot 2567-05-10 at 19 09 15 Screenshot 2567-05-10 at 18 31 28
Screenshot 2567-05-14 at 18 54 58Screenshot 2567-05-14 at 18 59 05 Screenshot 2567-05-14 at 18 58 39

Copy link
Contributor

github-actions bot commented May 9, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the fix/calypso-locale-sync branch.

    • For jetpack-mu-wpcom changes, also add define( 'JETPACK_MU_WPCOM_LOAD_VIA_BETA_PLUGIN', true ); to your wp-config.php file.
  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/calypso-locale-sync
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented May 9, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Mu Wpcom plugin:

  • Next scheduled release: June 4, 2024.
  • Scheduled code freeze: May 27, 2024.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

DustyReagan
DustyReagan previously approved these changes May 10, 2024
Copy link
Member

@DustyReagan DustyReagan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great!

fushar
fushar previously approved these changes May 13, 2024
Copy link
Contributor

@fushar fushar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working great!

@fushar
Copy link
Contributor

fushar commented May 14, 2024

@miksansegundo @DustyReagan I pushed 100a220 which does two things:

  1. Extract the inline filter function into a real function for better documentation (with this we can add name to the function)
  2. Rename the file to /calypso-locale-sync/sync-wp-admin-to-calypso.php. My idea/suggestion is to move the file in this PR WordPress.com Features: Calypso Locale Sync from Calypso to wp-admin  #37352 to /calypso-locale-sync/sync-calypso-to-wp-admin.php. With this the logic are colocated in the same place.

What do you think? Feel free to modify!

@miksansegundo miksansegundo force-pushed the fix/calypso-locale-sync branch from 734a5f3 to 067a906 Compare May 14, 2024 05:54
@miksansegundo miksansegundo changed the title WordPress.com Features: Sync atomic site locale on calypso locale WordPress.com Features: Calypso Locale Sync from wp-admin to Calypso May 14, 2024
@miksansegundo
Copy link
Contributor Author

miksansegundo commented May 14, 2024

I have fixed the following edge case in 4f93519

When the "Site Default" option is selected in /wp-admin/profile.php and the user changes the "Site language" from /wp-admin/options-general.php, we have to update the Calypso locale with the new Site language.

Reproduction steps:

  • Calypso locale is English
  • Site language is English
  • Go to /wp-admin/profile.php and change the wp-admin locale to "Site Default"
  • Go to /wp-admin/options-general.php and change the Site language to "Spanish"
  • Visit https://wordpress.com/plans/{ YOUR SITE } to verify the UI is completely in Spanish because Calypso locale in /me/account has been updated to English

@mmtr
Copy link
Member

mmtr commented May 14, 2024

I think this PR can mess the translations to users with multiple sites.

Steps to reproduce:

  • Calypso locale is English
  • wp-admin locale of Site A is English
  • wp-admin locale of Site B is English
  • Go to <SITE_A>/wp-admin/profile.php and change the wp-admin locale to Spanish ✅
  • Go to wordpress.com/me/account and confirm that the Calypso locale has changed to Spanish ✅
  • Go to <SITE_B>/wp-admin/profile.php and confirm that the wp-admin is still English ✅
  • Go to wordpress.com/plans/<SITE_B> to verify that the UI is in Spanish ❌

@mmtr
Copy link
Member

mmtr commented May 14, 2024

To fix the behavior I noted above, I think we need to change Calypso so when the user is on a page with nav unification (e.g. My Home, Plans, Domains, etc) and the admin interface is classic, we use the wp-admin locale instead of the Calypso locale.

If we do that, I think we can also fix the problem noted by @miksansegundo earlier.

@miksansegundo
Copy link
Contributor Author

Thanks for testing!

Go to wordpress.com/plans/<SITE_B> to verify that the UI is in Spanish ❌

I just pushed a fix in 4f93519

@miksansegundo miksansegundo requested a review from DustyReagan May 14, 2024 12:02
@mmtr
Copy link
Member

mmtr commented May 14, 2024

Go to wordpress.com/plans/<SITE_B> to verify that the UI is in Spanish ❌

I just pushed a fix in 4f93519

I think the issue I described is still present. It's not an issue about using the site default language, but an issue about having multiple sites with different languages.

@mmtr
Copy link
Member

mmtr commented May 14, 2024

I think this PR can mess the translations to users with multiple sites.

Clarified in p1715689279091669-slack-C06DN6QQVAQ. #37352 will also sync the locale back from Calypso to all classic sites and Site B will have the same locale as Site A.

I have some concerns though about users being unaware that the locale setting in wp-admin is actually a global UI language across all sites and WordPress.com, but I guess we can improve that in a follow-up with an informative notice or something else.

@mmtr
Copy link
Member

mmtr commented May 14, 2024

Pretty close! Overall this works quite well, but the Calypso locale doesn't change when I follow these steps:

  • wp-admin locale is English
  • Site language is English
  • Go to /wp-admin/profile.php
  • Change locale to Spanish
  • Go to wordpress.com/me/account
  • Confirm the locale is Spanish
  • Go to /wp-admin/profile.php
  • Change locale to Site Default
  • Go to wordpress.com/me/account
  • ❌ Locale is still Spanish. Should be English, since that's my site language.

EDIT: Fixed it in 40b656d

@mmtr mmtr merged commit a4f77e6 into trunk May 14, 2024
54 checks passed
@mmtr mmtr deleted the fix/calypso-locale-sync branch May 14, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants