From b89ccef2aa1ef6105a868a8511a57b8c1162babb Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Tue, 22 Sep 2020 22:01:20 -0400 Subject: [PATCH 1/5] save/retrieve locale when serializing mail data in the queue --- src/Mail/Mailable.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Mail/Mailable.php b/src/Mail/Mailable.php index a8d6c91bb..9c4868991 100644 --- a/src/Mail/Mailable.php +++ b/src/Mail/Mailable.php @@ -1,5 +1,6 @@ viewData; + // retrieved saved locale + if (isset($data['_saved_locale'])) { + App::setLocale($data['_saved_locale']); + unset($data['_saved_locale']); + } + foreach ($data as $param => $value) { $data[$param] = $this->getRestoredPropertyValue($value); } @@ -47,6 +54,10 @@ public function buildViewData() */ public function withSerializedData($data) { + // save current locale in $data to be serialized + list($locale) = explode('-', App::getLocale()); + $data['_saved_locale'] = $locale; + foreach ($data as $param => $value) { $this->viewData[$param] = $this->getSerializedPropertyValue($value); } From 6c4c43ab2a25bf49125f6d45d1eaaba12143beff Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Tue, 22 Sep 2020 22:48:55 -0400 Subject: [PATCH 2/5] save the true locale --- src/Mail/Mailable.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Mail/Mailable.php b/src/Mail/Mailable.php index 9c4868991..0e35cb150 100644 --- a/src/Mail/Mailable.php +++ b/src/Mail/Mailable.php @@ -55,8 +55,7 @@ public function buildViewData() public function withSerializedData($data) { // save current locale in $data to be serialized - list($locale) = explode('-', App::getLocale()); - $data['_saved_locale'] = $locale; + $data['_saved_locale'] = App::getLocale()); foreach ($data as $param => $value) { $this->viewData[$param] = $this->getSerializedPropertyValue($value); From cad4765de74805c3d9de538e5e811981a9610f67 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 23 Sep 2020 07:10:11 -0400 Subject: [PATCH 3/5] allow _current_locale to be overridden with passed $data --- src/Mail/Mailable.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Mail/Mailable.php b/src/Mail/Mailable.php index 0e35cb150..61f3661d1 100644 --- a/src/Mail/Mailable.php +++ b/src/Mail/Mailable.php @@ -33,10 +33,10 @@ public function buildViewData() { $data = $this->viewData; - // retrieved saved locale - if (isset($data['_saved_locale'])) { - App::setLocale($data['_saved_locale']); - unset($data['_saved_locale']); + // retrieve saved locale + if (isset($data['_current_locale'])) { + App::setLocale($data['_current_locale']); + unset($data['_current_locale']); } foreach ($data as $param => $value) { @@ -54,8 +54,12 @@ public function buildViewData() */ public function withSerializedData($data) { - // save current locale in $data to be serialized - $data['_saved_locale'] = App::getLocale()); + // save current locale to be serialized + $defaultData = [ + '_current_locale' => App::getLocale(), + ]; + + $data = array_merge($defaultData, $data); foreach ($data as $param => $value) { $this->viewData[$param] = $this->getSerializedPropertyValue($value); From cc1c88a6062a9686aa70b40b67c89ea8b0c5dc5f Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Wed, 23 Sep 2020 14:01:50 -0400 Subject: [PATCH 4/5] leave _current_locale in data array --- src/Mail/Mailable.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Mail/Mailable.php b/src/Mail/Mailable.php index 61f3661d1..a15910fbb 100644 --- a/src/Mail/Mailable.php +++ b/src/Mail/Mailable.php @@ -33,12 +33,6 @@ public function buildViewData() { $data = $this->viewData; - // retrieve saved locale - if (isset($data['_current_locale'])) { - App::setLocale($data['_current_locale']); - unset($data['_current_locale']); - } - foreach ($data as $param => $value) { $data[$param] = $this->getRestoredPropertyValue($value); } From 8d4ee3935ea20bfa0579cd5b412b8003be0c4316 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Tue, 13 Oct 2020 11:46:41 -0600 Subject: [PATCH 5/5] Update src/Mail/Mailable.php --- src/Mail/Mailable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mail/Mailable.php b/src/Mail/Mailable.php index a15910fbb..a54865617 100644 --- a/src/Mail/Mailable.php +++ b/src/Mail/Mailable.php @@ -48,7 +48,7 @@ public function buildViewData() */ public function withSerializedData($data) { - // save current locale to be serialized + // Ensure that the current locale is stored with the rest of the data for proper translation of queued messages $defaultData = [ '_current_locale' => App::getLocale(), ];