Make WordPress Core


Ignore:
Timestamp:
07/05/2014 05:13:05 AM (10 years ago)
Author:
nacin
Message:

Bring the language chooser to setup-config.php.

see #28577.

File:
1 edited

Legend:

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

    r28984 r29006  
    4545
    4646/**
    47  * @todo rename, move
    48  */
    49 function wp_get_available_translations() {
    50     $url = 'http://api.wordpress.org/translations/core/1.0/';
    51     if ( wp_http_supports( array( 'ssl' ) ) ) {
    52         $url = set_url_scheme( $url, 'https' );
    53     }
    54 
    55     $options = array(
    56         'timeout' => 3,
    57         'body' => array( 'version' => $GLOBALS['wp_version'] ),
    58     );
    59 
    60     $response = wp_remote_post( $url, $options );
    61     $body = wp_remote_retrieve_body( $response );
    62     if ( $body && $body = json_decode( $body, true ) ) {
    63         $languages = array();
    64         // Key the language array with the language code
    65         foreach ( $body['languages'] as $language ) {
    66             $languages[$language['language']] = $language;
    67         }
    68         $body['languages'] = $languages;
    69         return $body;
    70     }
    71     return false;
    72 }
    73 
    74 /**
    7547 * Display install header.
    7648 *
     
    172144    </table>
    173145    <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
    174     <input type="hidden" name="language" value="<?php echo isset( $_POST['language'] ) ? esc_attr( $_POST['language'] ) : ''; ?>" />
     146    <input type="hidden" name="language" value="<?php echo isset( $_REQUEST['language'] ) ? esc_attr( $_REQUEST['language'] ) : ''; ?>" />
    175147</form>
    176148<?php
     
    207179switch($step) {
    208180    case 0: // Step 0
    209         $body = wp_get_available_translations();
    210         if ( $body ) {
     181
     182        if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) {
    211183            display_header( 'language-chooser' );
    212             echo '<form id="setup" method="post" action="install.php?step=1">';
    213             echo "<fieldset>\n";
    214             echo "<legend class='screen-reader-text'>Select a default language</legend>\n";
    215             echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">';
    216             echo '<label for="language_default">English (United States)</label>';
    217             echo "\n";
    218 
    219             if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
    220                 if ( isset( $body['languages'][WPLANG] ) ) {
    221                     $language = $body['languages'][WPLANG];
    222                     echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">';
    223                     echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n";
    224                 }
    225             }
    226 
    227             foreach ( $body['languages'] as $language ) {
    228                 echo '<input type="radio" name="language" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_'. esc_attr( $language['language'] ) .'" value="' . esc_attr( $language['language'] ) . '">';
    229                 echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n";
    230             }
    231             echo "</fieldset>\n";
    232             echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
     184            echo '<form id="setup" method="post" action="?step=1">';
     185            wp_install_language_form( $body );
    233186            echo '</form>';
    234187            break;
    235188        }
     189
    236190        // Deliberately fall through if we can't reach the translations API.
    237191
    238192    case 1: // Step 1, direct link or from language chooser.
    239         if ( ! empty( $_POST['language'] ) ) {
    240             $body = wp_get_available_translations();
    241             $loading_language = false;
    242             if ( $body ) {
    243                 foreach ( $body['languages'] as $language ) {
    244                     if ( $language['language'] === $_POST['language'] ) {
    245                         $loading_language = $_POST['language'];
    246                         break;
    247                     }
    248                 }
    249             }
    250             if ( ! empty( $loading_language ) ) {
    251                 require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    252                 $skin = new Automatic_Upgrader_Skin;
    253                 $upgrader = new Language_Pack_Upgrader( $skin );
    254                 $options = array( 'clear_update_cache' => false );
    255                 $language['type'] = 'core';
    256                 $language = (object) $language;
    257                 /**
    258                  * @todo failures (such as non-direct FS)
    259                  */
    260                 $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) );
    261                 load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" );
    262                 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" );
     193        if ( ! empty( $_REQUEST['language'] ) ) {
     194            $loaded_language = wp_install_download_language_pack( $_REQUEST['language'] );
     195            if ( $loaded_language ) {
     196                wp_install_load_language( $loaded_language );
    263197            }
    264198        }
     
    276210        break;
    277211    case 2:
    278         $loading_language = '';
    279         if ( ! empty( $_POST['language'] ) ) {
    280             $available_languages = get_available_languages();
    281             if ( in_array( $_POST['language'], $available_languages ) ) {
    282                 $loading_language = $_POST['language'];
    283                 load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" );
    284                 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" );
    285             }
    286         }
     212        $loaded_language = wp_install_load_language( $_REQUEST['language'] );
    287213
    288214        if ( ! empty( $wpdb->error ) )
     
    322248        if ( $error === false ) {
    323249            $wpdb->show_errors();
    324             $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loading_language );
     250            $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loaded_language );
    325251?>
    326252
Note: See TracChangeset for help on using the changeset viewer.