Framework: Translate queued mails (localization)

Created on 12 Apr 2015  路  13Comments  路  Source: laravel/framework

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

Let's assume, we have two emails in the _pipeline_, one for an English en user and another for an Japanese jp user.

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

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

  Mailer::queue($email, 'Party at Batman\'s cave (Batcave)', 'emails.party-invitation', [

    ...

    '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
  ]);

Most helpful comment

@GrahamCampbell, I really appreciate your tremendous contribution for the community. But your attitude is quite annoying. You act like the guard dog of issues without even allowing a discussion on valid issues (you will probably close this issue now and limit discussion to contributors because I wrote this ;-)). While the Laravel ecosystem is promoting a friendly "netiquette" all I see is issues being instantly closed for no good reason. Obviously people are having trouble with this issue:

13830

So it doesn't help to tuck it away by closing it. As far as I can see it is not solved and it is a problem for millions of non-English speaking developers.

What is the best way to address this issue without the issue being instantly closed? I'd be glad to give it a shot!

All 13 comments

A different template for each locale is not a solution... (imagine an application with 10 languages...)

There is no way to achieve this?

Why is this issue closed? Is it solved? Is there a way to utilize the locale in queued mails? I think it's really annoying that @GrahamCampbell is closing issues without a proper solution/fix. Imho that doesn't help at all. Keeping this thread open shows that this is still not addressed and needs some solution sooner or later.

I would appreciate a solution where it's possible to pass a locale to the queue method. I've also seen suggestions to set the locale via App::setLocale($locale) within the queue callback. But unfortunately that doesn't help either.

:+1: this needs to be reopened.

It's insanely bad that I can't handle this at all... The only solution I've found is passing the locale to the mail, and then passing it onto the trans() method.. Horribly time consuming and ugly when having +50 templates, and an text only version too. I have to at least do manual labor on +100 blade files..

How can it be that even changing language before queue, and inside the closure - does not work..?

I just came across the very same problem. Has this been solved? This is a very essential feature that is overlooked! Anything that is thrown into a queue should pass the original locale own to the job! There is no reason not to.

@GrahamCampbell, I really appreciate your tremendous contribution for the community. But your attitude is quite annoying. You act like the guard dog of issues without even allowing a discussion on valid issues (you will probably close this issue now and limit discussion to contributors because I wrote this ;-)). While the Laravel ecosystem is promoting a friendly "netiquette" all I see is issues being instantly closed for no good reason. Obviously people are having trouble with this issue:

13830

So it doesn't help to tuck it away by closing it. As far as I can see it is not solved and it is a problem for millions of non-English speaking developers.

What is the best way to address this issue without the issue being instantly closed? I'd be glad to give it a shot!

I second that @frankmichel It is quite (very!) annoying that these issues are closed before a sensible discussion on the issue is allowed. @taylorotwell what are your thoughts on this?

I would suggest developing it along the lines of what was discussed in #13830 and submit a pull request. Hopefully, it will be seen as a welcome "feature" and accepted.

This feature request is being discussed on laravel/internals#394 that's the reason that this issue is closed...
We use that repo for feature requests, you guys could share your ideas there... 馃槃

Perfect! Thanks @fernandobandeira

Thanks @fernandobandeira. That's the kind of answer I was hoping for :)

I see discussion is still in progress in related internal issue. Came here with assumption that Carbon::now()->formatLocalized('%B %Y') is also affected with this issue.

I had the similar problem. Check my StackOverflow answer.
The idea is to inherit Illuminate\Mail\Mailable class and replace queue method, then your Mailables will take care of current locale automatically!

https://stackoverflow.com/questions/28889148/translate-queued-mails-localization

I believe this was solved in Laravel 5.6?

$activeMail = new \App\Mail\Register\Activate($user); \Mail::to($user)->locale('tr')->queue($activeMail);

Was this page helpful?
0 / 5 - 0 ratings