From 81ed9a7563e5ad4c0edccd059bc4ea7d9c1a4a10 Mon Sep 17 00:00:00 2001 From: nacin Date: Thu, 26 Jan 2012 20:34:27 +0000 Subject: [PATCH] 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. git-svn-id: http://svn.automattic.com/wordpress/trunk@19760 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/setup-config.php | 95 +++++++++++++++-------------- wp-includes/functions.php | 10 +++- wp-includes/load.php | 115 +++++++++++++++++++++++++++++++----- wp-includes/locale.php | 7 ++- wp-includes/ms-load.php | 24 ++++---- wp-includes/ms-settings.php | 8 ++- wp-includes/wp-db.php | 23 ++++---- wp-load.php | 22 +++---- wp-settings.php | 8 +-- 9 files changed, 207 insertions(+), 105 deletions(-) diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index 0a025761af..68d3ee53d4 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -41,31 +41,31 @@ define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); define('WP_DEBUG', false); /**#@-*/ -require_once(ABSPATH . WPINC . '/load.php'); -require_once(ABSPATH . WPINC . '/version.php'); +require(ABSPATH . WPINC . '/load.php'); +require(ABSPATH . WPINC . '/version.php'); + +// Also loads functions.php, plugin.php, l10n.php, pomo/mo.php (all required by setup-config.php) +wp_load_translations_early(); + wp_check_php_mysql_versions(); require_once(ABSPATH . WPINC . '/compat.php'); -require_once(ABSPATH . WPINC . '/functions.php'); require_once(ABSPATH . WPINC . '/class-wp-error.php'); -if (!file_exists(ABSPATH . 'wp-config-sample.php')) - wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.'); +if ( ! file_exists( ABSPATH . 'wp-config-sample.php' ) ) + wp_die( __( 'Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.' ) ); $config_file = file(ABSPATH . 'wp-config-sample.php'); // Check if wp-config.php has been created -if (file_exists(ABSPATH . 'wp-config.php')) - wp_die("

The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now.

"); +if ( file_exists( ABSPATH . 'wp-config.php' ) ) + wp_die( '

' . sprintf( __( "The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now." ), 'install.php' ) . '

' ); // Check if wp-config.php exists above the root directory but is not part of another install -if (file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php')) - wp_die("

The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now.

"); +if ( file_exists(ABSPATH . '../wp-config.php' ) && ! file_exists( ABSPATH . '../wp-settings.php' ) ) + wp_die( '

' . sprintf( __( "The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try installing now."), 'install.php' ) . '

' ); -if (isset($_GET['step'])) - $step = $_GET['step']; -else - $step = 0; +$step = isset( $_GET['step'] ) ? (int) $_GET['step'] : 0; /** * Display setup wp-config.php file header. @@ -82,7 +82,7 @@ function display_header() { -WordPress › Setup Configuration File +<?php _e( 'WordPress › Setup Configuration File' ); ?> @@ -96,18 +96,18 @@ switch($step) { display_header(); ?> -

Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.

+

    -
  1. Database name
  2. -
  3. Database username
  4. -
  5. Database password
  6. -
  7. Database host
  8. -
  9. Table prefix (if you want to run more than one WordPress in a single database)
  10. +
  11. +
  12. +
  13. +
  14. +
-

If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php.

-

In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you’re all ready…

+

wp-config-sample.php in a text editor, fill in your information, and save it as wp-config.php.

+

In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you’re all ready…" ); ?>

-

Let’s go!

+

-

Below you should enter your database connection details. If you're not sure about these, contact your host.

+

- + - + - - - + + + - - - + + + - + - + - + - +
The name of the database you want to run WP in.
Your MySQL username
...and your MySQL password.
You should be able to get this info from your web host, if localhost does not work.localhost does not work.' ); ?>
If you want to run multiple WordPress installations in a single database, change this.
- -

+ +

ERROR: "Table Prefix" can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ ); + wp_die( __( 'ERROR: "Table Prefix" can only contain numbers, letters, and underscores.' ) ); // Test the db connection. /**#@+ @@ -175,15 +175,12 @@ switch($step) { // We'll fail here if the values are no good. require_wp_db(); if ( ! empty( $wpdb->error ) ) { - $back = '

Try Again

'; + $back = '

' . __( 'Try Again' ) . '

'; wp_die( $wpdb->error->get_error_message() . $back ); } // Fetch or generate keys and salts. $no_api = isset( $_POST['noapi'] ); - require_once( ABSPATH . WPINC . '/plugin.php' ); - require_once( ABSPATH . WPINC . '/l10n.php' ); - require_once( ABSPATH . WPINC . '/pomo/translations.php' ); if ( ! $no_api ) { require_once( ABSPATH . WPINC . '/class-http.php' ); require_once( ABSPATH . WPINC . '/http.php' ); @@ -248,15 +245,15 @@ switch($step) { if ( ! is_writable(ABSPATH) ) : display_header(); ?> -

Sorry, but I can't write the wp-config.php file.

-

