Skip to content

Commit

Permalink
Merge pull request #215 from pxlrbt/db-locale
Browse files Browse the repository at this point in the history
Add locale to ExportFinishedEvent
  • Loading branch information
pxlrbt authored Jan 25, 2025
2 parents 76c5ec6 + 41c5df0 commit c054128
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Events/ExportFinishedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ExportFinishedEvent
public function __construct(
public string $filename,
public int|string|null $userId,
public string $locale,
) {
//
}
Expand Down
3 changes: 2 additions & 1 deletion src/Exports/ExcelExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
1 change: 1 addition & 0 deletions src/FilamentExcelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/FilamentExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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
Expand Down

0 comments on commit c054128

Please sign in to comment.