diff --git a/app/Classes/NotificationBuilder.php b/app/Classes/NotificationBuilder.php
index 826a3ad0..799aa6c3 100644
--- a/app/Classes/NotificationBuilder.php
+++ b/app/Classes/NotificationBuilder.php
@@ -15,7 +15,7 @@ class NotificationBuilder
/**
* @param Notification $notification
*/
- public function __construct(private readonly Notification $notification)
+ public function __construct(private $notification, private $locale)
{
}
@@ -31,7 +31,7 @@ public function convertToBroadcastable(): array
$contents = $this->notification->contents;
$title = $contents['title'];
$content = $contents['content'];
- $locale = app()->getLocale();
+ $locale = $this->locale;
$fallback = env('APP_LOCALE', 'tr');
if (isset($title[$locale])) {
diff --git a/app/Http/Controllers/API/NotificationController.php b/app/Http/Controllers/API/NotificationController.php
index b1c0dd26..7429fd61 100644
--- a/app/Http/Controllers/API/NotificationController.php
+++ b/app/Http/Controllers/API/NotificationController.php
@@ -19,14 +19,14 @@ class NotificationController extends Controller
*/
public function index()
{
- return auth()->user()
+ return auth('api')->user()
->notifications()
->withPivot('read_at', 'seen_at')
->orderBy('send_at', 'desc')
->take(100)
->get()
->map(function ($notification) {
- $builder = new NotificationBuilder($notification);
+ $builder = new NotificationBuilder($notification, auth('api')->user()->locale);
return $builder->convertToBroadcastable();
});
@@ -39,7 +39,7 @@ public function index()
*/
public function unread()
{
- return auth()->user()
+ return auth('api')->user()
->notifications()
->withPivot('read_at', 'seen_at')
->where('read_at', null)
@@ -47,7 +47,7 @@ public function unread()
->take(8)
->get()
->map(function ($notification) {
- $builder = new NotificationBuilder($notification);
+ $builder = new NotificationBuilder($notification, auth('api')->user()->locale);
return $builder->convertToBroadcastable();
});
diff --git a/app/Mail/BasicNotification.php b/app/Mail/BasicNotification.php
index 1ab4ef9c..dd67fab6 100644
--- a/app/Mail/BasicNotification.php
+++ b/app/Mail/BasicNotification.php
@@ -16,21 +16,17 @@ class BasicNotification extends Mailable
{
use Queueable, SerializesModels;
- public $user;
-
public $subject;
- public $notification;
-
/**
* Create a new message instance.
*
* @return void
*/
- public function __construct($notification)
+ public function __construct(public $notification, public $user)
{
$this->subject = __('Liman MYS Bilgilendirme');
- $builder = new NotificationBuilder($notification);
+ $builder = new NotificationBuilder($this->notification, $this->user->locale ?? env('APP_LOCALE', 'tr'));
$this->notification = $builder->convertToBroadcastable();
}
@@ -41,6 +37,9 @@ public function __construct($notification)
*/
public function build()
{
+ // Set session locale
+ app()->setLocale($this->user->locale ?? env('APP_LOCALE', 'tr'));
+
return $this->from([
'address' => env('APP_NOTIFICATION_EMAIL'),
'name' => __('Liman Bildiri Sistemi'),
diff --git a/app/Notifications/NotificationSent.php b/app/Notifications/NotificationSent.php
index 7ae185df..7b4f777f 100644
--- a/app/Notifications/NotificationSent.php
+++ b/app/Notifications/NotificationSent.php
@@ -18,7 +18,7 @@ class NotificationSent extends Notification
*
* @return void
*/
- public function __construct(private $notification)
+ public function __construct(private $notification, private $user)
{
}
@@ -52,7 +52,7 @@ public function toBroadcast(mixed $notifiable): BroadcastMessage
*/
public function toArray(): array
{
- $builder = new NotificationBuilder($this->notification);
+ $builder = new NotificationBuilder($this->notification, $this->user->locale);
return $builder->convertToBroadcastable();
}
}
diff --git a/app/Observers/NotificationObserver.php b/app/Observers/NotificationObserver.php
index c761f8cd..75834b89 100644
--- a/app/Observers/NotificationObserver.php
+++ b/app/Observers/NotificationObserver.php
@@ -26,7 +26,7 @@ private function sendBroadcast(Notification $notification)
$user->notify(new NotificationSent($notification, $user));
if (env('MAIL_ENABLED') && $notification && $notification->mail) {
try {
- Mail::to($user)->send(new BasicNotification($notification));
+ Mail::to($user)->send(new BasicNotification($notification, $user));
} catch (TransportException $e) {
// Don't throw anything on when mail server is not active
}
diff --git a/resources/lang/en.json b/resources/lang/en.json
index 17336659..3c413527 100644
--- a/resources/lang/en.json
+++ b/resources/lang/en.json
@@ -1,4 +1,6 @@
{
+ "Merhaba": "Hello",
+ "Bilginize": "For your information",
"Email Adresi": "Email Address",
"Beni Hatırla": "Remember Me",
"Giriş Yap ": "Login ",
diff --git a/resources/views/email/external_notification.blade.php b/resources/views/email/external_notification.blade.php
index 310eb097..a859cb3a 100644
--- a/resources/views/email/external_notification.blade.php
+++ b/resources/views/email/external_notification.blade.php
@@ -5,13 +5,13 @@
@endcomponent
@endslot
- Merhaba,
+ {{__("Merhaba")}},
{{$notification['content']}}
- Bilginize.
+ {{__("Bilginize")}}.
@slot('footer')
@component('mail::footer')
- Bu email Liman MYS dış bildirim sisteminde {{ isset(explode("->", $notification['title'])[1]) ? explode("->", $notification['title'])[1] : 'Liman' }} tarafından oluşturulmuştur.
+ Bu email Liman MYS dış bildirim sisteminde {{ isset(explode("->", $notification['title'])[1]) ? explode("->", $notification['title'])[1] : 'Liman' }} tarafından oluşturulmuştur.
@endcomponent
@endslot