Make WordPress Core

Ticket #28577: 28577.4.patch

File 28577.4.patch, 3.3 KB (added by johnbillion, 10 years ago)
  • src/wp-admin/includes/upgrade.php

     
    21602160endif;
    21612161
    21622162function wp_install_language_form( $body ) {
     2163
    21632164        echo "<fieldset>\n";
    21642165        echo "<legend class='screen-reader-text'>Select a default language</legend>\n";
    21652166        echo '<input type="radio" checked="checked" class="screen-reader-input" name="language" id="language_default" value="">';
    21662167        echo '<label for="language_default">English (United States)</label>';
    21672168        echo "\n";
    21682169
    2169         if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {
     2170        $shown = array(
     2171                'en_US' => true
     2172        );
     2173
     2174        if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && !isset( $shown[WPLANG] ) ) {
    21702175                if ( isset( $body['languages'][WPLANG] ) ) {
     2176                        $shown[WPLANG] = true;
    21712177                        $language = $body['languages'][WPLANG];
    21722178                        echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">';
    21732179                        echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n";
    21742180                }
    21752181        }
    21762182
     2183        $top_accepted = false;
     2184        foreach ( wp_get_browser_accepted_languages() as $accepted_language ) {
     2185
     2186                if ( isset( $shown[$accepted_language] ) ) {
     2187                        continue;
     2188                }
     2189                if ( isset( $body['languages'][$accepted_language] ) ) {
     2190                        $shown[$accepted_language] = true;
     2191                        $language = $body['languages'][$accepted_language];
     2192                        echo '<input type="radio" name="language" ' . checked( $top_accepted, false, false ) . 'class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_accepted_' . esc_attr( $language['language'] ) . '" value="' . esc_attr( $language['language'] ) . '">';
     2193                        echo '<label for="language_accepted_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n";
     2194                }
     2195                $top_accepted = $accepted_language;
     2196
     2197        }
     2198
    21772199        foreach ( $body['languages'] as $language ) {
     2200                if ( isset( $shown[$language['language']] ) ) {
     2201                        continue;
     2202                }
    21782203                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'] ) . '">';
    21792204                echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n";
    21802205        }
     
    21822207        echo '<p class="step"><input type="submit" class="button button-primary button-hero" value="&raquo;" /></p>';
    21832208}
    21842209
     2210function wp_get_browser_accepted_languages() {
     2211        if ( empty( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
     2212                return array();
     2213        }
     2214
     2215        $langs = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
     2216        $codes = array();
     2217
     2218        foreach ( $langs as $lang ) {
     2219                $lang = str_replace( '-', '_', trim( $lang ) );
     2220                if ( preg_match( '#^([^;]+);q=(0\.[0-9]{1,3})#', $lang, $m ) ) {
     2221                        $lang = $m[1];
     2222                        $codes[$lang] = floatval( $m[2] );
     2223                } else {
     2224                        $codes[$lang] = 1.0;
     2225                }
     2226        }
     2227
     2228        arsort( $codes );
     2229        $accepted = array_keys( $codes );
     2230        return $accepted;
     2231
     2232}
     2233
    21852234/**
    2186  * @todo rename, move
     2235 * Get available languages from translations API
     2236 *
     2237 * @return boolean|array
    21872238 */
    21882239function wp_get_available_translations() {
    21892240        $url = 'http://api.wordpress.org/translations/core/1.0/';