You can create the wp-config.php manually and paste the following text into it.

+

wp-config.php file." ); ?>

+

wp-config.php manually and paste the following text into it.' ); ?>

-

After you've done that, click "Run the install."

-

Run the install

+

+

-

All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to…

+

-

Run the install

+

error = sprintf( /*WP_I18N_NO_TABLES*/'One or more database tables are unavailable. The database may need to be repaired.'/*/WP_I18N_NO_TABLES*/, 'maint/repair.php?referrer=is_blog_installed' ); + $wpdb->error = sprintf( __( 'One or more database tables are unavailable. The database may need to be repaired.' ), 'maint/repair.php?referrer=is_blog_installed' ); dead_db(); } @@ -2647,16 +2649,18 @@ function dead_db() { status_header( 500 ); nocache_headers(); header( 'Content-Type: text/html; charset=utf-8' ); + + wp_load_translations_early(); ?> > - <?php echo /*WP_I18N_DB_ERROR*/'Database Error'/*/WP_I18N_DB_ERROR*/; ?> + <?php _e( 'Database Error' ); ?> -

+

' ) ) - 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 ) ); + if ( version_compare( $required_php_version, $php_version, '>' ) ) { + wp_load_translations_early(); + 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 ) ); + } - if ( !extension_loaded( 'mysql' ) && !file_exists( WP_CONTENT_DIR . '/db.php' ) ) - die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ ); + if ( ! extension_loaded( 'mysql' ) && ! file_exists( WP_CONTENT_DIR . '/db.php' ) ) { + wp_load_translations_early(); + wp_die( __( 'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.' ) ); + } } /** @@ -159,6 +158,8 @@ function wp_maintenance() { die(); } + wp_load_translations_early(); + $protocol = $_SERVER["SERVER_PROTOCOL"]; if ( 'HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol ) $protocol = 'HTTP/1.0'; @@ -170,11 +171,11 @@ function wp_maintenance() { - <?php echo /*WP_I18N_MAINTENANCE*/'Maintenance'/*/WP_I18N_MAINTENANCE*/; ?> + <?php _e( 'Maintenance' ); ?> -

+

set_prefix( $table_prefix ); - if ( is_wp_error( $prefix ) ) - wp_die( /*WP_I18N_BAD_PREFIX*/'ERROR: $table_prefix in wp-config.php can only contain numbers, letters, and underscores.'/*/WP_I18N_BAD_PREFIX*/ ); + if ( is_wp_error( $prefix ) ) { + wp_load_translations_early(); + wp_die( __( 'ERROR: $table_prefix in wp-config.php can only contain numbers, letters, and underscores.' ) ); + } } /** @@ -649,3 +652,87 @@ function is_multisite() { return false; } + +/** + * Attempts an early load of translations. + * + * Used for errors encountered during the initial loading process, before the locale has been + * properly detected and loaded. + * + * Designed for unusual load sequences (like setup-config.php) or for when the script will then + * terminate with an error, otherwise there is a risk that a file can be double-included. + * + * @since 3.4.0 + * @access private + */ +function wp_load_translations_early() { + global $text_direction, $wp_locale; + + static $loaded = false; + if ( $loaded ) + return; + $loaded = true; + + if ( function_exists( 'did_action' ) && did_action( 'init' ) ) + return; + + // We need $wp_local_package + require ABSPATH . WPINC . '/version.php'; + + // Translation and localization + require_once ABSPATH . WPINC . '/pomo/mo.php'; + require_once ABSPATH . WPINC . '/l10n.php'; + require_once ABSPATH . WPINC . '/locale.php'; + + // General libraries + require_once ABSPATH . WPINC . '/functions.php'; + require_once ABSPATH . WPINC . '/plugin.php'; + + $locales = $locations = array(); + + while ( true ) { + if ( defined( 'WPLANG' ) ) { + if ( '' == WPLANG ) + break; + $locales[] = WPLANG; + } + + if ( isset( $wp_local_package ) ) + $locales[] = $wp_local_package; + + if ( ! $locales ) + break; + + if ( defined( 'WP_LANG_DIR' ) && @is_dir( WP_LANG_DIR ) ) + $locations[] = WP_LANG_DIR; + + if ( defined( 'WP_CONTENT_DIR' ) && @is_dir( WP_CONTENT_DIR . '/languages' ) ) + $locations[] = WP_CONTENT_DIR . '/languages'; + + if ( @is_dir( ABSPATH . 'wp-content/languages' ) ) + $locations[] = ABSPATH . 'wp-content/languages'; + + if ( @is_dir( ABSPATH . WPINC . '/languages' ) ) + $locations[] = ABSPATH . WPINC . '/languages'; + + if ( ! $locations ) + break; + + $locations = array_unique( $locations ); + + foreach ( $locales as $locale ) { + foreach ( $locations as $location ) { + if ( file_exists( $location . '/' . $locale . '.mo' ) ) { + load_textdomain( 'default', $location . '/' . $locale . '.mo' ); + if ( WP_Locale::is_locale_rtl( $locale ) ) + $text_direction = 'rtl'; + break 2; + } + } + } + + break; + } + + $wp_locale = new WP_Locale(); +} diff --git a/wp-includes/locale.php b/wp-includes/locale.php index b34129238b..647888d7dd 100644 --- a/wp-includes/locale.php +++ b/wp-includes/locale.php @@ -87,7 +87,7 @@ class WP_Locale { /** * Locales which are known to be right-to-left. */ - private $rtl_locales = array( 'ar', 'ckb', 'fa_IR', 'he_IL', 'ug_CN', 'dv', 'fa_AF', 'ha', 'ps', 'uz_UZ', 'yi' ); + private static $rtl_locales = array( 'ar', 'ckb', 'fa_IR', 'he_IL', 'ug_CN', 'dv', 'fa_AF', 'ha', 'ps', 'uz_UZ', 'yi' ); /** * Sets up the translated strings and object properties. @@ -183,7 +183,7 @@ class WP_Locale { $this->number_format['decimal_point'] = ('number_format_decimal_point' == $trans) ? '.' : $trans; // Locale-specific tweaks - if ( in_array( get_locale(), $this->rtl_locales ) ) + if ( self::is_locale_rtl( get_locale() ) ) $this->text_direction = 'rtl'; // Import the $text_direction global. @@ -333,6 +333,9 @@ class WP_Locale { return 'rtl' == $this->text_direction; } + public static function is_locale_rtl( $locale ) { + return in_array( $locale, self::$rtl_locales ); + } } /** diff --git a/wp-includes/ms-load.php b/wp-includes/ms-load.php index c55832ff43..58826e7804 100644 --- a/wp-includes/ms-load.php +++ b/wp-includes/ms-load.php @@ -211,10 +211,12 @@ function wpmu_current_site() { } // Still no dice. + wp_load_translations_early(); + if ( 1 == count( $sites ) ) - wp_die( sprintf( /*WP_I18N_BLOG_DOESNT_EXIST*/'That site does not exist. Please try %s.'/*/WP_I18N_BLOG_DOESNT_EXIST*/, $sites[0]->domain . $sites[0]->path ) ); + wp_die( sprintf( __( 'That site does not exist. Please try %s.' ), 'http://' . $sites[0]->domain . $sites[0]->path ) ); else - wp_die( /*WP_I18N_NO_SITE_DEFINED*/'No site defined on this host. If you are the owner of this site, please check Debugging a WordPress Network for help.'/*/WP_I18N_NO_SITE_DEFINED*/ ); + wp_die( __( 'No site defined on this host. If you are the owner of this site, please check Debugging a WordPress Network for help.' ) ); } /** @@ -228,19 +230,21 @@ function wpmu_current_site() { function ms_not_installed() { global $wpdb, $domain, $path; - $title = /*WP_I18N_FATAL_ERROR*/'Error establishing database connection'/*/WP_I18N_FATAL_ERROR*/; + wp_load_translations_early(); + + $title = __( 'Error establishing database connection' ); $msg = '

' . $title . '

'; if ( ! is_admin() ) die( $msg ); - $msg .= '

' . /*WP_I18N_CONTACT_OWNER*/'If your site does not display, please contact the owner of this network.'/*/WP_I18N_CONTACT_OWNER*/ . ''; - $msg .= ' ' . /*WP_I18N_CHECK_MYSQL*/'If you are the owner of this network please check that MySQL is running properly and all tables are error free.'/*/WP_I18N_CHECK_MYSQL*/ . '

'; + $msg .= '

' . __( 'If your site does not display, please contact the owner of this network.' ) . ''; + $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '

'; if ( false && !$wpdb->get_var( "SHOW TABLES LIKE '$wpdb->site'" ) ) - $msg .= '

' . sprintf( /*WP_I18N_TABLES_MISSING_LONG*/'Database tables are missing. This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.'/*/WP_I18N_TABLES_MISSING_LONG*/, $wpdb->site ) . '

'; + $msg .= '

' . sprintf( __( 'Database tables are missing. This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ), $wpdb->site ) . '

'; else - $msg .= '

' . sprintf( /*WP_I18N_NO_SITE_FOUND*/'Could not find site %1$s. Searched for table %2$s in database %3$s. Is that right?'/*/WP_I18N_NO_SITE_FOUND*/, rtrim( $domain . $path, '/' ), $wpdb->blogs, DB_NAME ) . '

'; - $msg .= '

' . /*WP_I18N_WHAT_DO_I_DO*/'What do I do now?'/*/WP_I18N_WHAT_DO_I_DO*/ . ' '; - $msg .= /*WP_I18N_RTFM*/'Read the bug report page. Some of the guidelines there may help you figure out what went wrong.'/*/WP_I18N_RTFM*/; - $msg .= ' ' . /*WP_I18N_STUCK*/'If you’re still stuck with this message, then check that your database contains the following tables:'/*/WP_I18N_STUCK*/ . '