mate64 mate64 - 1 year ago 106
PHP Question

Translate queued mails (localization)

I am looking for a working solution, to translate queued emails in .
Unfortunately, all emails use the default locale (defined under


Let's assume, we have two emails in the pipeline, one for an English
user and another for an Japanese

What data should I pass to the
facade to translate (localize) the queued emails?

// User model
$user = User:find(1)->first();

Mailer::queue($email, 'Party at Batman\'s cave (Batcave)', '', [


'locale' => $user->getLocale(), // value: "jp", but does not work
'lang' => $user->getLocale(), // value: "jp", but does not work
'language' => $user->getLocale(), // value: "jp", but does not work

Answer Source

I have been struggling to get this done in a more efficient way. Currently I have it set up like this. Hopefully this helps someone in the future with this issue:

// Fetch the locale of the receiver.
$user = Auth::user();
$locale = $user->locale;
Mail::queue('emails.welcome.template', ['user' => $user, 'locale' => $locale], function($mail) use ($user, $locale) {
               [], null, $locale

And use the following in your template:

{{ trans('mails.welcome', ['name' => ucfirst($user['first_name'])], null, $locale) }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download