Skip to content

Commit

Permalink
Send system messages in the current site's language
Browse files Browse the repository at this point in the history
Resolves #3388
  • Loading branch information
brandonkelly committed Oct 19, 2018
1 parent 75dca63 commit ebec187
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
11 changes: 8 additions & 3 deletions src/mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ?: []) + [
Expand Down

0 comments on commit ebec187

Please sign in to comment.