Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
I have a short question: Is the password expiration email translatable ?
I put a test string as message but I can't find it on admin/config/regional/translate/translate and I don't find t() function around the subject or the email body.
Thanks for any help.
Comments
Comment #1
AohRveTPV CreditAttribution: AohRveTPV commentedIt looks to me like the default e-mail subject (
expire_warning_email_subject
) is not translatable currently. The body (expire_warning_email_message
) looks to be empty, so there is nothing to translate.Recategorizing as a bug since the default subject should be translatable.
I have never really used translations, but my understanding is if you configure a custom e-mail subject or body, it would be stored in a variable, and you would need to use "Variable translation" in the Internationalization module to translate the variable. So we need only to make the default strings translatable. Please correct me if wrong.
Comment #2
GrimreaperTalking about translations, I see there is empty form field description with empty t(''), which is useless.
For the default value, I think using a t() function at this level will be good. I didn't test.
But after overriding using custom values. It is saved in the database with the policies config, so not in a variable, and it is not translatable. That why I asked the question.
For strings in t() function and variables, I know how to translate but for strings in configuration objects I didn't know, I have not experienced before.
Comment #3
GrimreaperI have taken a look at how rules managed to translate its rules.
In rules_i18n, it uses the i18n_string API. But it needs to indicate to the i18n_string the object to manage. I don't figure if it will be a lot of work or not for password policy to have the same think.
Comment #4
AohRveTPV CreditAttribution: AohRveTPV commentedI understand the problem now. These strings aren't stored in Drupal variables so they cannot be translated by Variable Translation. I am not familiar with the Ctools APIs and do not know either how these configurations are typically translated.
The i18n_string API looks promising. Thanks for sharing.
Patches would be welcome. My current focus is on fixing bugs in 1.x.
Comment #5
nicrodgersThis patch makes the warning email translatable, providing you have i18n_variable enabled.
I've had to change the settings form to use system_settings_form, so that the i18n_variable module can add it's language selection interface in.
Comment #7
nicrodgersWhoops, forgot to change the version. We are using the stable version in prod.
Comment #8
nicrodgersComment #9
prashant.kabade CreditAttribution: prashant.kabade commentedI have achieved this using another contrib module . https://www.drupal.org/project/mail_edit
Comment #10
AohRveTPV CreditAttribution: AohRveTPV commentedIn 7.x-1.x, the mail subject and body is handled the same as in the core User module.
user.module:
password_policy.module:
Both just use
variable_get()
when a custom mail subject and body has been set. The User module mail must be translatable somehow without implementinghook_variable_info()
. Why then does Password Policy need to implementhook_variable_info()
when User module does not?Comment #11
nicrodgershi @AohRveTPV
If you only use D7 core, then no, the mail variables are not translatable unless you install some contrib modules.
To translate them, you install i18n and enable i18n_variable. This depends in the contrib module 'variable'. It's the variable contrib module that makes the core variables translatable, see http://cgit.drupalcode.org/variable/tree/includes/user.variable.inc?id=7... - basically by implementing hook_variable_info.
attached is a re-rolled patch for latest 7.x-1.x-dev
Comment #12
AohRveTPV CreditAttribution: AohRveTPV commentedThanks for explaining.
Minor changes after a first-pass, superficial review:
- Changed
function_exists()
tomodule_exists()
. It seems to me likemodule_exists()
is kind of self-documenting and avoids the need for an inline comment explaining why we are usingfunction_exists()
?- Fixed indentation on a line.
- Removed some trailing spaces.
Two things I'm not sure on:
- Is it OK to call both
variable_del()
andvariable_delete()
for the same variables (as is done in the reset callback)?- Does
variable_delete()
need to be called byhook_uninstall()
?I'm also wondering how the variable modules can translate the core mails without modifying core. If it's not necessary to modify core to translate the core mails, why is it necessary to modify Password Policy to translate its mails? Don't necessarily need an answer on that, just something I'm wondering.
Comment #13
AohRveTPV CreditAttribution: AohRveTPV commentedAlso I believe "Email" should be "E-mail" in Drupal 7. Or at least for consistency with the rest of Password Policy. It's "Email" in Drupal 8. I'll update patch later.
Comment #14
AohRveTPV CreditAttribution: AohRveTPV commentedMinor changes:
- Fixed two Coder errors due to consecutive blank lines.
- Changed "email" to "e-mail" per Drupal 7 convention.
- Changed "e-mail body" to just "body" for consistency with "subject".
Comment #15
nicrodgersHi @AohRveTPV - thanks for your work on this and sorry for taking a while to come back to you. I'm working on a D8 project at the mo, and don't have much time spare for D7 stuff,.
I can't find any evidence to suggest issues with variable_del and variable_delete being called at the same time, but I think you're right that it'd probably be better to refactor the reset code so the deletion of those two variables are in an if/else block.
About uninstallation, from what I can see, variables set using variable API are automatically deleted by the variable module when the *variable* module is uninstalled. So yes, it's probably worth adding a variable_delete call in password_policy's hook_uninstall to tidy things up.
Re your question/pondering about how variable module can translate core without modifying core, that's sort of the point of the module. There's specific code within the variable module that makes core variables translatable. Take a look at that user.variable.inc file to see how it works. As well as making core variables translatable, the purpose of the variable module is to enable contrib modules to also have their variables translated. To do that, you must implement hook_variable_info (as per this patch). More info here: http://cgit.drupalcode.org/variable/tree/README.txt?id=7.x-1.x
Sorry I've not had a chance to create an updated patch to do this stuff, I will try to do that in a few weeks after this current project, if it hasn't been picked up in the meantime.
Comment #16
AohRveTPV CreditAttribution: AohRveTPV commentedGenerally I do not commit patches that integrate directly with other contributed modules because I feel it produces spaghetti code. (It adds unnecessary coupling that makes the code complex and hard to understand/maintain/test.) Usually there's a way to integrate without adding module-specific code. But I think an exception is warranted here since the module is otherwise not internationalizable.
It might be better to move the
hook_variable_info()
implementation to password_policy.variable.inc. password_policy.module is overly long. Will update patch to do this if I get a chance.Comment #17
AohRveTPV CreditAttribution: AohRveTPV commentednicrodgers, did you try using the 'mail_text' variable type? I was just working on this and it looks like other mails use that type. Here's what I have so far (not working):
Comment #18
AohRveTPV CreditAttribution: AohRveTPV commentedUntested patch that moves
hook_variable_info()
implementation topassword_policy.variable.inc
. Also changes the variables to type'mail_text'
. There seems to be no need to set the'localize'
key because it is set TRUE for the'mail_text'
variable type in the Variable module.Comment #19
AohRveTPV CreditAttribution: AohRveTPV commentedChanges:
- Made variable description more consistent with fields descriptions, and more consistent with User module email descriptions. Now shows list of available variables.
- Changed
module_exists('variable')
back tofunction_exists('variable_delete')
. This seems more defensive against possible Variable module API changes, however unlikely.- Added function to eliminate duplicate definitions of warning email tokens help.
I tested this manually with two languages, and verified the correct warning e-mail translation was sent according to the user's chosen language.
If this passes testing, and no one sees any issues with this patch, will plan to commit soon.
Comment #21
AohRveTPV CreditAttribution: AohRveTPV commentedComment #22
AohRveTPV CreditAttribution: AohRveTPV commentedFixed bug found in previous commit.
Comment #24
AohRveTPV CreditAttribution: AohRveTPV commentedSetting back to 7.x-2.x, where this bug still exists.