Changeset 29018 for trunk/src/wp-admin/includes/upgrade.php
- Timestamp:
- 07/07/2014 09:48:50 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/upgrade.php
r29016 r29018 2160 2160 endif; 2161 2161 2162 function wp_install_language_form( $ body) {2162 function wp_install_language_form( $languages ) { 2163 2163 echo "<fieldset>\n"; 2164 2164 echo "<legend class='screen-reader-text'>Select a default language</legend>\n"; … … 2168 2168 2169 2169 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 ]; 2172 2172 echo '<input type="radio" name="language" checked="checked" class="' . esc_attr( $language['language'] ) . ' screen-reader-input" id="language_wplang" value="' . esc_attr( $language['language'] ) . '">'; 2173 2173 echo '<label for="language_wplang">' . esc_html( $language['native_name'] ) . "</label>\n"; … … 2175 2175 } 2176 2176 2177 foreach ( $ body['languages']as $language ) {2177 foreach ( $languages as $language ) { 2178 2178 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'] ) . '">'; 2179 2179 echo '<label for="language_' . esc_attr( $language['language'] ) . '">' . esc_html( $language['native_name'] ) . "</label>\n"; … … 2184 2184 2185 2185 /** 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 */ 2192 function wp_get_available_translations_from_api() { 2189 2193 $url = 'http://api.wordpress.org/translations/core/1.0/'; 2190 2194 if ( wp_http_supports( array( 'ssl' ) ) ) { … … 2200 2204 $body = wp_remote_retrieve_body( $response ); 2201 2205 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; 2209 2212 } 2210 2213 return false; … … 2212 2215 2213 2216 /** 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 */ 2225 function 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 ) { 2239 2234 return false; 2240 2235 } 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; 2242 2247 2243 2248 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 2244 2249 $skin = new Automatic_Upgrader_Skin; 2245 2250 $upgrader = new Language_Pack_Upgrader( $skin ); 2246 $ language->type = 'core';2251 $translation->type = 'core'; 2247 2252 /** 2248 2253 * @todo failures (such as non-direct FS) 2249 2254 */ 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 */ 2268 function 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 }
Note: See TracChangeset
for help on using the changeset viewer.