i18n_user.module 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * User mail translation module.
  5. */
  6. /**
  7. * Implements hook_mail_alter().
  8. */
  9. function i18n_user_mail_alter(&$message) {
  10. if ($message['module'] == 'user') {
  11. $language = $message['language'];
  12. $variables = array('user' => $message['params']['account']);
  13. $key = $message['key'];
  14. $components = array('subject', 'body');
  15. foreach ($components as $component) {
  16. $text = i18n_variable_get('user_mail_' . $key . '_' . $component, $language->language, FALSE);
  17. if ($text) {
  18. $text = token_replace($text, $variables, array('language' => $language, 'callback' => 'i18n_user_user_mail_tokens', 'sanitize' => FALSE));
  19. switch ($component) {
  20. case 'subject':
  21. $message[$component] = $text;
  22. break;
  23. case 'body':
  24. $message[$component] = array($text);
  25. break;
  26. }
  27. }
  28. }
  29. }
  30. }
  31. /**
  32. * Overrides user_mail_tokens().
  33. *
  34. * @see i18n_user_user_tokens_alter()
  35. * @see user_mail_tokens()
  36. */
  37. function i18n_user_user_mail_tokens(&$replacements, $data, $options) {
  38. if (isset($data['user'])) {
  39. $replacements['[user:one-time-login-url]'] = i18n_user_user_pass_reset_url($data['user']);
  40. $replacements['[user:cancel-url]'] = i18n_user_user_cancel_url($data['user']);
  41. }
  42. }
  43. /**
  44. * Overrides user_pass_reset_url().
  45. * Generates a unique and localized URL for a user to login and reset their password.
  46. *
  47. * @see user_pass_reset_url().
  48. */
  49. function i18n_user_user_pass_reset_url($account) {
  50. $timestamp = REQUEST_TIME;
  51. return url("user/reset/$account->uid/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE, 'language' => i18n_language($account->language)));
  52. }
  53. /**
  54. * Overrides user_pass_cancel_url().
  55. * Generates a localized URL to confirm an account cancellation request.
  56. *
  57. * @see i18n_user_user_cancel_url()
  58. */
  59. function i18n_user_user_cancel_url($account) {
  60. $timestamp = REQUEST_TIME;
  61. return url("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login), array('absolute' => TRUE, 'language' => i18n_language($account->language)));
  62. }