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

Site Settings: Allow language change even if WPLANG is defined as constant #13154

Merged
merged 3 commits into from
Aug 1, 2019

Conversation

donpark
Copy link
Contributor

@donpark donpark commented Jul 30, 2019

wp-admin users can change site language even if WPLANG constant is defined in wp-config.php. This PR allows Calypso user to do the same in the general settings page (/settings/general/).

Fixes Automattic/wp-calypso#33440

Changes proposed in this Pull Request:

Removes defined( 'WPLANG' ) checks from Jetpack's Core Data API endpoints used by Calypso to change site settings.

Testing instructions:

  1. Test with a Jetpack site whose wp-config.php contains the line define('WPLANG', '');
  2. Navigate to URL: https://wordpress.com/settings/general/{site_slug}.
  3. Check that error message no longer appears.

Before:
58593747-97de3f80-8220-11e9-8211-e2b65f0a0d8c

After:
screenshot_815

  1. Also check that site language can now be changed.

Proposed changelog entry for your changes:

  • allow language to be changed even if WPLANG constant is defined.

@donpark donpark requested review from a team, gravityrail, lancewillett and jeherve July 30, 2019 18:08
@donpark donpark added the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Jul 30, 2019
@donpark donpark changed the title Settings: Allow language change even if WPLANG is defined as constant Site Settings: Allow language change even if WPLANG is defined as constant Jul 30, 2019
@jetpackbot
Copy link

jetpackbot commented Jul 30, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: August 6, 2019.
Scheduled code freeze: July 30, 2019

Generated by 🚫 dangerJS against 7f447d1

@donpark
Copy link
Contributor Author

donpark commented Jul 30, 2019

Core displays a notice after site language is change if WPLANG constant is defined:

screenshot_814

I felt above message may confuse Calypso users so chose not to display a similar notice. Fact that it involves a lot more work to display the notice in Calypso also contributed.

gravityrail
gravityrail previously approved these changes Jul 30, 2019
Copy link
Contributor

@gravityrail gravityrail left a comment

Choose a reason for hiding this comment

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

I have confirmed that this patch fixes the issue.

@donpark
Copy link
Contributor Author

donpark commented Jul 31, 2019

Reason for most recent update: Core's get_locale() uses WPLANG as default if defined and non-empty. Otherwise en_US is used.

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] WPCOM API labels Jul 31, 2019
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This handles empty strings for WPLANG well, but it does not handle valid strings.

For example, if I set WPLANG to fr_FR, here is what happens today with master:

image

And here is what happens with your branch:

image

That is not correct here, since my interface language is actually french, not English.

Maybe when WPLANG is defined and not empty, we should send the value back to WordPress.com so it can be displayed in Calypso.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Focus] i18n Internationalization / i18n, adaptation to different languages and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jul 31, 2019
@donpark
Copy link
Contributor Author

donpark commented Jul 31, 2019

For example, if I set WPLANG to fr_FR, here is what happens today with master:
...
That is not correct here, since my interface language is actually french, not English.

That may be a problem in Calypso, not in JP endpoint. With same setup, lang_id returned by remote Jetpack endpoint is French as remote site's wp-admin displays:

screenshot_819

wp-admin:

screenshot_822

But Calypso continues to display English as site language.

screenshot_821

Since this PR is about the endpoint, perhaps I should update the test plan to use WPCOM Console so we can at least fix the JP endpoint behavior to match that of wp-admin.

Meanwhile I'm going to look into why Calypso is misbehaving. I also noticed several /me/setttings requests being made repeatedly when Settings page reloads, all failing with reauthorization_required that is ignored by Calypso.

Maybe when WPLANG is defined and not empty, we should send the value back to WordPress.com so it can be displayed in Calypso.

Did you test with latest version? That's is what is being done now.

$value = get_option( 'WPLANG' );
if ( empty( $value ) && defined( 'WPLANG' ) ) {
	$value = WPLANG;
}
$response[ $setting ] = empty( $value ) ? 'en_US' : $value;

@donpark
Copy link
Contributor Author

donpark commented Jul 31, 2019

Hold on. I may be looking at wrong API response.

@donpark
Copy link
Contributor Author

donpark commented Jul 31, 2019

OK. I was looking at the wrong endpoint. End point that matters is:
https://public-api.wordpress.com/rest/v1.1/jetpack-blogs/{site_id}/rest-api/?http_envelope=1&path=%2Fjetpack%2Fv4%2Fsettings%2F&json=true

Finding out why the endpoint kept returning en_US as lang_id was a head-scratcher because:

  1. WPLANG option was not set and
  2. invoking get_option( 'WPLANG' ) from wp shell returns false but
  3. same function call in the endpoint code was returning en_US as value.

Replacing the call with get_option( 'WPLANG', '' ) removed the mystery value and Calypso started displaying same language value as wp-admin with WPLANG constant defined as fr_FR:

screenshot_823

@jeherve I think something went wrong with your test setup because black warning notice only comes up if error_const is returned as lang_id value and, with this patch, error_const is never returned. In other words, that warning notice should not come up if test setup is correct.

@donpark donpark requested a review from jeherve July 31, 2019 18:08
@donpark donpark added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Jul 31, 2019
@jeherve
Copy link
Member

jeherve commented Aug 1, 2019

I think something went wrong with your test setup

Yes I am sorry, I pasted the same screenshot twice in my comment, that was a mistake.

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well now. 👍

@jeherve jeherve removed the [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. label Aug 1, 2019
@jeherve jeherve added the [Status] Ready to Merge Go ahead, you can push that green button! label Aug 1, 2019
@jeherve jeherve added this to the 7.7 milestone Aug 1, 2019
@donpark donpark merged commit eb9a15f into master Aug 1, 2019
@donpark donpark deleted the fix/wplang-const branch August 1, 2019 18:59
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Aug 1, 2019
jeherve added a commit that referenced this pull request Aug 23, 2019
jeherve added a commit that referenced this pull request Aug 27, 2019
* 7.7 changelog: initial set of changes

* Changelog: add #13154

* Changelog: add #13134

* Changelog: add #12699 and many others

* Changelog: add #13127

* Changelog: add #13167

* Changelog: add #13225

* Changelog: add #13179

* Changelog: add #13173

* Changelog: add #13232

* Changelog: add #13137

* Changelog: add #13172

* Changelog: add #13182

* Changelog: add #13200

* Changelog: add #13244

* Changelog: add #13267

* Changelog: add #13204

* changelog: add #13205

* Changelog: add #13183

* Changelog: add #13278

* Changelog: add #13162

* Changelog: add #13268

* Changelog: add #13286

* Changelog: add #13273

* Changelog: add #12474

* Changelog: add #13085

* Changelog: add #13266

* Changelog: add #13306

* Changelog: add #13311

* Changelog: add #13302

* Changelog: add #13196

* Changelog: add #12733

* Changelog: add #13261

* Changelog: add #13322

* Changelog: add #13333

* Changelog: add #13335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WPCOM API [Focus] i18n Internationalization / i18n, adaptation to different languages [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect warning about WPLANG constant when set to empty string
5 participants