This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
What is the best practise to send email on different languages ?
The only way I can imagine, just to create a different layouts and templates according to choosen lang. Maybe there is a simple way to extent system model ? I'm not sure will it work with a views, maybe there should be a file based changes in structure for translations something like: /plugins/author/plugin/views/mail/en/message.htm
Shouldn't the easiest be to use language strings in your message template? That is, instead of hard coding your message content into the message view (views/mail/message.htm
) just put in something like <?= echo Lang::get('acme.mail::lang.mail.message.header'); ?>
and have your lang file be
<?php
return [
'message' => [
'header' => 'This is a message header'
],
];
The other languages then accordingly.
I use different language mail templates for my plugins. if you interested see this plugin: https://github.com/gergo85/oc-news
Hm, to be honest, I still don't see why my proposed solution would not suit your use-case. Looking at your two mail views I cannot see any different layouts between either email_hu
and email_en
. They only use different, language-specific links to your homepage, however, even this should be "localizable".
Have you maybe tried my solution but it didn't work? Would be great to then hear what the problem was or where it failed to work.
I know, it isn't a best solution. When I started to develop I can't translate the subject of mail template. I haven't tried any solution yet.
I like your solution, but the users can't change the value of translated texts. In some cases it would be a useful feature.
philipptempel said: Have you maybe tried my solution but it didn't work? Would be great to then hear what the problem was or where it failed to work.
Emails sent from backend are in the backend's locale. Could this be parametrized inside mail template/Twig? Something like:
{{ 'Text in default language'|_(locale: 'hr') }}
1-6 of 6