Forums

Multilang - how to translate the email template?

elaphe 13 Aug, 2009
Hello all.

I have a problem with translating the Email template.
I need to send the copy with answer to the submited email (via DynamicCC) in the language, the user filled it.
Now it's sending it only in the primary language, and I cannot find, where to translate it.

Using Joomla 1.5, Chronoforms 3.1 RC5, Joomfish V2.0.3

I use the Joomfish to translate the form - it works correctly and show the correct content depending on the language, but it send the email answer allways in primaru language
I've tried to translate it via Multilanguage settings on Chronoform page, but it's still sendign the email in primal language.
GreyHead 13 Aug, 2009
Hi elaphe,

As far as I know there is no multi-language support for the email template.

I think you will need to code your own template. You can check the user language and either use a PHP switch to display a version in the correct language; or you could use defines for the constant language and require a language file depending on the user's language.

Bob
jafeth 30 Sep, 2009

or you could use defines for the constant language and require a language file depending on the user's language.



Could You write sth more how to do that? Where to store this language constant and where to replace variables in PHP?
GreyHead 04 Oct, 2009
Hi jafeth,

The template code would look something like this:
<?php
$lang =& JFactory::getLanguage();
$LangTag = $lang->getTag();
switch ($lang->getTag()) {
  case 'en-GB':
  default:
?>
    <!-- English template html -->
<?php
    break;
  case 'fr-FR':
?>
    <!-- French template html -->
<?php
    break;
  case 'nl-NL':
?>
    <!-- Dutch template html -->
<?php
    break;
}
?>

Bob
jafeth 08 Oct, 2009
Thanks Bob for reply,

Could You suggest where is the place for this code. Maybe in Email Template field in form settings? But then I suppose I should switch off editor for this text area to place php code...

Regards
GreyHead 08 Oct, 2009
Hi jafeth,

Yes - exactly that.

Bob
jafeth 12 Oct, 2009
My client didnt accept this solution because they want to have ability to have html template in english also (our base langauage is polish).
So I wrote plugin which have two fields - english email template field and OnSubmit Code field. Before email sending plugin change value of this fields.

Here is this plugin. Maybe it will help someone:

<?php
defined('_JEXEC') or die('Restricted access'); 
global $mainframe;
require_once( $mainframe->getPath( 'class', 'com_chronocontact' ) );
// the class name must be the same as the file name without the .php at the end

$lang =& JFactory::getLanguage();
//print_r($lang);
require_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'languages'.DS.$lang->_lang.'.ext.php');

