FAQs

How can I translate emails?

Written
The ChronoForms Email action allows you to create an email template but there is only one template and there is no obvious way to support different languages. This FAQ suggests some ways to handle translations. 

The Multi-language action

ChronoForms has Multi-language actions in CFv4 (or the Locale tab in CFv5) which will work to translate language used in the Form HTML - it's not obvious but they will also work to translate language in the Email template too.
To use them you need to add Multi-language actions to the event with the Email action, usually the On Submit event. You need one copy of the Multi-language action for each language in use on your site.
Open one of the actions, set the Language tag e.g. en-GB or fr-FR and add strings to be translated. 
While the action will try to translate any string I recommend that you use distinctive strings to avoid problems, for example:
##THANKS##=Thanks for sending your question.
##REPLY##=We'll reply to your question as soon as we can.
This shows clearly where you have missing translations and avoids problems that can easily arise with typos between languages.
This method works well if the email template is simple, especially if it is similar to the Form HTML as you will already have languages strings that you can copy and paste. However, it will only handle language strings on a single line without paragraph breaks. 
If your template is more complex then there are other approaches that you can use. For the most part these use PHP and so require that the Rich Text Editor on the Template tab is turned off. 

Use a switch statement

If you have languages that are quite different then it may well help to have completely separate templates:
<?php
$lang =& JFactory::getLanguage();
$tag =& $lang->getTag();
switch ($tag) {
  case 'en-GB':
  default:
    echo "<div>Hi {username},<br />Thank you for sending your question '{question}'.<br />We'll reply as soon as we can.<br /><br />The XYZ site admin</div>";
    break;
  case 'fr-FR':
    echo "<div>Salut {username}, <br /> Merci d'envoyer votre question '{question}'. <br /> Nous vous répondrons dès que possible. <br /> <br /> L'administrateur du site XYZ</div>";
    break;
}
?>
Notice that you can still insert form data using the {input_name} curly brackets syntax.

Include language files

This works well but can still get complex if the email is long. A third appraoch is to adapt this code to include an external file depending on the language. So we might include email_template.en-GB.php for English and email_template.fr-FR.php for French.
<?php
$lang =& JFactory::getLanguage();
$tag =& $lang->getTag();
include (JPATH_SITE."/components/com_chronoforms/includes/{$form->form_details->name}/email_template.{$tag}.php");
?>
With the included file holding the PHP to create the language template:

	
<?php
echo "<div>Salut {username}, <br /> Merci d'envoyer votre question '{question}'. <br /> Nous vous répondrons dès que possible. <br /><br /> L'administrateur du site XYZ</div>";
?>
Or, using HTML without the 'echo' - note the reversed PHP tags to keep the code integrity. 
?>
<div>Hi {username},<br />Thank you for sending your question '{question}'.<br />We'll reply as soon as we can.<br /><br />The XYZ site admin</div>
<?php 

For even more advanced templates you can 'mix and match' these methods - maybe including some paragraphs from external files and using the ChronoForms Multi-language actions in others.