### Eclipse Workspace Patch 1.0 #P drupal Index: modules/locale/locale.module =================================================================== RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v retrieving revision 1.171 diff -u -r1.171 locale.module --- modules/locale/locale.module 3 May 2007 09:51:08 -0000 1.171 +++ modules/locale/locale.module 11 May 2007 14:06:12 -0000 @@ -186,10 +186,11 @@ * Implementation of hook_user(). */ function locale_user($type, $edit, &$user, $category = NULL) { - if ($type == 'form' && $category == 'account' && variable_get('language_count', 1) > 1 && variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_PATH) { + // Show language field when user is editing own account and administrator is creating account + if (variable_get('language_count', 1) > 1 && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account' )) { $languages = language_list('enabled'); $languages = $languages['1']; - if ($user->language == '') { + if (!$user || $user->language == '') { $default = language_default(); $user->language = $default->language; } @@ -203,12 +204,16 @@ ); $form['locale']['language'] = array('#type' => 'radios', '#title' => t('Language'), - '#default_value' => $user->language, + '#default_value' => $user ? $user->language : $default->language, '#options' => $names, - '#description' => t('Selecting a different locale will change the interface language of the site.'), + '#description' => t('Selecting a different locale will change the interface and mail language and of the site.'), ); return $form; } + elseif ($type == 'context') { + // Switches to default language if user doesn't have one + locale_switch_language($user ? ($user->language ? $user->language : language_default()) : NULL); + } } /** @@ -289,8 +294,8 @@ static $locale_t; // Store database cached translations in a static var. - if (!isset($locale_t)) { - $locale_t = array(); + if (!isset($locale_t[$language->language])) { + $locale_t[$language->language] = array(); if (!($cache = cache_get('locale:'. $language->language, 'cache'))) { locale_refresh_cache(); $cache = cache_get('locale:'. $language->language, 'cache'); @@ -302,8 +307,8 @@ // We have the translation cached (if it is TRUE, then there is no // translation, so there is no point in checking the database) - if (isset($locale_t[$string])) { - $string = ($locale_t[$string] === TRUE ? $string : $locale_t[$string]); + if (isset($locale_t[$language->language][$string])) { + $string = ($locale_t[$language->language][$string] === TRUE ? $string : $locale_t[$language->language][$string]); } // We do not have this translation cached, so get it from the DB. @@ -312,7 +317,7 @@ // Translation found if ($trans = db_fetch_object($result)) { if (!empty($trans->translation)) { - $locale_t[$string] = $trans->translation; + $locale_t[$language->language][$string] = $trans->translation; $string = $trans->translation; } } @@ -343,6 +348,33 @@ } /** + * Switch global language while preserving current one + * + * @param $new_language + * Language object or language code to switch + */ +function locale_switch_language($new_language = NULL){ + static $request_language; + global $language; + + // Store original request language + if (!isset($request_language)) { + $request_language = $language; + } + + if (!$new_language) { + return $language = $request_language; + } elseif (is_object($new_language)) { + return $language = $new_language; + } else { + $language_list = language_list(); + if (isset($language_list[$new_language])) { + return $language = $language_list[$new_language]; + } + } +} + +/** * Refreshes database stored cache of translations. * * We only store short strings to improve performance and consume less memory. Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.779 diff -u -r1.779 user.module --- modules/user/user.module 10 May 2007 19:55:23 -0000 1.779 +++ modules/user/user.module 11 May 2007 14:06:15 -0000 @@ -282,6 +282,16 @@ } /** + * Temporarily switch some global settings like language + * + * @param $account + * User account to switch settings to + */ +function user_context($account = NULL, $operation = 'mail', $edit = array()) { + user_module_invoke('context', $edit, $account , $operation); +} + +/** * Verify the syntax of the given name. */ function user_validate_name($name) { @@ -1192,13 +1202,17 @@ $account = $form_values['account']; $from = variable_get('site_mail', ini_get('sendmail_from')); - + + // Switch language + user_context($account); // Mail one time login URL and instructions. $variables = array('!username' => $account->name, '!site' => variable_get('site_name', 'Drupal'), '!login_url' => user_pass_reset_url($account), '!uri' => $base_url, '!uri_brief' => substr($base_url, strlen('http://')), '!mailto' => $account->mail, '!date' => format_date(time()), '!login_uri' => url('user', array('absolute' => TRUE)), '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE))); $subject = _user_mail_text('pass_subject', $variables); $body = _user_mail_text('pass_body', $variables); $mail_success = drupal_mail('user-pass', $account->mail, $subject, $body, $from); - + // Reset language + user_context(); + if ($mail_success) { watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' => $account->name, '%email' => $account->mail)); drupal_set_message(t('Further instructions have been sent to your e-mail address.')); @@ -1396,6 +1410,7 @@ } else if ($account->status || $notify) { // Create new user account, no administrator approval required. + $subject = $notify ? _user_mail_text('admin_subject', $variables) : _user_mail_text('welcome_subject', $variables); $body = $notify ? _user_mail_text('admin_body', $variables) : _user_mail_text('welcome_body', $variables); @@ -1415,7 +1430,10 @@ $body = _user_mail_text('approval_body', $variables); drupal_mail('user-register-approval-user', $mail, $subject, $body, $from); + // Switch language to administrator's then back + user_context(user_load(1)); drupal_mail('user-register-approval-admin', $from, $subject, t("!username has applied for an account.\n\n!edit_uri", $variables), $from); + user_context(); drupal_set_message(t('Thank you for applying for an account. Your account is currently pending approval by the site administrator.
In the meantime, your password and further instructions have been sent to your e-mail address.')); } Index: languageswitch.php =================================================================== RCS file: languageswitch.php diff -N languageswitch.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ languageswitch.php 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,24 @@ +Testing multilingual requests'; +foreach (language_list() as $tmplang) { + locale_switch_language($tmplang); + $output .= '

'.$language->name.'

'; + $output .= '

'.t('Create content').'

'; + $output .= '

'.t('One, two, three').'

'; +} +$output .= '

Back to default request language

'; +locale_switch_language(); +$output .= '

'.t('One, two, three').'

'; +print theme('page', $output); + +drupal_page_footer();