Hello,
is there already a way to translate the body and subject text? I looked into it but it seems that the module is not implementing hook_variable_info() to use variable translation.
Does the module use a differen translation method or could translation be integrated?
Thank you!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Rechi’s picture

I made a dirty fix to implement variable_info(), you have to use the variable admin module to set the body and subject text. I hope this may be a start for someone with more experience.

ptmkenny’s picture

Category: support » feature
Status: Active » Needs review
GiorgosK’s picture

Issue summary: View changes

it would be great to implement this

sysosmaster’s picture

Version: 7.x-2.8 » 7.x-2.x-dev
Issue tags: +i18n
FileSize
2.82 KB

Previous patch was not working, I rewrote a patch that utilizes the i18n_variable and retrieves this when the module is active.

sysosmaster’s picture

re factored patch to no longer use custom code but make use of the i18n_variable and the variable_info hook.
To enable the new i18n variable after patching go to /admin/config/regional/i18n/variable and enable them in the 'Other' tab.

sysosmaster’s picture

Fixed: sending the one time login mail in the user preferred language.

florisg’s picture

Verified that patch #6 works.
Also against 7.x-2.9 of login_one_time

Be sure to clear cache.
Then go to /admin/config/regional/i18n/variable and enable translation under the 'Other' tab
Now you can translate under /admin/config/people/accounts. (note the 'This is a multilingual variable.' label under the fields

Finally one time login messages are in the user's preferred language :)

  • Maedi committed 16a82bc on 7.x-2.x authored by sysosmaster
    Issue #1751336 by sysosmaster, Rechi: Translation of body and subject
    
Maedi’s picture

Status: Needs review » Fixed

A patch becomes a feature, thanks. Reopen if any issues.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

AgentJay’s picture

This isn't working for me, I'm getting this error:

Trying to get property of non-object in login_one_time_mail_text() (line 630 of /srv/www/biopama/sites/all/modules/login_one_time/login_one_time.module)

AgentJay’s picture

Status: Closed (fixed) » Active
sysosmaster’s picture

@Agentjay Just posting "this does not work" does not qualify as a useful comment.

Please Supply a proper Bug report if you expect any sort of assistance.

Things to check for:

  • Have you actually patch your module.
  • What Version of php are you using.
  • Are you actually patching against the version the patch was written for.

And to further deepen your reply, consider making a NEW issue instead of reopening one from 8 months ago.

xelat’s picture

@Agentjay and @sysosmaster, I can replicate this with 2.10 (line 630) and dev (line 646).


    $langcode = isset($language) ? $language->language : NULL;
    $options = array();
    if (!is_null($langcode)) {
      $options['langcode'] = $langcode;
    }

In the first line above, the $language is just a string and does not have the 'language' property and thus generating the warning.

sysosmaster’s picture

code Snippet (bigger to see what is going on);
Line 1~596

/**
 * Retrieve the Global (or user) Language, seperated method to not polute the language variable in the parameter list.
 */
function _login_one_time_getLanguage(){
    global $language ;
  return $language->language;
}

/**
 * Returns a mail string for a variable name.
 *
 * Used by user_mail() and the settings forms to retrieve strings.
 */
function login_one_time_mail_text($key, $path = NULL, $language = NULL, $variables = array()) {

  if (empty($language)) {
    $language = _login_one_time_getLanguage();
  }
  if (is_object($language)) {
    $language = $language->language;
  }
  if (module_exists("i18n_variable")) {
    $admin_setting = i18n_variable_get($key, $language, FALSE);
  }
  else {
    $admin_setting = variable_get($key, FALSE);
  }

  if ($admin_setting) {
   // An admin setting overrides the default string.
   return strtr($admin_setting, $variables);
  }
  else {
    $langcode = isset($language) ? $language->language : NULL;
    $options = array();
    if (!is_null($langcode)) {
      $options['langcode'] = $langcode;
    }
    // No override, return default string.
    switch ($key) {
      case 'login_one_time_subject':
        return t('One-time login link for [user:name] at [site:name]', $variables, $options);
      case 'login_one_time_body':
        return t("[user:name],\n\nA request to give you a one-time login for your account has been made at [site:name].\n\nYou may now log in to [site:url-brief] by clicking on this link or copying and pasting it in your browser:\n\n[user:login-one-time]\n\nThis is a one-time login, so it can be used only once.  It expires in two weeks and nothing will happen if it's not used.\n\n--  [site:name] team", $variables, $options);
    }
  }
}

Line 644

So if you use an i18n Replacement all works as intended. If you have a Admin setting set it works as intended. but if you trust the default it can work diffrently. (the test for object shouuld be included there again)