I would like to have the password forget mail in the same language as the user, and not the current language of the site

Comments

kars-t’s picture

Assigned: Unassigned » kars-t

Hi dereine :)

I will look into this and maybe I can set a language so we can translate it through the mail_edit module. But the real translation of the email can only be done by mail_edit module as these are core mails and not translatable through core methods.

dawehner’s picture

Status: Active » Needs review

yes thats true, here is a short example code

/**
 * Implementation of hook_form_user_pass_alter().
 */
function foo_form_user_pass_alter(&$form, $form_state) {
  // remove the default submit callback
  array_shift($form['#submit']);
  $form['#submit'][] = 'foo_user_pass_submit';
}

function foo_user_pass_submit($form, &$form_state) {
  $account = $form_state['values']['account'];
  // Mail one time login URL and instructions using current language.
  drupal_set_message(print_r($account->language, TRUE));
  _user_mail_notify('password_reset', $account, $account->language);
  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.'));

  $form_state['redirect'] = 'user';
  return;

}

i think this should work

kars-t’s picture

If you look in line 2145 of the user.module

    $language = $language ? $language : user_preferred_language($account);
    $mail = drupal_mail('user', $op, $account->mail, $language, $params);

If there is a current language use it otherwise the user preferred. I have no clue why this was used but proofs you problem...

If I read your solution correct you want to override the forms submit and handle it yourself. I bet it works but I believe hook_mail_alter is our friend here and a smaller solution:

function reglang_mail_alter(&$message) {
  if($message['id'] == 'user_password_reset') {
    $message['language'] = user_preferred_language($message['params']['account']);
  }
}

The user is an object in the params array and still here. So I load the preferred language and send the message.

I will test this now and make a new release if it works.

kars-t’s picture

Status: Needs review » Fixed

implemented in latest version

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.