You can translate invite email subject properly, since the code for getting subject looks like this:

function invite_get_subject($args = array()) {
  $subject = variable_get('invite_subject', t('[invite:inviter-raw] has sent you an invite!'));
  return token_replace($subject, invite_token_data($args));
}

So, if you submit invite settings, the default value of string wrapped by t() will never be called.
And the "invite_subject" variable will hold one value for all languages.
The correct way to fix it is to use variable module API to expose invite variables for translation.

Comments

miqmago’s picture

It happens the same with _invite_get_email_template()
For me this patch resolves the issue. The main point is to change the t() position to variable_get:

Index: invite.module
===================================================================
--- invite.module	(revision 2)
+++ invite.module	(working copy)
@@ -1551,14 +1551,14 @@
  *   The localized e-mail body.
  */
 function _invite_get_mail_template() {
-  $template = t("[invite:inviter-raw] has invited you to join [site:name] at [site:url].
+  $template = "[invite:inviter-raw] has invited you to join [site:name] at [site:url].
 
 To become a member of [site:name], click the link below or paste it into the address bar of your browser.
 
 [invite:join-link]
-");
+";
 
-  return variable_get('invite_default_mail_template', $template);
+  return t(variable_get('invite_default_mail_template', $template));
 }
 
 /**
basillic’s picture

The integration with the Variable module seems to have been modified since the issue submission date.

Variables must be declared in a separated file (invite.variable.inc). Here the code I've written to use Variable with Invite :

<?php

/**
 * @file
 * Definition of variables for Variable API module.
 */

/**
 * Implements hook_variable_info().
 */
function invite_variable_info($options) {
  $variables['invite_subject'] = array(
    'type' => 'string',
    'title' => t('Invite email subject', array(), $options),
    'default' => t('[invite:inviter-raw] has sent you an invite!'),
    'description' => t('The email default subject'),
    'required' => TRUE,
    'group' => 'invite',
    'localize' => TRUE
  );

  $variables['invite_default_mail_template'] = array(
    'type' => 'string',
    'title' => t('Mail template', array(), $options),
    'default' => _invite_get_mail_template(),
    'description' => t('The email default content'),
    'required' => TRUE,
    'group' => 'invite',
    'localize' => TRUE
  );

  $variables['invite_page_title'] = array(
  		'type' => 'string',
  		'title' => t('Page title', array(), $options),
  		'default' => t('Invite a friend'),
  		'description' => t('The invite page title'),
  		'required' => TRUE,
  		'group' => 'invite',
  		'localize' => TRUE
  );

  return $variables;
}

/**
 * Implements hook_variable_group_info().
 */
function invite_variable_group_info() {
  $groups['invite'] = array(
    'title' => t('Invite'),
    'description' => t('Configure the Invite module.'),
    'access' => 'administer site configuration',
    'path' => array('admin/config/people/invite'),
  );

  return $groups;
}

Please give me a feedback for this hack.

passengerabcd’s picture

I patched invite 7.x-2.1-beta2 with comment #1 and #2, and it's working great. Thanks for your sharing, miqmago & basilic. Hope it can be merged into future release.

benjifisher’s picture

Version: 7.x-2.x-dev » 7.x-4.0-beta2
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.05 KB

Using Invite 7.x-4.0-beta2, I do not run into this issue with the default configuration, but when I check off "Invite By Mail" as the Sending method at admin/structure/invite-types/manage/invite_by_email, suddenly my subject and body are not translated. :-( It seems that the problem has gone away in the main Invite module, but still exists in the invite_by_email submodule.

My solution is similar to the one @miqmago suggested in #1 above: put variable_get() inside t(). This has a disadvantage that the strings will not be extracted when you generate PO files. (This is why you are supposed to use t() with literal strings.) For the site I am working on, we manage the PO files and keep them in a git repository, so this is not too bad.

Integrating with the Variable and i18n_variable modules, as in @basillic's comment #2 above, is another approach. It will work better for some sites, but I do not know how to manage translations using PO files and this approach.

I have attached a little patch.

basillic’s picture

@benjifisher, to clarify my method : I don't use PO files to translate realm variables (i18n_variables). I translate realm variables with the admin interface (on my dev site) and use the module features_translations to deploy all the translated variables to the testing and production sites.

ipwa’s picture

StatusFileSize
new856 bytes

Adding patch for 7.x-2.x-dev based on #3.

ipwa’s picture

StatusFileSize
new2.46 KB

Adding new correct patch that also adds file from #2

alfthecat’s picture

Patch from #7 fails

patching file invite.module
Hunk #1 FAILED at 1571.
Hunk #2 FAILED at 1580.
ckng’s picture

Version: 7.x-4.0-beta2 » 7.x-4.x-dev
Status: Needs review » Needs work

For 7.x-4.x (patch #4), would prefer Variable integration via i18n.

7.x-2.x is currently not supported and no maintainer.

MorinLuc0’s picture

StatusFileSize
new2.31 KB

@basillic has it right you should not be translating a variable.

Rolling his code in a patch after fixing a few items. (7.x-4.0-beta2) release.

SpartyDan’s picture

Status: Needs work » Needs review