Skip to content

Commit

Permalink
Locale Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cesurapp committed Sep 20, 2020
1 parent 061f0e2 commit 395a645
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Mailer/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ private function addLog(Email $email): void
{
// Get Template ID
$template = $email->getHeaders()->get('template');
$locale = $email->getHeaders()->get('locale')->getBodyAsString();

// Create Log
$log = new MailLog();
Expand All @@ -98,7 +97,7 @@ private function addLog(Email $email): void
->setSubject($email->getSubject())
->setBody(\is_array($email->getHtmlBody()) ? $email->getHtmlBody() : [])
->setDate(new \DateTime())
->setLanguage($locale ?? ($this->request->getCurrentRequest() ? $this->request->getCurrentRequest()->getLocale() : 'en'))
->setLanguage($this->getLocale($email))
->setTemplateId($template ? $template->getBodyAsString() : '');

// Save
Expand All @@ -113,7 +112,6 @@ private function renderTemplate(Email $email): void
{
if ($templateId = $email->getHeaders()->get('template')) {
$bodyData = $email->getHtmlBody();
$locale = $email->getHeaders()->get('locale')->getBodyAsString();

// Check Array
if (\is_array($bodyData)) {
Expand All @@ -122,7 +120,7 @@ private function renderTemplate(Email $email): void
->findOneBy([
'templateId' => $templateId->getBody(),
'status' => true,
'language' => $locale ?? ($this->request->getCurrentRequest() ? $this->request->getCurrentRequest()->getLocale() : 'en'),
'language' => $this->getLocale($email),
]);

if ($template) {
Expand All @@ -142,4 +140,17 @@ private function renderTemplate(Email $email): void
$email->getHeaders()->remove('template');
}
}

/**
* Get Email Locale
*
* @return string
*/
private function getLocale(Email $email): string
{
$locale = $email->getHeaders()->get('locale');
$locale = $locale ? $locale->getBodyAsString() : null;

return strtolower($locale ?? ($this->request->getCurrentRequest() ? $this->request->getCurrentRequest()->getLocale() : 'en'));
}
}

0 comments on commit 395a645

Please sign in to comment.