diff --git a/src/Events/ExportFinishedEvent.php b/src/Events/ExportFinishedEvent.php index 8b2ef93..74b099b 100644 --- a/src/Events/ExportFinishedEvent.php +++ b/src/Events/ExportFinishedEvent.php @@ -11,6 +11,7 @@ class ExportFinishedEvent public function __construct( public string $filename, public int|string|null $userId, + public string $locale, ) { // } diff --git a/src/Exports/ExcelExport.php b/src/Exports/ExcelExport.php index 12f961d..4c60273 100644 --- a/src/Exports/ExcelExport.php +++ b/src/Exports/ExcelExport.php @@ -222,10 +222,11 @@ public function export() $filename = Str::uuid().'-'.$this->getFilename(); $userId = auth()->id(); + $locale = app()->getLocale(); $this ->queueExport($filename, 'filament-excel', $this->getWriterType()) - ->chain([fn () => ExportFinishedEvent::dispatch($filename, $userId)]); + ->chain([fn () => ExportFinishedEvent::dispatch($filename, $userId, $locale)]); Notification::make() ->title(__('filament-excel::notifications.queued.title')) diff --git a/src/FilamentExcelServiceProvider.php b/src/FilamentExcelServiceProvider.php index 059a48d..1ebe32a 100644 --- a/src/FilamentExcelServiceProvider.php +++ b/src/FilamentExcelServiceProvider.php @@ -56,6 +56,7 @@ public function cacheExportFinishedNotification(ExportFinishedEvent $event): voi 'id' => Str::uuid(), 'filename' => $event->filename, 'userId' => $event->userId, + 'locale' => $event->locale, ]; cache()->put($key, $exports); diff --git a/src/FilamentExport.php b/src/FilamentExport.php index 57db576..3763870 100644 --- a/src/FilamentExport.php +++ b/src/FilamentExport.php @@ -20,6 +20,12 @@ public static function createExportUrlUsing(Closure $closure): void protected function sendDatabaseNotification(array $export, string $url): void { + $previousLocale = app()->getLocale(); + + if (isset($export['locale'])) { + app()->setLocale($export['locale']); + } + Notification::make(data_get($export, 'id')) ->title(__('filament-excel::notifications.download_ready.title')) ->body(__('filament-excel::notifications.download_ready.body')) @@ -33,6 +39,8 @@ protected function sendDatabaseNotification(array $export, string $url): void ->close(), ]) ->sendToDatabase(auth()->user()); + + app()->setLocale($previousLocale); } protected function sendPersistentNotification(array $export, string $url): void