WordPress.org

Make WordPress Core

Changeset 29018


Ignore:
Timestamp:
07/07/14 21:48:50 (3 years ago)
Author:
nacin
Message:

Language on install: Docs and naming cleanups. see #28577.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r29016 r29018  
    21602160endif; 
    21612161 
    2162 function wp_install_language_form( $body ) { 
     2162function wp_install_language_form( $languages ) { 
    21632163    echo "<fieldset>\n"; 
    21642164    echo "<legend class='screen-reader-text'>Select a default language</legend>\n"; 
     
    21682168 
    21692169    if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) { 
    2170         if ( isset( $body['languages'][WPLANG] ) ) { 
    2171             $language = $body['languages'][WPLANG]; 
     2170        if ( isset( $languages[ WPLANG ] ) ) { 
     2171            $language = $languages[ WPLANG ]; 
    21722172            echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">'; 
    21732173            echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n"; 
     
    21752175    } 
    21762176 
    2177     foreach ( $body['languages'] as $language ) { 
     2177    foreach ( $languages as $language ) { 
    21782178        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'] ) . '">'; 
    21792179        echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n"; 
     
    21842184 
    21852185/** 
    2186  * @todo rename, move 
    2187  */ 
    2188 function wp_get_available_translations() { 
     2186 * Gets available translations from the WordPress.org API. 
     2187 * 
     2188 * @since 4.0.0 
     2189 * 
     2190 * @return array Array of translations, each an array of data. 
     2191 */ 
     2192function wp_get_available_translations_from_api() { 
    21892193    $url = 'http://api.wordpress.org/translations/core/1.0/'; 
    21902194    if ( wp_http_supports( array( 'ssl' ) ) ) { 
     
    22002204    $body = wp_remote_retrieve_body( $response ); 
    22012205    if ( $body && $body = json_decode( $body, true ) ) { 
    2202         $languages = array(); 
    2203         // Key the language array with the language code 
    2204         foreach ( $body['languages'] as $language ) { 
    2205             $languages[$language['language']] = $language; 
    2206         } 
    2207         $body['languages'] = $languages; 
    2208         return $body; 
     2206        $translations = array(); 
     2207        // Key the array with the language code for now 
     2208        foreach ( $body['translations'] as $translation ) { 
     2209            $translations[ $translation['language'] ] = $translation; 
     2210        } 
     2211        return $translations; 
    22092212    } 
    22102213    return false; 
     
    22122215 
    22132216/** 
    2214  * [wp_install_download_language_pack description] 
    2215  *  
    2216  * @param  string $lang [description] 
    2217  * @return string|false [description] 
    2218  */ 
    2219 function wp_install_download_language_pack( $lang ) { 
    2220     // Check if the language is already installed. 
    2221     $available_languages = get_available_languages(); 
    2222     if ( in_array( $lang, $available_languages ) ) { 
    2223         return $lang; 
    2224     } 
    2225  
    2226     // Confirm the language is one we can download. 
    2227     $body = wp_get_available_translations(); 
    2228     $loading_language = false; 
    2229     if ( $body ) { 
    2230         foreach ( $body['languages'] as $language ) { 
    2231             if ( $language['language'] === $lang ) { 
    2232                 $loading_language = $lang; 
    2233                 break; 
    2234             } 
    2235         } 
    2236     } 
    2237  
    2238     if ( ! $loading_language ) { 
     2217 * Downloads a language pack. 
     2218 * 
     2219 * @since 4.0.0 
     2220 * 
     2221 * @param string $download Language code to download. 
     2222 * @return string|false Returns the language code if successfully downloaded 
     2223 *                      (or already installed), or false on failure. 
     2224 */ 
     2225function wp_install_download_language_pack( $download ) { 
     2226    // Check if the translation is already installed. 
     2227    if ( in_array( $download, get_available_languages() ) ) { 
     2228        return $download; 
     2229    } 
     2230 
     2231    // Confirm the translation is one we can download. 
     2232    $translations = wp_get_available_translations_from_api(); 
     2233    if ( ! $translations ) { 
    22392234        return false; 
    22402235    } 
    2241     $language = (object) $language; 
     2236    foreach ( $translations as $translation ) { 
     2237        if ( $translation['language'] === $download ) { 
     2238            $translation_to_load = true; 
     2239            break; 
     2240        } 
     2241    } 
     2242 
     2243    if ( empty( $translation_to_load ) ) { 
     2244        return false; 
     2245    } 
     2246    $translation = (object) $translation; 
    22422247 
    22432248    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
    22442249    $skin = new Automatic_Upgrader_Skin; 
    22452250    $upgrader = new Language_Pack_Upgrader( $skin ); 
    2246     $language->type = 'core'; 
     2251    $translation->type = 'core'; 
    22472252    /** 
    22482253     * @todo failures (such as non-direct FS) 
    22492254     */ 
    2250     $upgrader->upgrade( $language, array( 'clear_update_cache' => false ) ); 
    2251     return $language->language; 
    2252 } 
    2253  
    2254 function wp_install_load_language( $request ) { 
    2255     $loading_language = ''; 
    2256     if ( ! empty( $request ) ) { 
    2257         $available_languages = get_available_languages(); 
    2258         if ( in_array( $request, $available_languages ) ) { 
    2259             $loading_language = $request; 
    2260         } 
    2261     } 
    2262  
    2263     if ( $loading_language ) { 
    2264         load_textdomain( 'default', WP_LANG_DIR . "/{$loading_language}.mo" ); 
    2265         load_textdomain( 'default', WP_LANG_DIR . "/admin-{$loading_language}.mo" ); 
    2266         return $loading_language; 
    2267     } 
    2268  
    2269     return false; 
    2270 } 
     2255    $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) ); 
     2256    return $translation->language; 
     2257} 
     2258 
     2259/** 
     2260 * Load a translation during the install process. 
     2261 * 
     2262 * @since 4.0.0 
     2263 * 
     2264 * @param string $translation Translation to load. 
     2265 * @return string|false Returns the language code if successfully loaded, 
     2266 *                      or false on failure. 
     2267 */ 
     2268function wp_install_load_language( $translation ) { 
     2269    if ( ! empty( $translation ) ) { 
     2270        if ( in_array( $translation, get_available_languages() ) ) { 
     2271            $translation_to_load = $translation; 
     2272        } 
     2273    } 
     2274 
     2275    if ( empty( $translation_to_load ) ) { 
     2276        return false; 
     2277    } 
     2278 
     2279    load_textdomain( 'default', WP_LANG_DIR . "/{$translation_to_load}.mo" ); 
     2280    load_textdomain( 'default', WP_LANG_DIR . "/admin-{$translation_to_load}.mo" ); 
     2281    return $translation_to_load; 
     2282} 
  • trunk/src/wp-admin/install.php

    r29006 r29018  
    180180    case 0: // Step 0 
    181181 
    182         if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { 
     182        if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations_from_api() ) ) { 
    183183            display_header( 'language-chooser' ); 
    184184            echo '<form id="setup" method="post" action="?step=1">'; 
    185             wp_install_language_form( $body ); 
     185            wp_install_language_form( $languages ); 
    186186            echo '</form>'; 
    187187            break; 
  • trunk/src/wp-admin/setup-config.php

    r29015 r29018  
    8787    case -1: 
    8888 
    89         if ( empty( $_GET['language'] ) && ( $body = wp_get_available_translations() ) ) { 
     89        if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations_from_api() ) ) { 
    9090            setup_config_display_header( 'language-chooser' ); 
    9191            echo '<form id="setup" method="post" action="?step=0">'; 
    92             wp_install_language_form( $body ); 
     92            wp_install_language_form( $languages ); 
    9393            echo '</form>'; 
    9494            break; 
  • trunk/src/wp-includes/version.php

    r29010 r29018  
    55 * @global string $wp_version 
    66 */ 
    7 $wp_version = '4.0-alpha-28611-src'; 
     7$wp_version = '4.0-alpha-29018-src'; 
    88 
    99/** 
Note: See TracChangeset for help on using the changeset viewer.