Ticket #15677: 15677.12.patch
File 15677.12.patch, 26.9 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/translation-install.php
1 <?php 2 /** 3 * WordPress Translation Install Administration API 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 10 /** 11 * Retrieve translations from WordPress Translation API. 12 * 13 * @since 4.0.0 14 * 15 * @param string $type Type of translations. Accepts 'plugins', 'themes', 'core'. 16 * @param array|object $args Translation API arguments. Optional. 17 * @return object|WP_Error On success an object of translations, WP_Error on failure. 18 */ 19 function translations_api( $type, $args = null ) { 20 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version 21 22 if ( ! in_array( $type, array( 'plugins', 'themes', 'core' ) ) ) { 23 return new WP_Error( 'invalid_type', __( 'Invalid translation type.' ) ); 24 } 25 26 /** 27 * Allows a plugin to override the WordPress.org Translation Install API entirely. 28 * 29 * @since 4.0.0 30 * 31 * @param bool|array $result The result object. Default false. 32 * @param string $type The type of translations being requested. 33 * @param object $args Translation API arguments. 34 */ 35 $res = apply_filters( 'translations_api', false, $type, $args ); 36 37 if ( false === $res ) { 38 $url = $http_url = 'http://api.wordpress.org/translations/' . $type . '/1.0/'; 39 if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { 40 $url = set_url_scheme( $url, 'https' ); 41 } 42 43 $options = array( 44 'timeout' => 3, 45 'body' => array( 46 'wp_version' => $wp_version, 47 'locale' => get_locale(), 48 'version' => $args['version'], // Version of plugin, theme or core 49 ), 50 ); 51 52 if ( 'core' !== $type ) { 53 $options['body']['slug'] = $args['slug']; // Plugin or theme slug 54 } 55 56 $request = wp_remote_post( $url, $options ); 57 58 if ( $ssl && is_wp_error( $request ) ) { 59 trigger_error( __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ) . ' ' . __( '(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)' ), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE ); 60 61 $request = wp_remote_post( $http_url, $options ); 62 } 63 64 if ( is_wp_error( $request ) ) { 65 $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() ); 66 } else { 67 $res = json_decode( wp_remote_retrieve_body( $request ), true ); 68 if ( ! is_object( $res ) && ! is_array( $res ) ) { 69 $res = new WP_Error( 'translations_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) ); 70 } 71 } 72 } 73 74 /** 75 * Filter the Translation Install API response results. 76 * 77 * @since 4.0.0 78 * 79 * @param object|WP_Error $res Response object or WP_Error. 80 * @param string $type The type of translations being requested. 81 * @param object $args Translation API arguments. 82 */ 83 return apply_filters( 'translations_api_result', $res, $type, $args ); 84 } 85 86 /** 87 * Get available translations from the WordPress.org API. 88 * 89 * @since 4.0.0 90 * 91 * @see translations_api() 92 * 93 * @return array Array of translations, each an array of data. If the API response results 94 * in an error, an empty array will be returned. 95 */ 96 function wp_get_available_translations() { 97 if ( ! defined( 'WP_INSTALLING' ) && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { 98 return $translations; 99 } 100 101 include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version 102 103 $api = translations_api( 'core', array( 'version' => $wp_version ) ); 104 105 if ( is_wp_error( $api ) || empty( $api['translations'] ) ) { 106 return array(); 107 } 108 109 $translations = array(); 110 // Key the array with the language code for now 111 foreach ( $api['translations'] as $translation ) { 112 $translations[ $translation['language'] ] = $translation; 113 } 114 115 if ( ! defined( 'WP_INSTALLING' ) ) { 116 set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS ); 117 } 118 119 return $translations; 120 } 121 122 /** 123 * Output the select form for the language selection on the installation screen. 124 * 125 * @since 4.0.0 126 * 127 * @param array $languages Array of available languages (populated via the Translation API). 128 */ 129 function wp_install_language_form( $languages ) { 130 $installed_languages = get_available_languages(); 131 132 echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n"; 133 echo "<select size='14' name='language' id='language'>\n"; 134 echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>'; 135 echo "\n"; 136 137 if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) { 138 if ( isset( $languages[ WPLANG ] ) ) { 139 $language = $languages[ WPLANG ]; 140 echo '<option value="' . esc_attr( $language['language'] ) . '" lang="' . esc_attr( $language['iso'][1] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n"; 141 unset( $languages[ WPLANG ] ); 142 } 143 } 144 145 foreach ( $languages as $language ) { 146 printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n", 147 esc_attr( $language['language'] ), 148 esc_attr( $language['iso'][1] ), 149 esc_attr( $language['strings']['continue'] ), 150 in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '', 151 esc_html( $language['native_name'] ) ); 152 } 153 echo "</select>\n"; 154 echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>'; 155 } 156 157 /** 158 * Download a language pack. 159 * 160 * @since 4.0.0 161 * 162 * @see wp_get_available_translations() 163 * 164 * @param string $download Language code to download. 165 * @return string|bool Returns the language code if successfully downloaded 166 * (or already installed), or false on failure. 167 */ 168 function wp_download_language_pack( $download ) { 169 // Check if the translation is already installed. 170 if ( in_array( $download, get_available_languages() ) ) { 171 return $download; 172 } 173 174 if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { 175 return false; 176 } 177 178 // Confirm the translation is one we can download. 179 $translations = wp_get_available_translations(); 180 if ( ! $translations ) { 181 return false; 182 } 183 foreach ( $translations as $translation ) { 184 if ( $translation['language'] === $download ) { 185 $translation_to_load = true; 186 break; 187 } 188 } 189 190 if ( empty( $translation_to_load ) ) { 191 return false; 192 } 193 $translation = (object) $translation; 194 195 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 196 $skin = new Automatic_Upgrader_Skin; 197 $upgrader = new Language_Pack_Upgrader( $skin ); 198 $translation->type = 'core'; 199 /** 200 * @todo failures (such as non-direct FS) 201 */ 202 $result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) ); 203 return $translation->language; 204 } -
src/wp-admin/includes/upgrade.php
1419 1419 */ 1420 1420 function maybe_create_table($table_name, $create_ddl) { 1421 1421 global $wpdb; 1422 1422 1423 1423 $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $table_name ) ); 1424 1424 1425 1425 if ( $wpdb->get_var( $query ) == $table_name ) { … … 2192 2192 dbDelta( $ms_queries ); 2193 2193 } 2194 2194 endif; 2195 2196 /**2197 * Output the input fields for the language selection form on the installation screen.2198 *2199 * @since 4.0.02200 *2201 * @see wp_get_available_translations_from_api()2202 *2203 * @param array $languages Array of available languages (populated via the Translations API).2204 */2205 function wp_install_language_form( $languages ) {2206 $installed_languages = get_available_languages();2207 2208 echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";2209 echo "<select size='14' name='language' id='language'>\n";2210 echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';2211 echo "\n";2212 2213 if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && ( 'en_US' !== WPLANG ) ) {2214 if ( isset( $languages[ WPLANG ] ) ) {2215 $language = $languages[ WPLANG ];2216 echo '<option value="' . esc_attr( $language['language'] ) . '" lang="' . esc_attr( $language['iso'][1] ) . '">' . esc_html( $language['native_name'] ) . "</option>\n";2217 }2218 }2219 2220 foreach ( $languages as $language ) {2221 printf( '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",2222 esc_attr( $language['language'] ),2223 esc_attr( $language['iso'][1] ),2224 esc_attr( $language['strings']['continue'] ),2225 in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',2226 esc_html( $language['native_name'] ) );2227 }2228 echo "</select>\n";2229 echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';2230 }2231 2232 /**2233 * Get available translations from the WordPress.org API.2234 *2235 * @since 4.0.02236 *2237 * @see wp_remote_post()2238 *2239 * @return array Array of translations, each an array of data.2240 */2241 function wp_get_available_translations_from_api() {2242 $url = 'http://api.wordpress.org/translations/core/1.0/';2243 if ( wp_http_supports( array( 'ssl' ) ) ) {2244 $url = set_url_scheme( $url, 'https' );2245 }2246 2247 $options = array(2248 'timeout' => 3,2249 'body' => array( 'version' => $GLOBALS['wp_version'] ),2250 );2251 2252 $response = wp_remote_post( $url, $options );2253 $body = wp_remote_retrieve_body( $response );2254 if ( $body && $body = json_decode( $body, true ) ) {2255 $translations = array();2256 // Key the array with the language code for now2257 foreach ( $body['translations'] as $translation ) {2258 $translations[ $translation['language'] ] = $translation;2259 }2260 return $translations;2261 }2262 return false;2263 }2264 2265 /**2266 * Download a language pack.2267 *2268 * @since 4.0.02269 *2270 * @see wp_get_available_translations_from_api()2271 *2272 * @param string $download Language code to download.2273 * @return string|bool Returns the language code if successfully downloaded2274 * (or already installed), or false on failure.2275 */2276 function wp_install_download_language_pack( $download ) {2277 // Check if the translation is already installed.2278 if ( in_array( $download, get_available_languages() ) ) {2279 return $download;2280 }2281 2282 // Confirm the translation is one we can download.2283 $translations = wp_get_available_translations_from_api();2284 if ( ! $translations ) {2285 return false;2286 }2287 foreach ( $translations as $translation ) {2288 if ( $translation['language'] === $download ) {2289 $translation_to_load = true;2290 break;2291 }2292 }2293 2294 if ( empty( $translation_to_load ) ) {2295 return false;2296 }2297 $translation = (object) $translation;2298 2299 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';2300 $skin = new Automatic_Upgrader_Skin;2301 $upgrader = new Language_Pack_Upgrader( $skin );2302 $translation->type = 'core';2303 /**2304 * @todo failures (such as non-direct FS)2305 */2306 $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );2307 return $translation->language;2308 }2309 2310 /**2311 * Load a translation during the install process.2312 *2313 * @since 4.0.02314 *2315 * @see load_textdomain()2316 *2317 * @param string $translation Translation to load.2318 * @return string|bool Returns the language code if successfully loaded,2319 * or false on failure.2320 */2321 function wp_install_load_language( $translation ) {2322 if ( ! empty( $translation ) ) {2323 if ( in_array( $translation, get_available_languages() ) ) {2324 $translation_to_load = $translation;2325 }2326 }2327 2328 if ( empty( $translation_to_load ) ) {2329 return false;2330 }2331 2332 unload_textdomain( 'default' ); // Start over.2333 load_textdomain( 'default', WP_LANG_DIR . "/{$translation_to_load}.mo" );2334 load_textdomain( 'default', WP_LANG_DIR . "/admin-{$translation_to_load}.mo" );2335 return $translation_to_load;2336 } -
src/wp-admin/install.php
38 38 /** Load WordPress Administration Upgrade API */ 39 39 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 40 40 41 /** Load WordPress Translation Install API */ 42 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 43 41 44 /** Load wpdb */ 42 45 require_once( ABSPATH . WPINC . '/wp-db.php' ); 43 46 … … 181 184 switch($step) { 182 185 case 0: // Step 0 183 186 184 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations _from_api() ) ) {187 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations() ) ) { 185 188 display_header( 'language-chooser' ); 186 189 echo '<form id="setup" method="post" action="?step=1">'; 187 190 wp_install_language_form( $languages ); … … 193 196 194 197 case 1: // Step 1, direct link or from language chooser. 195 198 if ( ! empty( $_REQUEST['language'] ) ) { 196 $loaded_language = wp_ install_download_language_pack( $_REQUEST['language'] );199 $loaded_language = wp_download_language_pack( $_REQUEST['language'] ); 197 200 if ( $loaded_language ) { 198 wp_ install_load_language( $loaded_language );201 wp_switch_default_textdomain( $loaded_language ); 199 202 } 200 203 } 201 204 … … 212 215 break; 213 216 case 2: 214 217 if ( !empty( $_REQUEST['language'] ) ) { 215 $loaded_language = wp_ install_load_language( $_REQUEST['language'] );218 $loaded_language = wp_switch_default_textdomain( $_REQUEST['language'] ); 216 219 } else { 217 220 $loaded_language = 'en_US'; 218 221 } -
src/wp-admin/network/settings.php
102 102 <input name="admin_email" type="email" id="admin_email" class="regular-text" value="<?php echo esc_attr( get_site_option( 'admin_email' ) ) ?>" /> 103 103 <p class="description"> 104 104 <?php _e( 'This email address will receive notifications. Registration and support emails will also come from this address.' ); ?> 105 </p> 105 </p> 106 106 </td> 107 107 </tr> 108 108 </table> … … 165 165 <?php echo esc_textarea( $limited_email_domains == '' ? '' : implode( "\n", (array) $limited_email_domains ) ); ?></textarea> 166 166 <p class="description"> 167 167 <?php _e( 'If you want to limit site registrations to certain domains. One domain per line.' ) ?> 168 </p> 168 </p> 169 169 </td> 170 170 </tr> 171 171 … … 231 231 <?php echo esc_textarea( get_site_option( 'first_comment' ) ) ?></textarea> 232 232 <p class="description"> 233 233 <?php _e( 'The first comment on a new site.' ) ?> 234 </p> 234 </p> 235 235 </td> 236 236 </tr> 237 237 <tr> … … 273 273 </tr> 274 274 </table> 275 275 276 <?php276 <?php 277 277 $languages = get_available_languages(); 278 278 if ( ! empty( $languages ) ) { 279 $lang = get_site_option( 'WPLANG' ); 280 ?> 281 <h3><?php _e( 'Language Settings' ); ?></h3> 282 <table class="form-table"> 279 ?> 280 <h3><?php _e( 'Language Settings' ); ?></h3> 281 <table class="form-table"> 283 282 <tr> 284 283 <th><label for="WPLANG"><?php _e( 'Default Language' ); ?></label></th> 285 284 <td> 286 <select name="WPLANG" id="WPLANG"> 287 <?php mu_dropdown_languages( $languages, get_site_option( 'WPLANG' ) ); ?> 288 </select> 285 <?php 286 $lang = get_site_option( 'WPLANG' ); 287 if ( ! in_array( $lang, $languages ) ) { 288 $lang = ''; 289 } 290 291 wp_dropdown_languages( array( 292 'name' => 'WPLANG', 293 'id' => 'WPLANG', 294 'selected' => $lang, 295 'languages' => $languages, 296 ) ); 297 ?> 289 298 </td> 290 299 </tr> 291 </table>292 <?php293 } // languages294 ?>300 </table> 301 <?php 302 } 303 ?> 295 304 296 305 <h3><?php _e( 'Menu Settings' ); ?></h3> 297 306 <table id="menu" class="form-table"> … … 324 333 </tr> 325 334 </table> 326 335 327 <?php 336 <?php 328 337 /** 329 338 * Fires at the end of the Network Settings form, before the submit button. 330 339 * -
src/wp-admin/options-general.php
302 302 </select></td> 303 303 </tr> 304 304 <?php do_settings_fields('general', 'default'); ?> 305 305 306 <?php 306 307 if ( $languages ) : 308 ?>307 $languages = get_available_languages(); 308 if ( ! empty( $languages ) ) { 309 ?> 309 310 <tr> 310 <th width="33%" scope="row"><label for="WPLANG"><?php _e( 'Site Language')?></label></th>311 <th width="33%" scope="row"><label for="WPLANG"><?php _e( 'Site Language' ); ?></label></th> 311 312 <td> 312 <?php wp_dropdown_languages( array( 313 <?php 314 $locale = get_locale(); 315 // Check if current locale is still installed. en_US will fail this test, but that's okay. 316 if ( ! in_array( $locale, $languages ) ) { 317 $locale = ''; 318 } 319 320 wp_dropdown_languages( array( 313 321 'name' => 'WPLANG', 314 322 'id' => 'WPLANG', 315 'selected' => get_option( 'WPLANG' ),323 'selected' => $locale, 316 324 'languages' => $languages, 317 ) ); ?> 325 ) ); 326 327 // Add note about deprecated WPLANG constant. 328 if ( defined( 'WPLANG' ) && ( '' !== WPLANG ) && $locale !== WPLANG && is_super_admin() ) { 329 ?> 330 <p class="description"> 331 <?php _e( '<strong>Note:</strong> The <code>WPLANG</code> constant in your <code>wp-config.php</code> file is deprecated.' ); ?> 332 </p> 333 <?php 334 } 335 ?> 318 336 </td> 319 337 </tr> 320 <?php321 endif; 338 <?php 339 } 322 340 ?> 323 341 </table> 324 342 -
src/wp-admin/options.php
151 151 $options = $whitelist_options[ $option_page ]; 152 152 } 153 153 154 // Handle custom date/time formats 154 // Handle custom date/time formats. 155 155 if ( 'general' == $option_page ) { 156 156 if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) ) 157 157 $_POST['date_format'] = $_POST['date_format_custom']; … … 180 180 } 181 181 update_option( $option, $value ); 182 182 } 183 184 // Switch translation in case WPLANG was changed. 185 $language = wp_unslash( trim( $_POST[ 'WPLANG' ] ) ); 186 if ( $language ) { 187 wp_switch_default_textdomain( $language ); 188 } else { 189 unload_textdomain( 'default' ); 190 } 183 191 } 184 192 185 193 /** -
src/wp-admin/setup-config.php
32 32 33 33 require( ABSPATH . 'wp-settings.php' ); 34 34 35 require( ABSPATH . 'wp-admin/includes/upgrade.php' ); 35 /** Load WordPress Administration Upgrade API */ 36 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 36 37 38 /** Load WordPress Translation Install API */ 39 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 40 37 41 nocache_headers(); 38 42 39 43 // Support wp-config-sample.php one level up, for the develop repo. … … 88 92 switch($step) { 89 93 case -1: 90 94 91 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations _from_api() ) ) {95 if ( empty( $_GET['language'] ) && ( $languages = wp_get_available_translations() ) ) { 92 96 setup_config_display_header( 'language-chooser' ); 93 97 echo '<form id="setup" method="post" action="?step=0">'; 94 98 wp_install_language_form( $languages ); … … 100 104 101 105 case 0: 102 106 if ( ! empty( $_REQUEST['language'] ) ) { 103 $loaded_language = wp_ install_download_language_pack( $_REQUEST['language'] );107 $loaded_language = wp_download_language_pack( $_REQUEST['language'] ); 104 108 if ( $loaded_language ) { 105 wp_ install_load_language( $loaded_language );109 wp_switch_default_textdomain( $loaded_language ); 106 110 } 107 111 } 108 112 … … 136 140 break; 137 141 138 142 case 1: 139 $loaded_language = wp_ install_load_language( $_REQUEST['language'] );143 $loaded_language = wp_switch_default_textdomain( $_REQUEST['language'] ); 140 144 setup_config_display_header(); 141 145 ?> 142 146 <form method="post" action="setup-config.php?step=2"> … … 176 180 break; 177 181 178 182 case 2: 179 $loaded_language = wp_ install_load_language( $_REQUEST['language'] );183 $loaded_language = wp_switch_default_textdomain( $_REQUEST['language'] ); 180 184 $dbname = trim( wp_unslash( $_POST[ 'dbname' ] ) ); 181 185 $uname = trim( wp_unslash( $_POST[ 'uname' ] ) ); 182 186 $pwd = trim( wp_unslash( $_POST[ 'pwd' ] ) ); -
src/wp-includes/l10n.php
24 24 * @return string The locale of the blog or from the 'locale' hook. 25 25 */ 26 26 function get_locale() { 27 global $locale ;27 global $locale, $wp_local_package; 28 28 29 29 if ( isset( $locale ) ) { 30 30 /** … … 38 38 } 39 39 40 40 // WPLANG is defined in wp-config. 41 if ( defined( 'WPLANG' ) ) 41 if ( defined( 'WPLANG' ) ) { 42 42 $locale = WPLANG; 43 } 43 44 45 if ( isset( $wp_local_package ) ) { 46 $locale = $wp_local_package; 47 } 48 44 49 // If multisite, check options. 45 50 if ( is_multisite() ) { 46 51 // Don't check blog option when installing. 47 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) 48 $ms_locale = get_site_option('WPLANG'); 52 if ( defined( 'WP_INSTALLING' ) || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { 53 $ms_locale = get_site_option( 'WPLANG' ); 54 } 49 55 50 if ( $ms_locale !== false ) 56 if ( $ms_locale !== false ) { 51 57 $locale = $ms_locale; 52 } elseif ( ! defined( 'WP_INSTALLING' ) ) { 58 } 59 } else { 53 60 $db_locale = get_option( 'WPLANG' ); 54 if ( $db_locale ) {61 if ( $db_locale !== false ) { 55 62 $locale = $db_locale; 56 63 } 57 64 } 58 65 59 if ( empty( $locale ) ) 66 if ( empty( $locale ) ) { 60 67 $locale = 'en_US'; 68 } 61 69 62 70 /** This filter is documented in wp-includes/l10n.php */ 63 71 return apply_filters( 'locale', $locale ); … … 523 531 * @see load_textdomain() 524 532 * 525 533 * @since 1.5.0 534 * 535 * @param string $locale Optional. Locale to load. Defaults to get_locale(). 526 536 */ 527 function load_default_textdomain() { 528 $locale = get_locale(); 537 function load_default_textdomain( $locale = null ) { 538 if ( null === $locale ) { 539 $locale = get_locale(); 540 } 529 541 530 load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" );542 $return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo" ); 531 543 532 544 if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) { 533 545 load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo" ); 534 return ;546 return $return; 535 547 } 536 548 537 549 if ( is_admin() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) … … 540 552 if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) 541 553 load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo" ); 542 554 555 return $return; 543 556 } 544 557 545 558 /** … … 818 831 } 819 832 820 833 /** 821 * Language selector. More to come.834 * Language selector. 822 835 * 823 836 * @since 4.0.0 824 837 * 825 838 * @see get_available_languages() 839 * @see wp_get_available_translations() 826 840 * 827 841 * @param array $args Optional arguments. Default empty array. 828 842 */ 829 843 function wp_dropdown_languages( $args = array() ) { 830 if ( isset( $args['languages'] ) ) { 831 $languages = $args['languages']; 832 } else { 833 $languages = get_available_languages(); 844 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); 845 846 $args = wp_parse_args( $args, array( 847 'id' => '', 848 'name' => '', 849 'languages' => array(), 850 'selected' => '' 851 ) ); 852 853 if ( empty( $args['languages'] ) ) { 854 return false; 834 855 } 835 856 857 $translations = wp_get_available_translations(); 858 859 /* 860 * $args['languages'] should only contain the locales. Find the locale in 861 * $translations to get the native name. Falls back to locale. 862 */ 863 $languages = array(); 864 foreach ( $args['languages'] as $locale ) { 865 if ( isset( $translations[ $locale ] ) ) { 866 $translation = $translations[ $locale ]; 867 $languages[] = $translation; 868 } else { 869 $languages[] = array( 870 'language' => $locale, 871 'native_name' => $locale, 872 'lang' => '', 873 ); 874 } 875 } 876 836 877 printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) ); 837 echo '<option value="">en_US</option>'; 878 879 // List installed languages. 880 echo '<option value="">English (United States)</option>'; 838 881 foreach ( $languages as $language ) { 839 $selected = selected( $language, $args['selected'], false ); 840 echo '<option value="' . esc_attr( $language ) .'"' . $selected . '>' . $language . '</option>'; 882 $selected = selected( $language['language'], $args['selected'], false ); 883 printf( 884 '<option value="%s" lang="%s"%s>%s</option>', 885 esc_attr( $language['language'] ), 886 esc_attr( $language['iso'][1] ), 887 $selected, 888 esc_html( $language['native_name'] ) 889 ); 841 890 } 891 842 892 echo '</select>'; 843 893 } 894 895 /** 896 * Switch translation for default translation. 897 * 898 * @since 4.0.0 899 * 900 * @see load_default_textdomain() 901 * 902 * @param string $translation Translation to load. 903 * string|bool Returns the language code if successfully loaded, 904 * or false on failure. 905 */ 906 function wp_switch_default_textdomain( $translation ) { 907 if ( ! empty( $translation ) ) { 908 if ( in_array( $translation, get_available_languages() ) ) { 909 $translation_to_load = $translation; 910 } 911 } 912 913 914 if ( empty( $translation_to_load ) ) { 915 return false; 916 } 917 918 if ( $translation_to_load === get_locale() ) { 919 return false; 920 } 921 922 unload_textdomain( 'default' ); // Start over. 923 $result = load_default_textdomain( $translation_to_load ); 924 925 if ( ! $result ) { 926 return false; 927 } 928 929 return $translation_to_load; 930 } -
wp-config-sample.php
62 62 $table_prefix = 'wp_'; 63 63 64 64 /** 65 * WordPress Localized Language, defaults to English.66 *67 * Change this to localize WordPress. A corresponding MO file for the chosen68 * language must be installed to wp-content/languages. For example, install69 * de_DE.mo to wp-content/languages and set WPLANG to 'de_DE' to enable German70 * language support.71 */72 define('WPLANG', '');73 74 /**75 65 * For developers: WordPress debugging mode. 76 66 * 77 67 * Change this to true to enable the display of notices during development.