Whilst trying to get my registration messages to appear in alternative languages, I've noticed a potential issue with the _user_mail_text function.

It appears that if a variable if found that contains a mail template (which seem to created as part of the installation), then the output is never run through the t() function, so cannot be translated....

Would it not be better to replace:

return strtr($admin_setting, $variables);

with

return t($admin_setting, $variables, $langcode);

Or better still, store the langcode as part of the variable so the correct translated variable could be retrieved.

e.g. 'user_mail_'. $key.'_'.$langcode

Comments

dddave’s picture

Status: Active » Closed (duplicate)

The translation of mail text is very flawed in D6. Those modules try to circumvent these problems:

http://drupal.org/project/mail_edit

http://drupal.org/project/reglang

If I remember correctly this problem is solved for D7. Setting this to duplicate because this is definitely a known problem. Sorry for not providing a link to another issue but I know they are out there. ;)

dmoore’s picture

Great thanks - these modules have solved my problem.

theex’s picture

Version: 6.x-dev » 7.8

This problem doesn't seem to be solved in drupal 7.8
And mail_edit doesn't solve my problem, it seems to be buggy at the moment.

Problem:
When mail template are saved they go into variables table in db.
When drupal_mail is called for a new registration _user_mail_text function is called and $text=$admin_setting;

No translation through t() is done in this case.

function _user_mail_text($key, $language = NULL, $variables = array(), $replace = TRUE) {
  $langcode = isset($language) ? $language->language : NULL;

  if ($admin_setting = variable_get('user_mail_' . $key, FALSE)) {
    // An admin setting overrides the default string.
    $text = $admin_setting;
  }
  else {
    // No override, return default string.
    switch ($key) {
      case 'register_no_approval_required_subject':
        $text = t('Account details for [user:name] at [site:name]', array(), array('langcode' => $langcode));
        break;
        ........
        ........

This change works for me (I know, it's not a good things to change core). replace (false) is a param that come from admin interface for disable token replace in mail.
Usually is true.

function _user_mail_text($key, $language = NULL, $variables = array(), $replace = TRUE) {
  $langcode = isset($language) ? $language->language : NULL;

  if ($admin_setting = variable_get('user_mail_' . $key, FALSE)) {
    // An admin setting overrides the default string.
    $text = $replace ? t($admin_setting, array(), array('langcode' => $langcode)) : $admin_setting;
  }
  else {
  ..........
  ..........

Hope this helps.
Sorry for my english

fenda’s picture

Priority: Minor » Major

This issue is still present in D7 core. I apologize if this is not classed as major, but I cannot use my site in production without this being fixed.

How to re-produce:

  • Set up a site with multiple languages installed
  • Set default language to English
  • Enable some sort of detection, for example Browser
  • Go to user/register on a browser that is non-english
  • The user registration form is in the visitors native language (WORKING)
  • After registration, email comes in the correct language (WORKING)
  • As admin, go to admin/config/people/accounts and change anything on the form (e.g. Account registration settings)
  • Try registering again on a non-english browser. Email comes in the sites default language (BROKEN)

After submitting the admin/config/people/accounts form, even when not changing the E-mails settings, user_mail_ variables get set. This forces the code below to run.

Problem code (user.module 2592):

if ($admin_setting = variable_get('user_mail_' . $key, FALSE)) {
    // An admin setting overrides the default string.
    $text = $admin_setting;
  }

Any smart ideas on how we could fix this?

fenda’s picture

Version: 7.8 » 7.9
fenda’s picture

Status: Closed (duplicate) » Active

I see there is another issue like this, but it is for 6.x-dev: http://drupal.org/node/163165
Wasn't sure how to proceed, but sticking to this one for now.

dddave’s picture

Version: 7.9 » 6.25
Status: Active » Closed (duplicate)

Sorry to be pain here but I am going to close this issue again because it is meandering (starting as a D6 issue). Please create a new issue with your stuff from #4 and set it at least against 7-dev. The ubercorrect way would be to set against D8 because it would have to be fixed there first. I don't know though how user module will change in D8 so setting against D7 might be ok. The priority would be "normal" btw.

Jānis Bebrītis’s picture

Issue summary: View changes
StatusFileSize
new579 bytes

Don't want to reopen the issue, but here's a #4 #3 made into patch