diff options
author | Neil Drumm <drumm@3064.no-reply.drupal.org> | 2006-09-01 05:38:40 +0000 |
---|---|---|
committer | Neil Drumm <drumm@3064.no-reply.drupal.org> | 2006-09-01 05:38:40 +0000 |
commit | 30c2e89ce701b3b4d71cdb81815418655f663a30 (patch) | |
tree | 057dd9310fc0168f226c5084daa57c298897c353 | |
parent | 0c9908c37db715bb339024a8791714415e77a5ae (diff) | |
download | brdo-30c2e89ce701b3b4d71cdb81815418655f663a30.tar.gz brdo-30c2e89ce701b3b4d71cdb81815418655f663a30.tar.bz2 |
#76555 by Goba. Installer l10n.
-rw-r--r-- | CHANGELOG.txt | 1 | ||||
-rw-r--r-- | includes/install.inc | 22 | ||||
-rw-r--r-- | includes/locale.inc | 311 | ||||
-rw-r--r-- | install.php | 126 |
4 files changed, 297 insertions, 163 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 668f27e70..ed4296eb7 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -8,6 +8,7 @@ Drupal x.x.x, xxxx-xx-xx (development version) * automatically generate the database configuration file * install pre-made 'install profiles' or distributions * import the database structure with automatic table prefixing + * be localized - included the jQuery JavaScript library and converted all core JavaScript to use it - introduced the ability to alter mail sent from system - moved core modules to their own directories to allow additional flexibility diff --git a/includes/install.inc b/includes/install.inc index b4367c16d..087d02577 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -253,10 +253,12 @@ function drupal_get_install_files($module_list = array()) { * * @param profile * Name of profile to verify. + * @param locale + * Name of locale used (if any). * @return * The list of modules to install. */ -function drupal_verify_profile($profile) { +function drupal_verify_profile($profile, $locale) { include_once './includes/file.inc'; $profile_file = "./profiles/$profile/$profile.profile"; @@ -269,7 +271,7 @@ function drupal_verify_profile($profile) { // Get a list of modules required by this profile. $function = $profile .'_profile_modules'; - $module_list = array_merge(array('system'), $function()); + $module_list = array_merge(array('system'), $function(), ($locale ? array('locale') : array())); // Verify that all required modules exist. $modules_present = TRUE; @@ -549,11 +551,25 @@ function install_goto($path) { * when the theme system is not available. */ function st($string, $args = array()) { + static $locale_strings = NULL; + global $profile, $install_locale; + + if (!isset($locale_strings)) { + $locale_strings = array(); + $filename = './profiles/' . $profile . '/' . $install_locale . '.po'; + if (file_exists($filename)) { + require_once './includes/locale.inc'; + $file = (object) array('filepath' => $filename); + _locale_import_read_po('mem-store', $file); + $locale_strings = _locale_import_one_string('mem-report'); + } + } + require_once './includes/theme.inc'; $GLOBALS['theme'] = 'theme'; // Transform arguments before inserting them array_walk($args, '_st'); - return strtr($string, $args); + return strtr((!empty($locale_strings[$string]) ? $locale_strings[$string] : $string), $args); } /** diff --git a/includes/locale.inc b/includes/locale.inc index 0b2c5a333..b81891e28 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -456,9 +456,12 @@ function _locale_string_delete($lid) { /** * Parses Gettext Portable Object file information and inserts into database * - * @param $file Object contains properties of local file to be imported - * @param $lang Language code - * @param $mode should existing translations be replaced? + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $lang + * Language code + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') */ function _locale_import_po($file, $lang, $mode) { // If not in 'safe mode', increase the maximum execution time: @@ -473,14 +476,14 @@ function _locale_import_po($file, $lang, $mode) { } // Get strings from file (returns on failure after a partial import, or on success) - $status = _locale_import_read_po($file, $mode, $lang); + $status = _locale_import_read_po('db-store', $file, $mode, $lang); if ($status === FALSE) { // error messages are set in _locale_import_read_po return FALSE; } // Get status information on import process - list($headerdone, $additions, $updates) = _locale_import_one_string('report', $mode); + list($headerdone, $additions, $updates) = _locale_import_one_string('db-report'); if (!$headerdone) { drupal_set_message(t('The translation file %filename appears to have a missing or malformed header.', array('%filename' => $file->filename)), 'error'); @@ -500,15 +503,21 @@ function _locale_import_po($file, $lang, $mode) { /** * Parses Gettext Portable Object file into an array * - * @param $file Object with properties of local file to parse + * @param $op + * Storage operation type: db-store or mem-store + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') + * @param $lang + * Language code * @author Jacobo Tarrio */ -function _locale_import_read_po($file, $mode, $lang) { +function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL) { - $message = theme('placeholder', $file->filename); $fd = fopen($file->filepath, "rb"); // File will get closed by PHP on return if (!$fd) { - drupal_set_message(t('The translation import failed, because the file %filename could not be read.', array('%filename' => $message)), 'error'); + _locale_import_message('The translation import failed, because the file %filename could not be read.', $file); return FALSE; } @@ -527,25 +536,25 @@ function _locale_import_read_po($file, $mode, $lang) { $current["#"][] = substr($line, 1); } elseif (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { // End current entry, start a new one - _locale_import_one_string($current, $mode, $lang); + _locale_import_one_string($op, $current, $mode, $lang); $current = array(); $current["#"][] = substr($line, 1); $context = "COMMENT"; } else { // Parse error - drupal_set_message(t('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: "msgstr" was expected but not found on line %line.', $file, $lineno); return FALSE; } } elseif (!strncmp("msgid_plural", $line, 12)) { if ($context != "MSGID") { // Must be plural form for current entry - drupal_set_message(t('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: "msgid_plural" was expected but not found on line %line.', $file, $lineno); return FALSE; } $line = trim(substr($line, 12)); $quoted = _locale_import_parse_quoted($line); if ($quoted === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } $current["msgid"] = $current["msgid"] ."\0". $quoted; @@ -553,17 +562,17 @@ function _locale_import_read_po($file, $mode, $lang) { } elseif (!strncmp("msgid", $line, 5)) { if ($context == "MSGSTR") { // End current entry, start a new one - _locale_import_one_string($current, $mode, $lang); + _locale_import_one_string($op, $current, $mode, $lang); $current = array(); } elseif ($context == "MSGID") { // Already in this context? Parse error - drupal_set_message(t('The translation file %filename contains an error: "msgid" is unexpected on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: "msgid" is unexpected on line %line.', $file, $lineno); return FALSE; } $line = trim(substr($line, 5)); $quoted = _locale_import_parse_quoted($line); if ($quoted === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } $current["msgid"] = $quoted; @@ -571,11 +580,11 @@ function _locale_import_read_po($file, $mode, $lang) { } elseif (!strncmp("msgstr[", $line, 7)) { if (($context != "MSGID") && ($context != "MSGID_PLURAL") && ($context != "MSGSTR_ARR")) { // Must come after msgid, msgid_plural, or msgstr[] - drupal_set_message(t('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: "msgstr[]" is unexpected on line %line.', $file, $lineno); return FALSE; } if (strpos($line, "]") === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } $frombracket = strstr($line, "["); @@ -583,7 +592,7 @@ function _locale_import_read_po($file, $mode, $lang) { $line = trim(strstr($line, " ")); $quoted = _locale_import_parse_quoted($line); if ($quoted === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } $current["msgstr"][$plural] = $quoted; @@ -591,13 +600,13 @@ function _locale_import_read_po($file, $mode, $lang) { } elseif (!strncmp("msgstr", $line, 6)) { if ($context != "MSGID") { // Should come just after a msgid block - drupal_set_message(t('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: "msgstr" is unexpected on line %line.', $file, $lineno); return FALSE; } $line = trim(substr($line, 6)); $quoted = _locale_import_parse_quoted($line); if ($quoted === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } $current["msgstr"] = $quoted; @@ -606,7 +615,7 @@ function _locale_import_read_po($file, $mode, $lang) { elseif ($line != "") { $quoted = _locale_import_parse_quoted($line); if ($quoted === FALSE) { - drupal_set_message(t('The translation file %filename contains a syntax error on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains a syntax error on line %line.', $file, $lineno); return FALSE; } if (($context == "MSGID") || ($context == "MSGID_PLURAL")) { @@ -619,7 +628,7 @@ function _locale_import_read_po($file, $mode, $lang) { $current["msgstr"][$plural] .= $quoted; } else { - drupal_set_message(t('The translation file %filename contains an error: there is an unexpected string on line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename contains an error: there is an unexpected string on line %line.', $file, $lineno); return FALSE; } } @@ -627,133 +636,174 @@ function _locale_import_read_po($file, $mode, $lang) { // End of PO file, flush last entry if (($context == "MSGSTR") || ($context == "MSGSTR_ARR")) { - _locale_import_one_string($current, $mode, $lang); + _locale_import_one_string($op, $current, $mode, $lang); } elseif ($context != "COMMENT") { - drupal_set_message(t('The translation file %filename ended unexpectedly at line %line.', array('%filename' => $message, '%line' => $lineno)), 'error'); + _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno); return FALSE; } } /** + * Sets an error message occured during locale file parsing. + * + * @param $message + * The message to be translated + * @param $file + * Drupal file object corresponding to the PO file to import + * @param $lineno + * An optional line number argument + */ +function _locale_import_message($message, $file, $lineno = NULL) { + $vars = array('%filename' => $file->filename); + if (isset($lineno)) { + $vars['%line'] = $lineno; + } + $t = function_exists('installer_main') ? 'st' : 't'; + drupal_set_message($t($message, $vars), 'error'); +} + +/** * Imports a string into the database * - * @param $value Information about the string + * @param $op + * Operation to perform: 'db-store', 'db-report', 'mem-store' or 'mem-report' + * @param $value + * Details of the string stored + * @param $mode + * Should existing translations be replaced ('overwrite' or 'keep') + * @param $lang + * Language to store the string in * @author Jacobo Tarrio */ -function _locale_import_one_string($value, $mode, $lang = NULL) { +function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL) { static $additions = 0; static $updates = 0; static $headerdone = FALSE; - - // Report the changes made (called at end of import) - if ($value == 'report') { - return array($headerdone, $additions, $updates); - } - // Current string is the header information - elseif ($value['msgid'] == '') { - $hdr = _locale_import_parse_header($value['msgstr']); - - // Get the plural formula - if ($hdr["Plural-Forms"] && $p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename)) { - list($nplurals, $plural) = $p; - db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", $nplurals, $plural, $lang); - } - else { - db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", 0, '', $lang); - } - $headerdone = TRUE; - } - // Some real string to import - else { - $comments = filter_xss_admin(_locale_import_shorten_comments($value['#'])); - - // Handle a translation for some plural string - if (strpos($value['msgid'], "\0")) { - $english = explode("\0", $value['msgid'], 2); - $entries = array_keys($value['msgstr']); - for ($i = 3; $i <= count($entries); $i++) { - $english[] = $english[1]; - } - $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); - $english = array_map('_locale_import_append_plural', $english, $entries); - foreach ($translation as $key => $trans) { - if ($key == 0) { - $plid = 0; + static $strings = array(); + + switch ($op) { + // Return stored strings + case 'mem-report': + return $strings; + + // Store string in memory (only supports single strings) + case 'mem-store': + $strings[$value['msgid']] = $value['msgstr']; + return; + + // Called at end of import to inform the user + case 'db-report': + return array($headerdone, $additions, $updates); + + // Store the string we got in the database + case 'db-store': + // We got header information + if ($value['msgid'] == '') { + $hdr = _locale_import_parse_header($value['msgstr']); + + // Get the plural formula + if ($hdr["Plural-Forms"] && $p = _locale_import_parse_plural_forms($hdr["Plural-Forms"], $file->filename)) { + list($nplurals, $plural) = $p; + db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", $nplurals, $plural, $lang); } - $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); - if ($loc->lid) { // a string exists - $lid = $loc->lid; - // update location field - db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid); - $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); - if (!$trans2->lid) { // no translation in current language - db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key); - $additions++; - } // translation exists - else if ($mode == 'overwrite' || $trans2->translation == '') { - db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", filter_xss_admin($trans), $plid, $key, $lang, $lid); - if ($trans2->translation == '') { - $additions++; + else { + db_query("UPDATE {locales_meta} SET plurals = %d, formula = '%s' WHERE locale = '%s'", 0, '', $lang); + } + $headerdone = TRUE; + } + + // Some real string to import + else { + $comments = filter_xss_admin(_locale_import_shorten_comments($value['#'])); + + // Handle a translation for some plural string + if (strpos($value['msgid'], "\0")) { + $english = explode("\0", $value['msgid'], 2); + $entries = array_keys($value['msgstr']); + for ($i = 3; $i <= count($entries); $i++) { + $english[] = $english[1]; + } + $translation = array_map('_locale_import_append_plural', $value['msgstr'], $entries); + $english = array_map('_locale_import_append_plural', $english, $entries); + foreach ($translation as $key => $trans) { + if ($key == 0) { + $plid = 0; } - else { - $updates++; + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); + if ($loc->lid) { // a string exists + $lid = $loc->lid; + // update location field + db_query("UPDATE {locales_source} SET location = '%s' WHERE lid = %d", $comments, $lid); + $trans2 = db_fetch_object(db_query("SELECT lid, translation, plid, plural FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + if (!$trans2->lid) { // no translation in current language + db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key); + $additions++; + } // translation exists + else if ($mode == 'overwrite' || $trans2->translation == '') { + db_query("UPDATE {locales_target} SET translation = '%s', plid = %d, plural = %d WHERE locale = '%s' AND lid = %d", filter_xss_admin($trans), $plid, $key, $lang, $lid); + if ($trans2->translation == '') { + $additions++; + } + else { + $updates++; + } + } } + else { // no string + db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, filter_xss_admin($english[$key])); + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); + $lid = $loc->lid; + db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key); + if ($trans != '') { + $additions++; + } + } + $plid = $lid; } } - else { // no string - db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, filter_xss_admin($english[$key])); - $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english[$key])); - $lid = $loc->lid; - db_query("INSERT INTO {locales_target} (lid, locale, translation, plid, plural) VALUES (%d, '%s', '%s', %d, %d)", $lid, $lang, filter_xss_admin($trans), $plid, $key); - if ($trans != '') { - $additions++; - } - } - $plid = $lid; - } - } - // A simple translation - else { - $english = $value['msgid']; - $translation = $value['msgstr']; - $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); - if ($loc->lid) { // a string exists - $lid = $loc->lid; - // update location field - db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english); - $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); - if (!$trans->lid) { // no translation in current language - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation)); - $additions++; - } // translation exists - else if ($mode == 'overwrite') { //overwrite in any case - db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", filter_xss_admin($translation), $lang, $lid); - if ($trans->translation == '') { - $additions++; + // A simple translation + else { + $english = $value['msgid']; + $translation = $value['msgstr']; + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); + if ($loc->lid) { // a string exists + $lid = $loc->lid; + // update location field + db_query("UPDATE {locales_source} SET location = '%s' WHERE source = '%s'", $comments, $english); + $trans = db_fetch_object(db_query("SELECT lid, translation FROM {locales_target} WHERE lid = %d AND locale = '%s'", $lid, $lang)); + if (!$trans->lid) { // no translation in current language + db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation)); + $additions++; + } // translation exists + else if ($mode == 'overwrite') { //overwrite in any case + db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", filter_xss_admin($translation), $lang, $lid); + if ($trans->translation == '') { + $additions++; + } + else { + $updates++; + } + } // overwrite if empty string + else if ($trans->translation == '') { + db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); + $additions++; + } } - else { - $updates++; + else { // no string + db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english); + $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); + $lid = $loc->lid; + db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation)); + if ($translation != '') { + $additions++; + } } - } // overwrite if empty string - else if ($trans->translation == '') { - db_query("UPDATE {locales_target} SET translation = '%s' WHERE locale = '%s' AND lid = %d", $translation, $lang, $lid); - $additions++; } } - else { // no string - db_query("INSERT INTO {locales_source} (location, source) VALUES ('%s', '%s')", $comments, $english); - $loc = db_fetch_object(db_query("SELECT lid FROM {locales_source} WHERE source = '%s'", $english)); - $lid = $loc->lid; - db_query("INSERT INTO {locales_target} (lid, locale, translation) VALUES (%d, '%s', '%s')", $lid, $lang, filter_xss_admin($translation)); - if ($translation != '') { - $additions++; - } - } - } - } + } // end of db-store operation } /** @@ -781,10 +831,13 @@ function _locale_import_parse_header($header) { /** * Parses a Plural-Forms entry from a Gettext Portable Object file header * - * @param $pluralforms A string containing the Plural-Forms entry - * @param $filename A string containing the filename - * @return An array containing the number of plurals and a - * formula in PHP for computing the plural form + * @param $pluralforms + * A string containing the Plural-Forms entry + * @param $filename + * A string containing the filename + * @return + * An array containing the number of plurals and a + * formula in PHP for computing the plural form * @author Jacobo Tarrio */ function _locale_import_parse_plural_forms($pluralforms, $filename) { diff --git a/install.php b/install.php index 5431fb71f..166e9f212 100644 --- a/install.php +++ b/install.php @@ -15,7 +15,7 @@ require_once './includes/install.inc'; * The installation phase we should proceed to. */ function install_main() { - global $profile; + global $profile, $install_locale; require_once './includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); require_once './modules/system/system.install'; @@ -53,6 +53,15 @@ function install_main() { else { install_no_profile_error(); } + + // Locale selection + if (!empty($_GET['locale'])) { + $install_locale = preg_replace('/[^a-zA-Z_0-9]/', '', $_GET['locale']); + } + elseif (($install_locale = install_select_locale($profile)) !== FALSE) { + install_goto("install.php?profile=$profile&locale=$install_locale"); + } + // Load the profile. require_once "./profiles/$profile/$profile.profile"; @@ -62,7 +71,7 @@ function install_main() { } // Perform actual installation defined in the profile. - $modules = drupal_verify_profile($profile); + $modules = drupal_verify_profile($profile, $install_locale); drupal_install_profile($profile, $modules); // Warn about settings.php permissions risk @@ -113,7 +122,7 @@ function install_verify_settings() { * Configure and rewrite settings.php. */ function install_change_settings() { - global $profile, $db_url, $db_type, $db_prefix; + global $profile, $install_locale, $db_url, $db_type, $db_prefix; $url = parse_url($db_url); $db_user = urldecode($url['user']); @@ -131,7 +140,7 @@ function install_change_settings() { if (!drupal_verify_install_file($settings_file, FILE_EXIST|FILE_READABLE|FILE_WRITABLE)) { drupal_set_message(st('The @drupal installer requires write permissions to %file during the installation process.', array('@drupal' => drupal_install_profile_name(), '%file' => $settings_file)), 'error'); - drupal_set_title('Drupal database setup'); + drupal_set_title(st('Drupal database setup')); print theme('install_page', ''); exit; } @@ -140,8 +149,8 @@ function install_change_settings() { if ($db_url == 'mysql://username:password@localhost/databasename') { $db_user = $db_pass = $db_path = ''; } - $output = drupal_get_form('install_settings_form', $profile, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path); - drupal_set_title('Database configuration'); + $output = drupal_get_form('install_settings_form', $profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path); + drupal_set_title(st('Database configuration')); print theme('install_page', $output); exit; } @@ -150,18 +159,18 @@ function install_change_settings() { /** * Form API array definition for install_settings. */ -function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path) { +function install_settings_form($profile, $install_locale, $settings_file, $db_url, $db_type, $db_prefix, $db_user, $db_pass, $db_host, $db_path) { $db_types = drupal_detect_database_types(); if (count($db_types) == 0) { $form['no_db_types'] = array( '#type' => 'markup', - '#value' => 'Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that <a href="http://drupal.org/node/270#database">Drupal supports</a>.', + '#value' => st('Your web server does not appear to support any common database types. Check with your hosting provider to see if they offer any databases that <a href="@drupal-databases">Drupal supports</a>.', array('@drupal-databases' => 'http://drupal.org/node/270#database')), ); } else { $form['basic_options'] = array( '#type' => 'fieldset', - '#title' => 'Basic options', + '#title' => st('Basic options'), '#description' => st('<p>To set up your @drupal database, enter the following information.</p>', array('@drupal' => drupal_install_profile_name())), ); @@ -169,7 +178,7 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ // Database type $form['basic_options']['db_type'] = array( '#type' => 'radios', - '#title' => 'Database type', + '#title' => st('Database type'), '#required' => TRUE, '#options' => drupal_detect_database_types(), '#default_value' => $db_type, @@ -191,7 +200,7 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ // Database name $form['basic_options']['db_path'] = array( '#type' => 'textfield', - '#title' => 'Database name', + '#title' => st('Database name'), '#default_value' => $db_path, '#size' => 45, '#maxlength' => 45, @@ -202,7 +211,7 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ // Database username $form['basic_options']['db_user'] = array( '#type' => 'textfield', - '#title' => 'Database username', + '#title' => st('Database username'), '#default_value' => $db_user, '#size' => 45, '#maxlength' => 45, @@ -212,7 +221,7 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ // Database username $form['basic_options']['db_pass'] = array( '#type' => 'password', - '#title' => 'Database password', + '#title' => st('Database password'), '#default_value' => $db_pass, '#size' => 45, '#maxlength' => 45, @@ -221,27 +230,27 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ $form['advanced_options'] = array( '#type' => 'fieldset', - '#title' => 'Advanced options', + '#title' => st('Advanced options'), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => 'These options are only necessary for some sites. If you\'re not sure what you should enter here, leave the default settings or check with your hosting provider.' + '#description' => st('These options are only necessary for some sites. If you\'re not sure what you should enter here, leave the default settings or check with your hosting provider.') ); // Database host $form['advanced_options']['db_host'] = array( '#type' => 'textfield', - '#title' => 'Database host', + '#title' => st('Database host'), '#default_value' => $db_host, '#size' => 45, '#maxlength' => 45, '#required' => TRUE, - '#description' => 'If your database is located on a different server, change this.', + '#description' => st('If your database is located on a different server, change this.'), ); // Database prefix $form['advanced_options']['db_prefix'] = array( '#type' => 'textfield', - '#title' => 'Database prefix', + '#title' => st('Database prefix'), '#default_value' => $db_prefix, '#size' => 45, '#maxlength' => 45, @@ -251,13 +260,13 @@ function install_settings_form($profile, $settings_file, $db_url, $db_type, $db_ $form['save'] = array( '#type' => 'submit', - '#value' => 'Save configuration', + '#value' => st('Save configuration'), ); $form['errors'] = array(); $form['settings_file'] = array('#type' => 'value', '#value' => $settings_file); $form['_db_url'] = array('#type' => 'value'); - $form['#action'] = "install.php?profile=$profile"; + $form['#action'] = "install.php?profile=$profile" . ($install_locale ? "&locale=$install_locale" : ''); $form['#redirect'] = NULL; } return $form; @@ -318,7 +327,7 @@ function _install_settings_form_validate($db_prefix, $db_type, $db_user, $db_pas * Form API submit for install_settings form. */ function install_settings_form_submit($form_id, $form_values) { - global $profile; + global $profile, $install_locale; // Update global settings array and save $settings['db_url'] = array( @@ -332,7 +341,7 @@ function install_settings_form_submit($form_id, $form_values) { drupal_rewrite_settings($settings); // Continue to install profile step - install_goto("install.php?profile=$profile"); + install_goto("install.php?profile=$profile" . ($install_locale ? "&locale=$install_locale" : '')); } /** @@ -361,7 +370,7 @@ function install_select_profile() { drupal_maintenance_theme(); - drupal_set_title('Select an installation profile'); + drupal_set_title(st('Select an installation profile')); print theme('install_page', drupal_get_form('install_select_profile_form', $profiles)); exit; } @@ -388,7 +397,63 @@ function install_select_profile_form($profiles) { } $form['submit'] = array( '#type' => 'submit', - '#value' => 'Save configuration', + '#value' => st('Save configuration'), + ); + return $form; +} + +/** + * Find all .po files for the current profile and allow admin to select which to use. + * + * @return + * The selected language. + */ +function install_select_locale($profilename) { + include_once './includes/file.inc'; + include_once './includes/form.inc'; + + // Collect possible locales, add default + $locales = file_scan_directory('./profiles/' . $profilename, '\.po$', array('.', '..', 'CVS'), 0, FALSE); + array_unshift($locales, (object) array('name' => 'en')); + + // Don't need to choose locale if only one (English) is available. + if (sizeof($locales) == 1) { + return FALSE; + } else { + foreach ($locales as $locale) { + if ($_POST['locale'] == $locale->name) { + return $locale->name; + } + } + + drupal_maintenance_theme(); + + drupal_set_title(st('Choose your preferred language')); + print theme('install_page', drupal_get_form('install_select_locale_form', $locales)); + exit; + } +} + +function install_select_locale_form($locales) { + include_once './includes/locale.inc'; + $languages = _locale_get_iso639_list(); + foreach ($locales as $locale) { + // Try to use verbose locale name + $name = $locale->name; + if (isset($languages[$name])) { + $name = $languages[$name][0] . (isset($languages[$name][1]) ? ' (' . $languages[$name][1] . ')' : ''); + } + $form['locale'][$locale->name] = array( + '#type' => 'radio', + '#return_value' => $locale->name, + '#default_value' => ($locale->name == 'en' ? TRUE : FALSE), + '#title' => $name . ($locale->name == 'en' ? ' (built-in)' : ''), + '#parents' => array('locale') + ); + } + $form['submit'] = array( + '#type' => 'submit', + '#value' => st('Save configuration'), ); return $form; } @@ -398,8 +463,8 @@ function install_select_profile_form($profiles) { */ function install_no_profile_error() { drupal_maintenance_theme(); - drupal_set_title('No profiles available'); - print theme('install_page', '<p>We were unable to find any installer profiles. Installer profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.</p>'); + drupal_set_title(st('No profiles available')); + print theme('install_page', st('<p>We were unable to find any installer profiles. Installer profiles tell us what modules to enable and what schema to install in the database. A profile is necessary to continue with the installation process.</p>')); exit; } @@ -411,8 +476,8 @@ function install_already_done_error() { global $base_url; drupal_maintenance_theme(); - drupal_set_title('Drupal already installed'); - print theme('install_page', '<ul><li>To start over, you must empty your existing database.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To upgrade an existing installation, proceed to the <a href="'. $base_url .'/update.php">update script</a>.</li></ul>'); + drupal_set_title(st('Drupal already installed')); + print theme('install_page', st('<ul><li>To start over, you must empty your existing database.</li><li>To install to a different database, edit the appropriate <em>settings.php</em> file in the <em>sites</em> folder.</li><li>To upgrade an existing installation, proceed to the <a href="@base-url/update.php">update script</a>.</li></ul>', array('@base-url' => $base_url))); exit; } @@ -432,7 +497,7 @@ function install_complete($profile) { // Build final page. drupal_maintenance_theme(); drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name()))); - $output = st('<p>Congratulations, @drupal has been successfully installed.</p>', array('@drupal' => drupal_install_profile_name())); + $output .= st('<p>Congratulations, @drupal has been successfully installed.</p>', array('@drupal' => drupal_install_profile_name())); // Show profile finalization info. $function = $profile .'_profile_final'; @@ -442,8 +507,7 @@ function install_complete($profile) { } else { // No more steps - $msg = drupal_set_message() ? 'Please review the messages above before continuing on to <a href="%url">your new site</a>.' : 'You may now visit <a href="%url">your new site</a>.'; - $output .= strtr('<p>'. $msg .'</p>', array('%url' => url(''))); + $output .= '<p>' . (drupal_set_message() ? st('Please review the messages above before continuing on to <a href="@url">your new site</a>.', array('@url' => url(''))) : st('You may now visit <a href="@url">your new site</a>.', array('@url' => url('')))) . '</p>'; } // Output page. print theme('maintenance_page', $output); |