Make WordPress Core

Changeset 57286


Ignore:
Timestamp:
01/15/2024 06:55:59 PM (3 years ago)
Author:
swissspidy
Message:

Upgrade/Install: Fix JavaScript localization on install page.

Blocks registration causes scripts to be initialized and localized very early, before the current locale has been properly set on the installation page.

This changes determine_locale() so that the locale chosen during installation is recognized and loaded earlier, ensuring proper script localization.

Props sabernhardt, NekoJonez, jornp, costdev.
Fixes #58696

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/install.php

    r57239 r57286  
    330330$language = '';
    331331if ( ! empty( $_REQUEST['language'] ) ) {
    332         $language = preg_replace( '/[^a-zA-Z0-9_]/', '', $_REQUEST['language'] );
     332        $language = sanitize_locale_name( $_REQUEST['language'] );
    333333} elseif ( isset( $GLOBALS['wp_local_package'] ) ) {
    334334        $language = $GLOBALS['wp_local_package'];
  • trunk/src/wp-includes/l10n.php

    r57233 r57286  
    151151        ) {
    152152                $determined_locale = get_user_locale();
     153        } elseif (
     154                ( ! empty( $_REQUEST['language'] ) || isset( $GLOBALS['wp_local_package'] ) )
     155                && wp_installing()
     156        ) {
     157                if ( ! empty( $_REQUEST['language'] ) ) {
     158                        $determined_locale = sanitize_locale_name( $_REQUEST['language'] );
     159                } else {
     160                        $determined_locale = $GLOBALS['wp_local_package'];
     161                }
    153162        }
    154163
  • trunk/tests/phpunit/tests/l10n/determineLocale.php

    r56559 r57286  
    2121
    2222        public function tear_down() {
    23                 unset( $_SERVER['CONTENT_TYPE'], $_GET['_locale'], $_COOKIE['wp_lang'], $GLOBALS['pagenow'] );
     23                unset(
     24                        $_SERVER['CONTENT_TYPE'],
     25                        $_GET['_locale'],
     26                        $_COOKIE['wp_lang'],
     27                        $GLOBALS['pagenow'],
     28                        $GLOBALS['wp_local_package'],
     29                        $_REQUEST['language']
     30                );
     31                wp_installing( false );
    2432
    2533                parent::tear_down();
    … …  
    274282                $this->assertSame( 'siteLocale', determine_locale() );
    275283        }
     284
     285        public function test_language_param_not_installing() {
     286                $_REQUEST['language'] = 'de_DE';
     287                $this->assertSame( 'en_US', determine_locale() );
     288        }
     289
     290        public function test_language_param_installing() {
     291                $_REQUEST['language'] = 'de_DE';
     292                wp_installing( true );
     293                $this->assertSame( 'de_DE', determine_locale() );
     294        }
     295
     296        public function test_language_param_installing_incorrect_string() {
     297                $_REQUEST['language'] = '####';  // Something sanitize_locale_name() strips away.
     298                wp_installing( true );
     299                $this->assertSame( 'en_US', determine_locale() );
     300        }
     301
     302        public function test_wp_local_package_global_not_installing() {
     303                $_REQUEST['language'] = 'de_DE';
     304                $this->assertSame( 'en_US', determine_locale() );
     305        }
     306        public function test_wp_local_package_global_installing() {
     307                $_REQUEST['language'] = 'de_DE';
     308                wp_installing( true );
     309                $this->assertSame( 'de_DE', determine_locale() );
     310        }
    276311}
Note: See TracChangeset for help on using the changeset viewer.