Site Health, App Passwords: Ensure REST API responses are properly translated.
The REST API requests in Site Health and App Passwords now include `_locale=user` in the request URL to ensure the user's locale is used instead of the site locale. Additionally, the `apiRequest` library now sends a JSON `Accept` header which is required by `determine_locale()` to respect the `_locale` query parameter. The Site Health REST API controllers now manually load the default admin textdomain if not `is_admin()`. This allows for the Site Health tests to be translated even though the translations are part of the administration project and the REST API is not. Props oglekler, kebbet, Clorith, TimothyBlynJacobs, ocean90, SergeyBiryukov, adamsilverstein. Fixes #51871. Built from https://develop.svn.wordpress.org/trunk@49716 git-svn-id: http://core.svn.wordpress.org/trunk@49439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -171,6 +171,7 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
* @return array
|
||||
*/
|
||||
public function test_background_updates() {
|
||||
$this->load_admin_textdomain();
|
||||
return $this->site_health->get_test_background_updates();
|
||||
}
|
||||
|
||||
@@ -182,6 +183,7 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
* @return array
|
||||
*/
|
||||
public function test_dotorg_communication() {
|
||||
$this->load_admin_textdomain();
|
||||
return $this->site_health->get_test_dotorg_communication();
|
||||
}
|
||||
|
||||
@@ -193,6 +195,7 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
* @return array
|
||||
*/
|
||||
public function test_loopback_requests() {
|
||||
$this->load_admin_textdomain();
|
||||
return $this->site_health->get_test_loopback_requests();
|
||||
}
|
||||
|
||||
@@ -204,6 +207,7 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
* @return array
|
||||
*/
|
||||
public function test_authorization_header() {
|
||||
$this->load_admin_textdomain();
|
||||
return $this->site_health->get_test_authorization_header();
|
||||
}
|
||||
|
||||
@@ -219,6 +223,8 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
|
||||
}
|
||||
|
||||
$this->load_admin_textdomain();
|
||||
|
||||
$sizes_data = WP_Debug_Data::get_sizes();
|
||||
$all_sizes = array( 'raw' => 0 );
|
||||
|
||||
@@ -256,6 +262,22 @@ class WP_REST_Site_Health_Controller extends WP_REST_Controller {
|
||||
return $all_sizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the admin textdomain for Site Health tests.
|
||||
*
|
||||
* The {@see WP_Site_Health} class is defined in WP-Admin, while the REST API operates in a front-end context.
|
||||
* This means that the translations for Site Health won't be loaded by default in {@see load_default_textdomain()}.
|
||||
*
|
||||
* @since 5.6.0
|
||||
*/
|
||||
protected function load_admin_textdomain() {
|
||||
// Accounts for inner REST API requests in the admin.
|
||||
if ( ! is_admin() ) {
|
||||
$locale = determine_locale();
|
||||
load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the schema for each site health test.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user