Any idea why twig translation is not working in email template. Other Twig function are working fine.
What could be the best way to fix it ?
<h3>{{ 'FORMATION_CREATED'|_ }}</h3>
Translation is not working in email because self::$locale is not declared
Is this on Build 420?
Yes, It's on Build 420. I'll test on 419 also and try to initialise self::$locale
It's work fine on frontend. For Cron and command line self::$locale should be set by manually
like
use RainLab\Translate\Models\Message;
[...]
Message::$locale = 'fr';
Mail::send( [...]
and it's work fine now 馃憤
So is there a bug or isn't there?
No bug here 馃槂
Just something hard to find and not documented.
Could be great to add a setLocalemethod into the RainLab\Translate\Models\Message class with a description.
@pvullioud as I see you can use it with static method RainLab\Translate\Models\Message::setContext('en', 'mail'); for example.
Second attribute just for caching.
@hocopor Thanks
How to list e-mail template messages to be translated into the backend? The search does not seem to scan e-mail templates. Do I need to add manually? How?
Try sending an email with each template to force October to render them @wellyfrs
With https://github.com/octobercms/october/pull/3152 and https://github.com/rainlab/translate-plugin/pull/304 and using the tip of @hocopor, I did it. Thanks!
I have the problem that regarding of what and where (Frontend, Task, Console) I set the locale with
Message::setContext(...)
The email template is always rendered in the default locale ('en'). I have setup en and de locale.
example for a test page:
use RainLab\Translate\Models\Message;
function onStart() {
Message::setContext('de', 'mail');
Mail::send('backend::mail.invite', [], function($message) {
$message->to('[email protected]', 'Mr. Debug');
});
}
inside of this mail template I have a translated string like {{ 'mail.invite.salutation'|_ }}.
Any ideas?
Closing as it has been over a month since any activity on this occurred and we are trying to figure out what issues are still relevant. If this is still something that you would like to see through to fruition please respond and we can get the ball rolling.
So, where would one need to put locale changing call from https://github.com/rainlab/translate-plugin/issues/285#issuecomment-375560715 when using mail queues asynchronously?
Most helpful comment
It's work fine on frontend. For Cron and command line
self::$localeshould be set by manuallylike
and it's work fine now 馃憤