class cf_multi_email {
	//the next 3 fields must be defined for every plugin
	var $result_TITLE = "English Email Template";
	var $result_TOOLTIP = "Sets English Email Template";
	var $plugin_name = "cf_multi_email"; // must be the same as the class name
	var $event = "ONSUBMIT"; // must be defined and in Uppercase, should be ONSUBMIT or ONLOAD
	// the next function must exist and will have the backend config code
	function show_conf($row, $id, $form_id, $option){
	
	if(!$row->params){
			$row->params = "english=
			onsubmit=";
		}
	//$paramsvalues = mosParseParams( $row->params );
	$registry = new JRegistry();
	$registry->loadINI( $row->params );
	$paramsvalues = $registry->toObject( );
	$editor =& JFactory::getEditor();

	
	?>
	
	<form action="index2.php" method="post" name="adminForm" id="adminForm" class="adminForm">
	<table border="0" cellpadding="3" cellspacing="0">

		<tr style="background-color:#c9c9c9 ">
			<td><?php echo JHTML::_('tooltip', "Runt he plugin before or after the email, running it before the email may be necessary to include some data intot he email or even dont get it emailed" ); ?></td>
			<td><strong><?php echo "Run Before/After the Email ?"; ?>:</strong> </td>
			<td></td>
			<td>
			<select name="params[onsubmit]" id="params[onsubmit]">
				<option<?php if($paramsvalues->onsubmit == 'after_email'){ echo ' selected';} ?> value="after_email">After Email</option>
				<option<?php if($paramsvalues->onsubmit == 'before_email'){ echo ' selected';} ?> value="before_email">Before Email</option>
			</select>
		</td>
		</tr>
        
        <tr style="background-color:#c9c9c9 ">
			<td><?php echo JHTML::_('tooltip', "" ); ?></td>
			<td><strong><?php echo "English Email Template"; ?>:</strong> </td>
			<td></td>
			<td>
            	<?php echo $editor->display('extra1', $row->extra1 , '550', '400', '60', '20', false); ?>
            </td>
		</tr>
        
        <tr style="background-color:#c9c9c9 ">
			<td><?php echo JHTML::_('tooltip', "" ); ?></td>
			<td><strong><?php echo "On Submit Text Template"; ?>:</strong> </td>
			<td></td>
			<td>
            	<?php echo $editor->display('extra2', $row->extra2 , '550', '400', '60', '20', false); ?>
            </td>
		</tr>
        
	</table>
	<input type="hidden" name="id" value="<?php echo $id; ?>" />
	<input type="hidden" name="form_id" value="<?php echo $form_id; ?>" />
	<input type="hidden" name="name" value="<?php echo $this->plugin_name; ?>" />
	<input type="hidden" name="event" value="<?php echo $this->event; ?>" />
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="task" value="save_conf" />
	
	</form>
	<?php
	}
	// this function must exist and may not be changed unless you need to customize something
	function save_conf( $option ) {
		global $mainframe;
		$database =& JFactory::getDBO();		
		$post = JRequest::get( 'post' , JREQUEST_ALLOWRAW );
		
		$row =& JTable::getInstance('chronocontactplugins', 'Table'); 
		if (!$row->bind( $post )) {
			JError::raiseWarning(100, $row->getError());
			$mainframe->redirect( "index2.php?option=$option" );
		}
		
		///$params = mosGetParam( $_POST, 'params', '' );
		$params 	= JRequest::getVar( 'params', '', 'post', 'array', array(0) );
		if (is_array( $params )) {
			$txt = array();
			foreach ( $params as $k=>$v) {
				$txt[] = "$k=$v";
			}
			$row->params = implode( "\n", $txt );
		}
		if (!$row->store()) {
			JError::raiseWarning(100, $row->getError());
			$mainframe->redirect( "index2.php?option=$option" );
		}
		$mainframe->redirect( "index2.php?option=".$option, "Config Saved" );
	}
	
	function onsubmit( $option, $params , $row ) {
	
		jimport('joomla.user.helper');
		global $mainframe;
		$database =& JFactory::getDBO();

		// Check for request forgeries
		//JRequest::checkToken() or die( 'Invalid Token' );

		// Get required system objects
		$pathway 	=& $mainframe->getPathway();
		$config		=& JFactory::getConfig();
		$authorize	=& JFactory::getACL();
		$document   =& JFactory::getDocument();
		$language =& JFactory::getLanguage(); 
		$language->load('com_user');
		$LangTag = $language->getTag();
		
		if ($LangTag=='en-GB')
		{
			$MyForm =& CFChronoForm::getInstance();
			
			$MyForm->formrow->emailtemplate = $row->extra1;
			$MyForm->formrow->useremailtemplate = $row->extra1;
			
			$MyForm->formrow->onsubmitcode = $row->extra2;
			
			$MyEmails =& CFEMails::getInstance($MyForm->formrow->id);
			
			foreach($MyEmails->emails as $email)
			{
				$email->template = $row->extra1;
			}
			
		}
		
	}


}

?>
GreyHead 12 Oct, 2009
Hi jafeth,

Very nice, thank you.

Bob
pat01 10 Dec, 2009
If you're using Joom!Fish for translating your website, this might be helpful:

I have created two plugins for Joom!Fish. These Plugins allow you to translate
- forms created using ChronoForms
- email templates created by using ChronoForms

Please note, that the two plugins are new and I did not get a chance to test them very well. But I did test them and all tests went successfully.

I have added the plugins for free download on my site here:
Webpage for the plugins.

Please read the information there and try them on a test environment first.

Enjoy!

