Make WordPress Core


Ignore:
Timestamp:
12/01/2020 03:42:31 AM (4 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php

    r49334 r49716  
    172172     */
    173173    public function test_background_updates() {
     174        $this->load_admin_textdomain();
    174175        return $this->site_health->get_test_background_updates();
    175176    }
     
    183184     */
    184185    public function test_dotorg_communication() {
     186        $this->load_admin_textdomain();
    185187        return $this->site_health->get_test_dotorg_communication();
    186188    }
     
    194196     */
    195197    public function test_loopback_requests() {
     198        $this->load_admin_textdomain();
    196199        return $this->site_health->get_test_loopback_requests();
    197200    }
     
    205208     */
    206209    public function test_authorization_header() {
     210        $this->load_admin_textdomain();
    207211        return $this->site_health->get_test_authorization_header();
    208212    }
     
    219223            require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php';
    220224        }
     225
     226        $this->load_admin_textdomain();
    221227
    222228        $sizes_data = WP_Debug_Data::get_sizes();
     
    255261
    256262        return $all_sizes;
     263    }
     264
     265    /**
     266     * Loads the admin textdomain for Site Health tests.
     267     *
     268     * The {@see WP_Site_Health} class is defined in WP-Admin, while the REST API operates in a front-end context.
     269     * This means that the translations for Site Health won't be loaded by default in {@see load_default_textdomain()}.
     270     *
     271     * @since 5.6.0
     272     */
     273    protected function load_admin_textdomain() {
     274        // Accounts for inner REST API requests in the admin.
     275        if ( ! is_admin() ) {
     276            $locale = determine_locale();
     277            load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" );
     278        }
    257279    }
    258280
Note: See TracChangeset for help on using the changeset viewer.