Translation of e-mail templates: creating and translating the e-mails

We will add a new form in the Details page to share the event to a friend. The first step is to declare your e-mail template.

  1. To declare your e-mail template, create a new [extension_path]/etc/ email_templates.xml file and add the following code:

<?xml version=”1.0″?> <configxmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi: noNamespaceSchemaLocation=”urn:magento:module:Magento_Email:etc/ email_templates.xsd”> <template id=”ticketblaster_email_email_template” label=”Share Form” file=”share_form.html” type=”text” module=”Blackbird_ TicketBlaster” area=”adminhtml”/> </config>

  1. Next, create the corresponding template by creating the [extension_path]/ view/adminhtml/email/share_form.html file and add the following code:

    <!–@subject Share Form@–> <!–@vars { “varpost.email”:”Sharer Email”, “varevent.title”:”Event Title”, “varevent.venue”:”Event Venue” } @–><p>{{trans “Your friend %email is sharing an event with you:” email=$post.email}}</p> {{trans “Title: %title” title=$event.title}}<br/> {{trans “Venue: %venue” venue=$event.venue}}<br/><p>{{trans “View the detailed page: %url” url=$event.url}}</p>

 

The e-mail template is ready; we will also add the ability to change it in the system configuration and allow users to determine the sender’s e-mail and name:

  1. Create the [extension_path]/etc/adminhtml/system.xml file and add the following code:

<?xml version=”1.0″?> <configxmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi: noNamespaceSchemaLocation=”urn:magento:module:Magento_Config:etc/ system_file.xsd”>
<system> <section id=”ticketblaster” translate=”label” type=”text” sortOrder=”100″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″> <label>Ticket Blaster</label> <tab>general</tab> <resource>Blackbird_TicketBlaster::event</resource> <group id=”email” translate=”label” type=”text” sortOrder=”50″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″> <label>Email Options</label> <field id=”recipient_email” translate=”label” type=”text” sortOrder=”10″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″> <label>Send Emails To</label> <validate>validate-email</validate> </field> <field id=”sender_email_identity” translate=”label” type=”select” sortOrder=”20″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″> <label>Email Sender</label> <source_model>Magento\Config\Model\Config\Source\Email\Identity</ source_model> </field> <field id=”email_template” translate=”label comment” type=”select” sortOrder=”30″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″> <label>Email Template</label> <comment>Email template chosen based on theme fallback when “Default” option is selected.</comment> <source_model>Magento\Config\Model\Config\Source\Email\Template</ source_model> </field> </group> </section> </system> </config>

  1. Create the [extension_path]/etc/config.xml file and add the following code:

<?xml version=”1.0″?> <configxmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi: noNamespaceSchemaLocation=”urn:magento:module:Magento_Store:etc/ config.xsd”> <default> <ticketblaster> <email>