I wanted to share something that took me a while. I have discovered today Multilingual Variables. Hurray!

Actually, if you have i18n module installed, there's an easy way to translate OG mail templates. Here's how to for OG 2.0:

1) Edit your settings.php and add the $conf['i18n_variables'] array as described here: Multilingual Variables.

2) Append to the list of variables the following list:

  // Organic Groups.
  'og_new_node_subject',
  'og_new_node_body',
  'og_admin_email_subject',
  'og_admin_email_body',
  'og_approve_user_subject',
  'og_approve_user_body',
  'og_deny_user_subject',
  'og_deny_user_body',
  'og_invite_user_subject',
  'og_invite_user_body',
  'og_request_user_subject',
  'og_request_user_body',
  'og_new_admin_subject',
  'og_new_admin_body',

3) Now, visit admin/og/og in any language to configure OG email templates for that language. ie. saving this page from es/admin/og/og will save your email templates in spanish version of OG variables. save from fr/admin/og/og to save them in french, and so on.

This could be obvious for some, but it took me a while. Maybe this could be documented in the OG readme? <--- feature request or task?

BTW, if you're looking for a way to translate mail templates in Notifications/Messaging, then take a look at #265680: Translation of email templates . Needs testing and feedback! :)

Comments

crea’s picture

Subscribing

span’s picture

Please remove.

danny_joris’s picture

Hi,

I've used this technique and I can translate the email messages, but the translations aren't actually used when sending emails to -say- a french user.

For invitation emails I managed to use the translated variable in the email using hook_mail_alter() , but for the other messages it didn't work. The other messages seem to be pre-generated by messages/notifications module, which add a header and footer to them.

Normally $message would contain the strings/values which I can use to replace @body and @description tokens with, but the $message variable of the emails that are modified by messages/notifications don't contain these strings/values...

How did this work for you, Markus? Did you use the messages & notifications modules?

<?php
function caubo_bilingual_mail_alter(&$message) {

  switch($message['id']) {
  
  case "og_invite_link_invite_to_group":
      $user_language = _caubo_get_language_from_mail($message['to']);
      if($user_language == 'fr') {

      		// set variables to create the full link with token. ($group_url)
		$group_id = $message['params']['invitation']->group_nid;
		$user_id = $message['params']['invitation']->uid;
		$key = $message['params']['invitation']->token;
		
		$group_url = 'http://caubo.ca/fr/group/'.$group_id.'/join/'.$user_id.'/'.$key;
        $group_title = $message['params']['group']->title;
		$group_description = $message['params']['group']->body;
		$group_message = $message['params']['additional_message'];
		
		$myBody = i18n_variable_get('og_invite_user_body', 'fr');
		
		$myBody = str_replace('@group', $group_title, $myBody);
		$myBody = str_replace('@description', $group_description, $myBody);
		$myBody = str_replace('!group_url', $group_url, $myBody);
		$myBody = str_replace('@body', $group_message, $myBody);

		$myBody = check_markup($myBody);
		
        if (is_array($message['body'])) {
          $message['body'][0] = $myBody;
        }else{
          $message['body'] = $myBody;
        }
        
	$message['subject'] = i18n_variable_get('og_invite_user_subject', 'fr');
		
      }

      break;
  }
  dsm($message);
  //dsm($message['id']);
}
?>
claudiu.cristea’s picture

Status: Active » Closed (outdated)

This version of Drupal is not supported anymore. If this is still an issue in the 8.x-1.x branch, please open a new up-to-date ticket. Closing.