Is it possible to use localized strings in custom e-mail templates

carramone 25 May, 2020
Hi
I use a custom email template to hide fields that are empty from the email that is being sent. I use the following code
<?php if(!empty($this->data["errand"])): ?>
<p><strong>{l:errand_title}:</strong>{data:errand}</p>
<?php endif; ?>
Is it possible to replace
{data:errand}
with something that will return the translated string instead? In the above example it is just data from a drop down that I'm trycing to retrieve. I do however also have a few arrays (check box fields) that I would like to retrieve the localized strings for instead of the placholder.
<?php if(!empty($this->data["what_console"])): ?>
<tr style="background-color:#fafafb">
<td style="padding:7px;"><strong>{l:what_console_title}</strong></td>
<td style="padding:7px;">{data:what_console}</td>
</tr>
<?php endif; ?>
So I wonder if it is possible to replace
{data:what_console}
with something that will take the localizations into consideration?

Thank you very much for your time.
Best regards
Max_admin 25 May, 2020
the default email content contains the localized strings, yes or not ?

I mean when you have a dropdown/checkboxes, the options text is sent, yes ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
carramone 25 May, 2020
Hi
When I autogenerate the email it uses the translations. All the {l:...} in my custom body also works. I just don’t know how to retrieve and echo the translations for {data: ...} .

best regards
Max_admin 25 May, 2020
but the problem is only for fields with options, correct ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
carramone 26 May, 2020
Hi
That is correct. It is the fields where I have made options to choose from. These options are translated. For an example, I have a check box field and it looks something like this:

option1={l:option_one}
option2={l:option_two}
option3={l:option_three}

and the drop downs look the same. Except I have an empty option at the top:
no_option=
option1={l:option_one}
...etc etc

Best regards
Max_admin 01 Jun, 2020
Since you need that because you are switching the values in the email body, I have got a solution for this in v7 beta4:
http://www.chronoengine.com/blog

Each field has an "Email conditions" behavior, this let's you add conditions to control the field value insertion in the email, I suggest that you try it and check yourself, do not hesitate to post questions!

but for the issue here, I do not think it will be possible to reference the options labels text in the email, unless you do that with PHP, like if value == x then show the {l:option_text}
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
carramone 02 Jun, 2020
Hi
I don't think I understand. My email presents the correct labels and values. For the labels it was easy to present the translated versions with
{l:what_console_title}
but the values are also presented correctly, I just don't know how to show the translated versions. Setting up some php to do it is what I was asking for. But making a snippet for each of the fields seem a bit tedious and prone to typos if I need to enter all the options. Is it the best way?

That would mean I need to do something like this for each field.
<?php if(!empty($this->data["errand"])): ?>
<p><strong>{l:service_what_type_of_errand}:</strong>
if ({data:errand} == "option1") echo "{l:option1} <br>";
if ({data:errand} == "option2") echo "{l:option2} <br>";
if ({data:errand} == "option3") echo "{l:option3} <br>";
</p> <?php endif; ?>
is this correct? And is this something that can't be done in chronoforms6? I'm wondering as you asked me to install beta 4 of chronoforms 7?

I tried to install the beta 4 but I can't save my settings. I get: "Your Global Email settings are not set, please save the ChronoForms7 Global Settings first!".

Best regards, and thank you again for helping out.
Max_admin 02 Jun, 2020
correct, you will need to use that code, at least for fields with options!

v7 has an "Email conditions" behavior where you can do the check in the field settings, what is the problem when you go to the settings page then click "Save" ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
carramone 02 Jun, 2020
Thank you.
I must be thick or something, I don't understand what you mean by email conditions? Can version 7 show the localized strings without php code in the email template?

The problem when I click save is that I get the messeage "Your Global Email settings are not set, please save the ChronoForms7 Global Settings first!" and it looks like the email address is removed and then added again. But that is probably just a css animation that has nothing to do with anything. I have tried different addresses, but only the one availible by the drop down in accepted.. But not fully accepted I guess, since the page won't save.

Best regards,
Max_admin 02 Jun, 2020
Ok, there was a problem with the beta4, please download it again then install and test the settings issue, it should be fixed!

Yes, in v7 you can switch the field on/off the email body in the field settings, no php, just enable and configure the "Email conditions" behavior under the Field settings under the "Data" behaviors!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
carramone 04 Jun, 2020
Thank you.

I downloaded the new beta 4 and yes, now it works. I haven't tested it out however since I could not import my old forms, and I can't take the time to convert the forms at the moment. Especially since it is still a beta... so, I'm astuck with making it work in v6 at the moment.

Anyway, I have updated my code in the email template to this[pre]<?php if(!empty($this->data["errand"])): ?>
<p><strong>{l:service_what_type_of_errand}:</strong>

<?php if(($this->data["errand"])==service_question): ?>{l:service_repairs}<?php endif; ?>
<?php if(($this->data["errand"])==generic_question): ?>{l:other_errand}<?php endif; ?>[br]<?php if(($this->data["errand"])==status_question): ?>{l:status_question}<?php endif; ?>[br][br]</p>[br] <?php endif; ?>[/pre]
and this works, I get the translated strings for my dropdowns, so yay! [br][br]I do understand that there are more effective ways to code this, and I'm open to suggestions.[br][br]Also, I have arrays ... and I don't know how to work with them. This is my code that generates the label, and then the list from the array:
<?php if(!empty($this->data["what_accessory"])): ?>
<tr style="background-color:#fafafb">
<td style="padding:7px;"><strong>{l:what_accessory}</strong></td>
<td style="padding:7px;">{data:what_accessory}</td>
</tr>
<?php endif; ?>
I would like to replace the
{data:what_accessory}
with code that will present the translated strings in the email. But I don't know how to.

Best regards,
This topic is locked and no more replies can be posted.