5

Whenever I create a new user, I want to send a welcome e-mail to the user. This email is translated in both English and Chinese using the Internationalization module.

But when I check Chinese for a user, it still sends out the email in English.

The only option is to switch to the Chinese interface and then create the user, is there a way that when I select Chinese it will send out the email in that language? Regardless or not the interface is in that language?

2
  • I have the same problem, I used variables and i18n to translate the emails but users still get the English one regardless.
    – ipwa
    Commented Mar 22, 2013 at 17:56
  • Have you set it at /admin/config/regional/language/configure to 'Follow the user's language preference.'?
    – Triskelion
    Commented Mar 23, 2013 at 17:48

4 Answers 4

2

This is not a answer but can't fit this to a comment. From what I see in the source of user.module, the function that fires drupal_mail favors user's preferred language.

3495 function _user_mail_notify($op, $account, $language = NULL) {
3496 // By default, we always notify except for canceled and blocked.
3497 $default_notify = ($op != 'status_canceled' && $op != 'status_blocked');
3498 $notify = variable_get('user_mail_' . $op . '_notify', $default_notify);
3499 if ($notify) {
3500 $params['account'] = $account;
3501 $language = $language ? $language : user_preferred_language($account);
3502 $mail = drupal_mail('user', $op, $account->mail, $language, $params);
3503 if ($op == 'register_pending_approval') {
3504 // If a user registered requiring admin approval, notify the admin, too.
3505 // We use the site default language for this.
3506 drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);
3507 }
3508 }
3509 return empty($mail) ? NULL : $mail['result'];
3510 }

Note the $language param defaults to NULL and, in line 3501, if the param is NULL, it will get the user's preferred language. Moreover, none of the function calls has the third argument, so in all cases, user_preferred_language() should be used to determine the language.

So,if you have correctly translated the message, with correct t() function's syntax, message should be translated.

However, rather than translating the entire message, I'd suggest a dirty hook_mail_alter() hack to translate line by line with t() or completely different messages on 2 languages.

2

@Triskelion pointed the correct way for me and i just give more details that i solved this problem by doing following :
First, enable the mail edit module from http://drupal.org/project/mail_edit. After that add some email templates for languages by going admin/config/system/mail-edit
Next, go to /admin/config/regional/language/configure and check the 'Follow the user's language preference.' option
Finally I tested to create new account by admin and I received an welcome email by the language that i set for that user before.

0

Did you tried Rules module? It may help you send emails, depending on language selected...

4
  • Rules can do this but that feature was only added in the last few weeks and may not work for all use cases. It also means you will have to re-create the welcome mail system in Rules and suppress the built-in Drupal welcome mails-- not impossible, but not trivial either. Commented Apr 19, 2012 at 13:58
  • I didn't try the Rules modules yet, will have a look at it tomorrow. It just feels strange that this is not a default behaviour, if I specifically select a language for a user then Drupal should send the email in that language.
    – woutr_be
    Commented Apr 19, 2012 at 17:53
  • Hmm, can't seem to figure it out, I know how to send emails with Rules, but how do I check which language the created user has?
    – woutr_be
    Commented Apr 20, 2012 at 3:48
  • Better than checking it is translating the rule :) Commented Dec 20, 2012 at 13:43
0

@Triskelion Once you configured your website like Stone Vo explains, you migth notice that the tokens in your emails refer to your website in the wrong language. You might need to install a core patch called "Implement language aware tokens for one time login link and cancel link" https://drupal.org/node/1754162

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.