- Patrick, CFJFP
harkman 23 Apr, 2010
How can I switch off the WYSIWYG editor in Version 3.1?

I tried the user settings in Joomla, but this did not have any effect on the editor in ChronoForms.
pat01 23 Apr, 2010
Hi

Open the form, click on the tab Setup Emails, then click into the green box (for example on the email address) and after that change the value at Use Template editor to No.
Don't forgett to click on Apply below the settings and on Save on the top of the page.

Patrick
harkman 23 Apr, 2010
Thank you Patrick,

That's exactly what I found myself some minutes after posting the question.

Jürgen
harkman 23 Apr, 2010
@GreyHead

The template code would look something like this



You have a idea how to translate the mail subject too?
GreyHead 23 Apr, 2010
Hi harkman,

A bit crude but you could use a Dynamic subject and switch it in the OnSubmit Before box; or you could put it into a hidden field and translate it with the Mulit-language plugin.

Bob

I'll make a note to see if we can't get the plugin to translate this - it may not be possible though :-(
piotr_cz 08 Oct, 2010
Hi Patrick,
thank you for the JoomFish files. I started using the email translation element yesterday and just noticed that the translation gets wiped out every time I save original form in Chornoform.
I have no idea where the issue might be (maybe chronoforms destroys the form instance & recreates it?); get in touch in case you need details for debugging.

Joomla 1.5.20 + MooTools 1.2 upgrade plugin on
ChronoForms 3.1 RC5.5
Joom!Fish 2.0.4

btw: I haven't ever had the CF multilanguage plugin on


UPDATE:
the problem is that everytime you save a form, email templates receive new 'emailid' which is used as a reference field for JoomFish content element (table #__chrono_contact_emails).
So it seems impossible to link email translation and CF form together.
I wish emailid would have stable number :/


If you're using Joom!Fish for translating your website, this might be helpful:

I have created two plugins for Joom!Fish. These Plugins allow you to translate
- forms created using ChronoForms
- email templates created by using ChronoForms

Please note, that the two plugins are new and I did not get a chance to test them very well. But I did test them and all tests went successfully.

I have added the plugins for free download on my site here:
Webpage for the plugins.

Please read the information there and try them on a test environment first.

Enjoy!

- Patrick

pat01 09 Oct, 2010
Hi

Thank you for your feedback and I'm sorry for my late reply.

I will look at it this weekend if I get a chance, otherwise the next week. I hope for your patience.

Regards
Patrick
pat01 10 Oct, 2010
Hi Piotr

I did fix the problem.

Please do the following:

1) Download the file chrono_contact_emails.zip and unzip it in a directory on your Computer
2) Upload the file chrono_contact_emails.php into the folder
/administrator/components/com_joomfish/contentelements/

Overwrite the existing file.

3) Open your original email template and save it.
4) Go to Joom!Fish and translate the email template.

Important: Every time you make changes to the original email tamplate, you must translate it again! Most of all, make sure you copy the Email_ID there, so it matches the original one. As you did figure out correctly, this ID changes every time the original email template gets saved.

Please let me know if it works for you, thank you very much.

Regards
Patrick
GreyHead 10 Oct, 2010
Hi Patrick,

Thanks for the plug-ins.

I looked at the ChronoForms code to see if there was an easy fix for the Emails. Unfortunately Max has set the save up to delete all the existing emails linked to a form and then create new ones. This could be changed but it's not one-minute hack :-(

Bob
pinochico 05 Nov, 2010
Hi Patrick,

great plugin


But if i have two emails with 1 form (one for admin and 1 for customer), both email view as one and i can not translate

I have two emails template in joomfish -
if I click on the first (etc. emailid=67) - its ok - translate
if I click on the second ((etc. emailid=68 - not the same emailid) - I view first (id=67)

It's bug?

Can me help any?

Chronoforms Email Templates 1.0.6
ChronoForms 3.1 RC5.5
pat01 06 Nov, 2010
Hi Rudolf

I never used the Plugin with two Email templates within one form :?

Of course, they should be different by their ID. I'll have a look at it.

Regards
Patrick
This topic is locked and no more replies can be posted.