Skip to content

Commit c054128

Browse files
authored
Merge pull request #215 from pxlrbt/db-locale
Add locale to ExportFinishedEvent
2 parents 76c5ec6 + 41c5df0 commit c054128

4 files changed

+12
-1
lines changed

src/Events/ExportFinishedEvent.php

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class ExportFinishedEvent
1111
public function __construct(
1212
public string $filename,
1313
public int|string|null $userId,
14+
public string $locale,
1415
) {
1516
//
1617
}

src/Exports/ExcelExport.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,11 @@ public function export()
222222

223223
$filename = Str::uuid().'-'.$this->getFilename();
224224
$userId = auth()->id();
225+
$locale = app()->getLocale();
225226

226227
$this
227228
->queueExport($filename, 'filament-excel', $this->getWriterType())
228-
->chain([fn () => ExportFinishedEvent::dispatch($filename, $userId)]);
229+
->chain([fn () => ExportFinishedEvent::dispatch($filename, $userId, $locale)]);
229230

230231
Notification::make()
231232
->title(__('filament-excel::notifications.queued.title'))

src/FilamentExcelServiceProvider.php

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function cacheExportFinishedNotification(ExportFinishedEvent $event): voi
5656
'id' => Str::uuid(),
5757
'filename' => $event->filename,
5858
'userId' => $event->userId,
59+
'locale' => $event->locale,
5960
];
6061

6162
cache()->put($key, $exports);

src/FilamentExport.php

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public static function createExportUrlUsing(Closure $closure): void
2020

2121
protected function sendDatabaseNotification(array $export, string $url): void
2222
{
23+
$previousLocale = app()->getLocale();
24+
25+
if (isset($export['locale'])) {
26+
app()->setLocale($export['locale']);
27+
}
28+
2329
Notification::make(data_get($export, 'id'))
2430
->title(__('filament-excel::notifications.download_ready.title'))
2531
->body(__('filament-excel::notifications.download_ready.body'))
@@ -33,6 +39,8 @@ protected function sendDatabaseNotification(array $export, string $url): void
3339
->close(),
3440
])
3541
->sendToDatabase(auth()->user());
42+
43+
app()->setLocale($previousLocale);
3644
}
3745

3846
protected function sendPersistentNotification(array $export, string $url): void

0 commit comments

Comments
 (0)