mirror of
https://github.com/flarum/core.git
synced 2025-08-01 22:20:21 +02:00
fix: set translator locale to user preference for email notifications (#3525)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Flarum\Notification;
|
||||
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Mail\Mailer;
|
||||
use Illuminate\Mail\Message;
|
||||
@@ -26,14 +27,21 @@ class NotificationMailer
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param Mailer $mailer
|
||||
* @param TranslatorInterface $translator
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function __construct(Mailer $mailer, TranslatorInterface $translator)
|
||||
public function __construct(Mailer $mailer, TranslatorInterface $translator, SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->mailer = $mailer;
|
||||
$this->translator = $translator;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +50,10 @@ class NotificationMailer
|
||||
*/
|
||||
public function send(MailableInterface $blueprint, User $user)
|
||||
{
|
||||
// Ensure that notifications are delivered to the user in their default language, if they've selected one.
|
||||
// If the selected locale is no longer available, the forum default will be used instead.
|
||||
$this->translator->setLocale($user->getPreference('locale') ?? $this->settings->get('default_locale'));
|
||||
|
||||
$this->mailer->send(
|
||||
$blueprint->getEmailView(),
|
||||
compact('blueprint', 'user'),
|
||||
|
Reference in New Issue
Block a user