The bug description:
account_activated email language depends on website language - not registered user preferred language (as expected).
so, if user registers on russian version of the website, and his preferred language is set to russian,
but admin uses english version of the website to approve the account, the approved user will get email in English.
Steps to reproduce:
1) Install drupal, set up registration mode to "user can register; approval required", enable english and russian languages for interface
2) enable i18n_variable module, activate translation for account-related emails
3) translate user_activated email body and subject to russian
4) open website as anonymous, using russian language, create new account
5) open website as admin, using english language, approve new user
result: new user will get email saying that his account was activated. in English!
(though email tokens will be generated for Russian language)
the research: the bug seems to be located in _user_mail_text function.
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 {
...
}
if ($replace) {
// We do not sanitize the token replacement, since the output of this
// replacement is intended for an e-mail message, not a web browser.
return token_replace($text, $variables, array('language' => $language, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE));
}
return $text;
}
so, variable_get('user_mail_' . $key, FALSE) will return English version of variable since admin uses website in English, while
token_replace() gets $language (which is the correct language of registered user)
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | drupal-i18n_variable_user_mail_text-1702468-12.patch | 751 bytes | rakesh.gectcr |
| #9 | interdiff-1702468-7-9.txt | 378 bytes | rakesh.gectcr |
| #9 | drupal-i18n_variable_user_mail_text-1702468-9.patch | 878 bytes | rakesh.gectcr |
| #7 | drupal-i18n_variable_user_mail_text-1702468-7.patch | 751 bytes | PascalAnimateur |
Comments
Comment #1
Rechi commentedI can confirm that issue.
I'm not a developer but maybe this could be a start:
Comment #2
Rechi commentedSorry that breaks the config form.
This could work:
Comment #3
claudio.rossini@rarolab.it commentedit works! thanks!
Comment #4
Rechi commentedDon't hack the core.
Use: mail_edit instead.
Just found that module a few days ago. Sorry for the core hacking.
Comment #5
truyenle commentedmail_edit does work it the link inside email still not aware of language. We need to have multilink module http://drupal.org/project/multilink to have these links arrive in the right languages.
THanks
Comment #6
qwckbrwnfx commentedsubscribe
Comment #6.0
qwckbrwnfx commentedbetter clarifications
Comment #7
PascalAnimateur commentedHere's a patch based on #2 that fixes the problem for Drupal 7.39 using i18n_variable.
Comment #8
tomyinhauser commentedWhy not translating the result from variable_get with t(), just as it does when no overrides were made on the default Drupal configuration?
Comment #9
rakesh.gectcrComment #10
rakesh.gectcrComment #11
PascalAnimateur commentedThe point of using i18n_variable is being able to override these strings per-language. So there's no need to return the translated text value via t() (which should never be used to translate user-entered strings, see https://groups.drupal.org/node/1827 for an explanation).
Simply check the variables you'd like to translate in /admin/config/regional/i18n/variable and the form for these settings should have language tabs to configure the value per-language.
Comment #12
rakesh.gectcrThat really making sense. I am reverting back the patch
Comment #13
tomyinhauser commentedThanks for the clarification, PascalAnimateur!
It is clear that t() has its limitations, and that i18n has proved to be a better alternative; it wouldn't be in D8 core otherwise. But using a contrib module inside D7 core? That sounds a little bit strange to me.
Comment #14
PascalAnimateur commentedIt only uses i18n_variable if it's enabled (see the module_exists call in the if statement). Don't want to sound pessimistic, but the patch probably won't be committed to 7.x core..
Comment #16
poker10 commentedThanks for reporting this.
I think this is a duplicate of #1197400: Use user's preferred language in system emails and as you can see there, it is replicable also without the i18n module. Lets keep the older issue open.