From ebec1875ef8be47172b0ef9fb0e3400601cef1ef Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Fri, 19 Oct 2018 10:49:49 -0700 Subject: [PATCH] Send system messages in the current site's language Resolves #3388 --- CHANGELOG-v3.md | 1 + src/mail/Mailer.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 0c794d6a115..5132616ee73 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -7,6 +7,7 @@ - Craft.EntryTypeSwitcher now fires a `beforeTypeChange` event before swapping the Edit Entry form tabs. ([#3375](https://github.com/craftcms/cms/pull/3375)) - Craft.MatrixInput now fires an `afterInit` event after initialization. ([#3375](https://github.com/craftcms/cms/pull/3375)) - Craft.MatrixInput now fires an `blockAdded` event after adding a new block. ([#3375](https://github.com/craftcms/cms/pull/3375)) +- System messages sent from front-end requests are now sent using the current site’s language. ([#3388](https://github.com/craftcms/cms/issues/3388)) ### Fixed - Fixed an error that could occur when acquiring a lock for a file path, if the `mutex` component was swapped out with `yii\mutex\MysqlMutex`. diff --git a/src/mail/Mailer.php b/src/mail/Mailer.php index 59c56c258e6..10099d46304 100644 --- a/src/mail/Mailer.php +++ b/src/mail/Mailer.php @@ -87,6 +87,13 @@ public function composeFromKey(string $key, array $variables = []): Message public function send($message) { if ($message instanceof Message && $message->key !== null) { + if ($message->language === null) { + // Default to the current language + $message->language = Craft::$app->getRequest()->getIsSiteRequest() + ? Craft::$app->language + : Craft::$app->getSites()->getPrimarySite()->language; + } + $systemMessage = Craft::$app->getSystemMessages()->getMessage($message->key, $message->language); $subjectTemplate = $systemMessage->subject; $textBodyTemplate = $systemMessage->body; @@ -98,9 +105,7 @@ public function send($message) // Use the message language $language = Craft::$app->language; - if ($message->language !== null) { - Craft::$app->language = $message->language; - } + Craft::$app->language = $message->language; $settings = Craft::$app->getSystemSettings()->getEmailSettings(); $variables = ($message->variables ?: []) + [