Make WordPress Core

Changeset 28774


Ignore:
Timestamp:
06/18/2014 07:57:21 PM (10 years ago)
Author:
nacin
Message:

Allow a language to be chosen before installing WordPress. First pass.

  • Checks WordPress.org for available languages.
  • In get_locale(), starts using the WPLANG option that has existed in multisite since the MU days.
  • Adds new argument to wp_install() for setting WPLANG.

see #28577.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r27855 r28774  
    312312
    313313}
     314
     315.language-chooser select {
     316    margin: 1px;
     317    padding: 8px;
     318    width: 100%;
     319    display: block;
     320    border: 1px solid #ddd;
     321    -webkit-border-radius: 0;
     322    border-radius: 0; /* Reset mobile webkit's default element styling */
     323    -webkit-transition: .05s border-color ease-in-out;
     324    transition: .05s border-color ease-in-out;
     325    outline: 0;
     326    -webkit-box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
     327    box-shadow: inset 0 1px 2px rgba(0,0,0,0.07);
     328    background-color: #fff;
     329    color: #333;
     330    font-size: 16px;
     331    font-family: inherit;
     332    font-weight: inherit;
     333}
     334
     335.language-chooser select:focus {
     336    border-color: #5b9dd9;
     337    -webkit-box-shadow: 0 0 2px rgba(30,140,190,0.8);
     338    box-shadow: 0 0 2px rgba(30,140,190,0.8);
     339}
     340
     341.wp-core-ui .language-chooser .button.button-hero {
     342    font-size: 30px;
     343    line-height: 30px;
     344}
     345
     346.language-chooser p {
     347    text-align: right;
     348}
  • trunk/src/wp-admin/includes/upgrade.php

    r28712 r28774  
    3333 * @param null $deprecated Optional. Not used.
    3434 * @param string $user_password Optional. User's chosen password. Will default to a random password.
     35 * @param string $language Optional. Language chosen.
    3536 * @return array Array keys 'url', 'user_id', 'password', 'password_message'.
    3637 */
    37 function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '' ) {
     38function wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) {
    3839    if ( !empty( $deprecated ) )
    3940        _deprecated_argument( __FUNCTION__, '2.6' );
     
    4849    update_option('admin_email', $user_email);
    4950    update_option('blog_public', $public);
     51
     52    if ( $language ) {
     53        update_option( 'WPLANG', $language );
     54    }
    5055
    5156    $guessurl = wp_guess_url();
  • trunk/src/wp-admin/install.php

    r28759 r28774  
    4545
    4646/**
     47 * @todo rename, move
     48 */
     49function 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        return $body;
     64    }
     65    return false;
     66}
     67
     68/**
    4769 * Display install header.
    4870 *
     
    137159    </table>
    138160    <p class="step"><input type="submit" name="Submit" value="<?php esc_attr_e( 'Install WordPress' ); ?>" class="button button-large" /></p>
     161    <input type="hidden" name="language" value="<?php echo isset( $_POST['language'] ) ? esc_attr( $_POST['language'] ) : ''; ?>" />
    139162</form>
    140163<?php
     
    170193
    171194switch($step) {
    172     case 0: // Step 1
    173     case 1: // Step 1, direct link.
    174       display_header();
     195    case 0: // Step 0
     196        if ( $body = wp_get_available_translations() ) {
     197            display_header();
     198
     199            echo '<form id="setup" method="post" action="install.php?step=1">';
     200            echo '<div class="language-chooser">';
     201            echo '<select name="language" id="language-chooser" size="15">';
     202            echo '<option selected="selected" value="">English (United States)</option>';
     203            foreach ( $body['languages'] as $language ) {
     204                echo '<option value="' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n";
     205            }
     206            echo "</select>\n";
     207            echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
     208            echo '</div>';
     209            echo '</form>';
     210            break;
     211        }
     212        // Deliberately fall through if we can't reach the translations API.
     213
     214    case 1: // Step 1, direct link or from language chooser.
     215        if ( ! empty( $_POST['language'] ) ) {
     216            $body = wp_get_available_translations();
     217            foreach ( $body['languages'] as $language ) {
     218                if ( $language['language'] === $_POST['language'] ) {
     219                    $loading_language = $_POST['language'];
     220                    break;
     221                }
     222            }
     223            if ( ! empty( $loading_language ) ) {
     224                require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     225                $skin = new Automatic_Upgrader_Skin;
     226                $upgrader = new Language_Pack_Upgrader( $skin );
     227                $options = array( 'clear_update_cache' => false );
     228                $language['type'] = 'core';
     229                $language = (object) $language;
     230                /**
     231                 * @todo failures (such as non-direct FS)
     232                 */
     233                $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) );
     234                load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" );
     235                load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" );
     236            }
     237        }
     238
     239        display_header();
    175240?>
    176241<h1><?php _ex( 'Welcome', 'Howdy' ); ?></h1>
     
    184249        break;
    185250    case 2:
     251        $loading_language = '';
     252        if ( ! empty( $_POST['language'] ) ) {
     253            $available_languages = get_available_languages();
     254            if ( isset( $available_languages[ $_POST['language'] ] ) ) {
     255                $loading_language = $_POST['language'];
     256                load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" );
     257                load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" );
     258            }
     259        }
     260
    186261        if ( ! empty( $wpdb->error ) )
    187262            wp_die( $wpdb->error->get_error_message() );
     
    220295        if ( $error === false ) {
    221296            $wpdb->show_errors();
    222             $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ) );
     297            $result = wp_install( $weblog_title, $user_name, $admin_email, $public, '', wp_slash( $admin_password ), $loading_language );
    223298?>
    224299
     
    251326if ( !wp_is_mobile() ) {
    252327?>
    253 <script type="text/javascript">var t = document.getElementById('weblog_title'); if (t){ t.focus(); }</script>
     328<script type="text/javascript">var t = document.getElementById('weblog_title') || document.getElementById('language-chooser'); if (t){ t.focus(); }</script>
    254329<?php } ?>
    255330<?php wp_print_scripts( 'user-profile' ); ?>
  • trunk/src/wp-includes/l10n.php

    r28083 r28774  
    2727    global $locale;
    2828
    29     if ( isset( $locale ) )
     29    if ( isset( $locale ) ) {
    3030        /**
    3131         * Filter WordPress install's locale ID.
     
    3636         */
    3737        return apply_filters( 'locale', $locale );
     38    }
    3839
    3940    // WPLANG is defined in wp-config.
     
    4950        if ( $ms_locale !== false )
    5051            $locale = $ms_locale;
     52    } elseif ( ! defined( 'WP_INSTALLING' ) ) {
     53        $db_locale = get_option( 'WPLANG' );
     54        if ( $db_locale ) {
     55            $locale = $db_locale;
     56        }
    5157    }
    5258
Note: See TracChangeset for help on using the changeset viewer.