Make WordPress Core


Ignore:
Timestamp:
01/26/2012 08:34:27 PM (15 years ago)
Author:
nacin
Message:

Introduce wp_load_translations_early(), which can be used before the locale is properly loaded in order to translate early error strings. Internationalize setup-config.php -- translators no longer have a reason to modify this file. fixes #18180.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/load.php

    r19712 r19760  
    2020
    2121        if ( isset( $_REQUEST['GLOBALS'] ) )
    22                 die( /*WP_I18N_GLOBALS_OVERWRITE*/'GLOBALS overwrite attempt detected'/*/WP_I18N_GLOBALS_OVERWRITE*/ );
     22                die( 'GLOBALS overwrite attempt detected' );
    2323
    2424        // Variables that shouldn't be unset
     
    9898 * Dies if requirements are not met.
    9999 *
    100  * This function must be able to work without a complete environment set up. In wp-load.php, for
    101  * example, WP_CONTENT_DIR is defined and version.php is included before this function is called.
    102  *
    103100 * @access private
    104101 * @since 3.0.0
    105102 */
    106103function wp_check_php_mysql_versions() {
    107         // we can probably extend this function to check if wp_die() exists then use translated strings, and then use it in install.php etc.
    108 
    109104        global $required_php_version, $wp_version;
    110105        $php_version = phpversion();
    111         if ( version_compare( $required_php_version, $php_version, '>' ) )
    112                 die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.'/*/WP_I18N_OLD_PHP*/, $php_version, $wp_version, $required_php_version ) );
    113 
    114         if ( !extension_loaded( 'mysql' ) && !file_exists( WP_CONTENT_DIR . '/db.php' ) )
    115                 die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
     106        if ( version_compare( $required_php_version, $php_version, '>' ) ) {
     107                wp_load_translations_early();
     108                wp_die( sprintf( __( 'Your server is running PHP version %1$s but WordPress %2$s requires at least %3$s.' ), $php_version, $wp_version, $required_php_version ) );
     109        }
     110
     111        if ( ! extension_loaded( 'mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) {
     112                wp_load_translations_early();
     113                wp_die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) );
     114        }
    116115}
    117116
     
    159158                die();
    160159        }
     160
     161        wp_load_translations_early();
    161162
    162163        $protocol = $_SERVER["SERVER_PROTOCOL"];
     
    171172        <head>
    172173        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    173                 <title><?php echo /*WP_I18N_MAINTENANCE*/'Maintenance'/*/WP_I18N_MAINTENANCE*/; ?></title>
     174                <title><?php _e( 'Maintenance' ); ?></title>
    174175
    175176        </head>
    176177        <body>
    177                 <h1><?php echo /*WP_I18N_MAINT_MSG*/'Briefly unavailable for scheduled maintenance. Check back in a minute.'/*/WP_I18N_MAINT_MSG*/; ?></h1>
     178                <h1><?php _e( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ); ?></h1>
    178179        </body>
    179180        </html>
     
    365366        $prefix = $wpdb->set_prefix( $table_prefix );
    366367
    367         if ( is_wp_error( $prefix ) )
    368                 wp_die( /*WP_I18N_BAD_PREFIX*/'<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ );
     368        if ( is_wp_error( $prefix ) ) {
     369                wp_load_translations_early();
     370                wp_die( __( '<strong>ERROR</strong>: <code>$table_prefix</code> in <code>wp-config.php</code> can only contain numbers, letters, and underscores.' ) );
     371        }
    369372}
    370373
     
    650653        return false;
    651654}
     655
     656/**
     657 * Attempts an early load of translations.
     658 *
     659 * Used for errors encountered during the initial loading process, before the locale has been
     660 * properly detected and loaded.
     661 *
     662 * Designed for unusual load sequences (like setup-config.php) or for when the script will then
     663 * terminate with an error, otherwise there is a risk that a file can be double-included.
     664 *
     665 * @since 3.4.0
     666 * @access private
     667 */
     668function wp_load_translations_early() {
     669        global $text_direction, $wp_locale;
     670
     671        static $loaded = false;
     672        if ( $loaded )
     673                return;
     674        $loaded = true;
     675
     676        if ( function_exists( 'did_action' ) && did_action( 'init' ) )
     677                return;
     678
     679        // We need $wp_local_package
     680        require ABSPATH . WPINC . '/version.php';
     681
     682        // Translation and localization
     683        require_once ABSPATH . WPINC . '/pomo/mo.php';
     684        require_once ABSPATH . WPINC . '/l10n.php';
     685        require_once ABSPATH . WPINC . '/locale.php';
     686
     687        // General libraries
     688        require_once ABSPATH . WPINC . '/functions.php';
     689        require_once ABSPATH . WPINC . '/plugin.php';
     690
     691        $locales = $locations = array();
     692
     693        while ( true ) {
     694                if ( defined( 'WPLANG' ) ) {
     695                        if ( '' == WPLANG )
     696                                break;
     697                        $locales[] = WPLANG;
     698                }
     699
     700                if ( isset( $wp_local_package ) )
     701                        $locales[] = $wp_local_package;
     702
     703                if ( ! $locales )
     704                        break;
     705
     706                if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) )
     707                        $locations[] = WP_LANG_DIR;
     708
     709                if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) )
     710                        $locations[] = WP_CONTENT_DIR . '/languages';
     711
     712                if ( @is_dir( ABSPATH . 'wp-content/languages' ) )
     713                        $locations[] = ABSPATH . 'wp-content/languages';
     714
     715                if ( @is_dir( ABSPATH . WPINC . '/languages' ) )
     716                        $locations[] = ABSPATH . WPINC . '/languages';
     717
     718                if ( ! $locations )
     719                        break;
     720
     721                $locations = array_unique( $locations );
     722
     723                foreach ( $locales as $locale ) {
     724                        foreach ( $locations as $location ) {
     725                                if ( file_exists( $location . '/' . $locale . '.mo' ) ) {
     726                                        load_textdomain( 'default', $location . '/' . $locale . '.mo' );
     727                                        if ( WP_Locale::is_locale_rtl( $locale ) )
     728                                                $text_direction = 'rtl';
     729                                        break 2;
     730                                }
     731                        }
     732                }
     733
     734                break;
     735        }
     736
     737        $wp_locale = new WP_Locale();
     738}
Note: See TracChangeset for help on using the changeset viewer.