Does anyone know of a best practice in how to translate an e-mail send by SwiftMailer in Symfony? With or without twig.
I can come up with some options, but they all are incomplete.
First thing I can come up with is to create several twig files. Just like User.register.html.twig
(default), User.register.nl_be.html.twig
(dutch in belgium, based on your current url) and User.register.nl.html.twig
(all dutch).
But there is a flaw with this approach, if my default template is edited, all other templates need to be altered too. Since we support a variety of languages, this is not maintainable.
Second I thought of using the translator of Symfony, by just using "labels" in one single template. For example:
<h1>{{ 'user.email.register.title'|trans }}</h1>
<div>{{ 'user.email.register.body'|trans }}</div>
The flaw in the first approach has been "fixed", but this contains another flaw. Now we need to manage the html in a translation file (yml, po, php, ini, etc.).
We can not just translate strings or placeholders, because e-mail templates are different based on the domain or language you are in. For example the header or footer are completely different. Sometimes marketing wants to add some other information to an e-mail only for a specific domain or language. And complete management around this, must be as simple as possible!
Does anyone have any idea on how to manage translatable e-mail, including changes in header/footer/etc. based on language/domain or other parameter?
<?= translate('user.email.register.title'); ?>
. Email will not parse your custom placeholder, so you need to send email with already translated text – Justinas<?php if (): ?>
to show/hide elements – Justinas