Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add customize the locale to specify the backup locale for translation purposes #1838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,4 +338,10 @@
'retry_delay' => 0,
],

/**
* Here you can specify the backup locale for translation purposes.
* For example, if you want to use German (de) notifications even though your base app is in English.
* Supported languages: you can check the available languages in the `resources/lang` directory.
*/
'locale' => env('BACKUP_LOCALE', 'en'),
];
23 changes: 14 additions & 9 deletions src/Notifications/BaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ protected function backupDestinationProperties(): Collection
$newestBackup = $backupDestination->newestBackup();
$oldestBackup = $backupDestination->oldestBackup();

$noBackupsText = trans('backup::notifications.no_backups_info');
$applicationName = trans('backup::notifications.application_name');
$backupName = trans('backup::notifications.backup_name');
$disk = trans('backup::notifications.disk');
$newestBackupSize = trans('backup::notifications.newest_backup_size');
$numberOfBackups = trans('backup::notifications.number_of_backups');
$totalStorageUsed = trans('backup::notifications.total_storage_used');
$newestBackupDate = trans('backup::notifications.newest_backup_date');
$oldestBackupDate = trans('backup::notifications.oldest_backup_date');
$noBackupsText = $this->trans('backup::notifications.no_backups_info');
$applicationName = $this->trans('backup::notifications.application_name');
$backupName = $this->trans('backup::notifications.backup_name');
$disk = $this->trans('backup::notifications.disk');
$newestBackupSize = $this->trans('backup::notifications.newest_backup_size');
$numberOfBackups = $this->trans('backup::notifications.number_of_backups');
$totalStorageUsed = $this->trans('backup::notifications.total_storage_used');
$newestBackupDate = $this->trans('backup::notifications.newest_backup_date');
$oldestBackupDate = $this->trans('backup::notifications.oldest_backup_date');

return collect([
$applicationName => $this->applicationName(),
Expand All @@ -89,4 +89,9 @@ public function backupDestination(): ?BackupDestination

return null;
}

public function trans($key, $replace = [])
{
return trans($key, $replace, config('backup.locale'));
}
}
20 changes: 10 additions & 10 deletions src/Notifications/Notifications/BackupHasFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function toMail(): MailMessage
$mailMessage = (new MailMessage())
->error()
->from($this->config()->notifications->mail->from->address, $this->config()->notifications->mail->from->name)
->subject(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.backup_failed_body', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));
->subject($this->trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.backup_failed_body', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line($this->trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));

$this->backupDestinationProperties()->each(fn ($value, $name) => $mailMessage->line("{$name}: {$value}"));
$this->backupDestinationProperties()->each(fn($value, $name) => $mailMessage->line("{$name}: {$value}"));

return $mailMessage;
}
Expand All @@ -36,15 +36,15 @@ public function toSlack(): SlackMessage
->error()
->from($this->config()->notifications->slack->username, $this->config()->notifications->slack->icon)
->to($this->config()->notifications->slack->channel)
->content(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->content($this->trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->attachment(function (SlackAttachment $attachment) {
$attachment
->title(trans('backup::notifications.exception_message_title'))
->title($this->trans('backup::notifications.exception_message_title'))
->content($this->event->exception->getMessage());
})
->attachment(function (SlackAttachment $attachment) {
$attachment
->title(trans('backup::notifications.exception_trace_title'))
->title($this->trans('backup::notifications.exception_trace_title'))
->content($this->event->exception->getTraceAsString());
})
->attachment(function (SlackAttachment $attachment) {
Expand All @@ -57,9 +57,9 @@ public function toDiscord(): DiscordMessage
return (new DiscordMessage())
->error()
->from($this->config()->notifications->discord->username, $this->config()->notifications->discord->avatar_url)
->title(trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->title($this->trans('backup::notifications.backup_failed_subject', ['application_name' => $this->applicationName()]))
->fields([
trans('backup::notifications.exception_message_title') => $this->event->exception->getMessage(),
$this->trans('backup::notifications.exception_message_title') => $this->event->exception->getMessage(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function toMail(): MailMessage
{
$mailMessage = (new MailMessage())
->from($this->config()->notifications->mail->from->address, $this->config()->notifications->mail->from->name)
->subject(trans('backup::notifications.backup_successful_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.backup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]));
->subject($this->trans('backup::notifications.backup_successful_subject', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.backup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
$mailMessage->line("{$name}: {$value}");
Expand All @@ -35,7 +35,7 @@ public function toSlack(): SlackMessage
->success()
->from($this->config()->notifications->slack->username, $this->config()->notifications->slack->icon)
->to($this->config()->notifications->slack->channel)
->content(trans('backup::notifications.backup_successful_subject_title'))
->content($this->trans('backup::notifications.backup_successful_subject_title'))
->attachment(function (SlackAttachment $attachment) {
$attachment->fields($this->backupDestinationProperties()->toArray());
});
Expand All @@ -46,7 +46,7 @@ public function toDiscord(): DiscordMessage
return (new DiscordMessage())
->success()
->from($this->config()->notifications->discord->username, $this->config()->notifications->discord->avatar_url)
->title(trans('backup::notifications.backup_successful_subject_title'))
->title($this->trans('backup::notifications.backup_successful_subject_title'))
->fields($this->backupDestinationProperties()->toArray());
}
}
18 changes: 9 additions & 9 deletions src/Notifications/Notifications/CleanupHasFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public function toMail(): MailMessage
$mailMessage = (new MailMessage())
->error()
->from($this->config()->notifications->mail->from->address, $this->config()->notifications->mail->from->name)
->subject(trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.cleanup_failed_body', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line(trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));
->subject($this->trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.cleanup_failed_body', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.exception_message', ['message' => $this->event->exception->getMessage()]))
->line($this->trans('backup::notifications.exception_trace', ['trace' => $this->event->exception->getTraceAsString()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
$mailMessage->line("{$name}: {$value}");
Expand All @@ -38,15 +38,15 @@ public function toSlack(): SlackMessage
->error()
->from($this->config()->notifications->slack->username, $this->config()->notifications->slack->icon)
->to($this->config()->notifications->slack->channel)
->content(trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()]))
->content($this->trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()]))
->attachment(function (SlackAttachment $attachment) {
$attachment
->title(trans('backup::notifications.exception_message_title'))
->title($this->trans('backup::notifications.exception_message_title'))
->content($this->event->exception->getMessage());
})
->attachment(function (SlackAttachment $attachment) {
$attachment
->title(trans('backup::notifications.exception_message_trace'))
->title($this->trans('backup::notifications.exception_message_trace'))
->content($this->event->exception->getTraceAsString());
})
->attachment(function (SlackAttachment $attachment) {
Expand All @@ -60,9 +60,9 @@ public function toDiscord(): DiscordMessage
->error()
->from($this->config()->notifications->discord->username, $this->config()->notifications->discord->avatar_url)
->title(
trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()])
$this->trans('backup::notifications.cleanup_failed_subject', ['application_name' => $this->applicationName()])
)->fields([
trans('backup::notifications.exception_message_title') => $this->event->exception->getMessage(),
$this->trans('backup::notifications.exception_message_title') => $this->event->exception->getMessage(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function toMail(): MailMessage
{
$mailMessage = (new MailMessage())
->from($this->config()->notifications->mail->from->address, $this->config()->notifications->mail->from->name)
->subject(trans('backup::notifications.cleanup_successful_subject', ['application_name' => $this->applicationName()]))
->line(trans('backup::notifications.cleanup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]));
->subject($this->trans('backup::notifications.cleanup_successful_subject', ['application_name' => $this->applicationName()]))
->line($this->trans('backup::notifications.cleanup_successful_body', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
$mailMessage->line("{$name}: {$value}");
Expand All @@ -35,7 +35,7 @@ public function toSlack(): SlackMessage
->success()
->from($this->config()->notifications->slack->username, $this->config()->notifications->slack->icon)
->to($this->config()->notifications->slack->channel)
->content(trans('backup::notifications.cleanup_successful_subject_title'))
->content($this->trans('backup::notifications.cleanup_successful_subject_title'))
->attachment(function (SlackAttachment $attachment) {
$attachment->fields($this->backupDestinationProperties()->toArray());
});
Expand All @@ -46,7 +46,7 @@ public function toDiscord(): DiscordMessage
return (new DiscordMessage())
->success()
->from($this->config()->notifications->discord->username, $this->config()->notifications->discord->avatar_url)
->title(trans('backup::notifications.cleanup_successful_subject_title'))
->title($this->trans('backup::notifications.cleanup_successful_subject_title'))
->fields($this->backupDestinationProperties()->toArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function toMail(): MailMessage
{
$mailMessage = (new MailMessage())
->from($this->config()->notifications->mail->from->address, $this->config()->notifications->mail->from->name)
->subject(trans('backup::notifications.healthy_backup_found_subject', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]))
->line(trans('backup::notifications.healthy_backup_found_body', ['application_name' => $this->applicationName()]));
->subject($this->trans('backup::notifications.healthy_backup_found_subject', ['application_name' => $this->applicationName(), 'disk_name' => $this->diskName()]))
->line($this->trans('backup::notifications.healthy_backup_found_body', ['application_name' => $this->applicationName()]));

$this->backupDestinationProperties()->each(function ($value, $name) use ($mailMessage) {
$mailMessage->line("{$name}: {$value}");
Expand All @@ -35,7 +35,7 @@ public function toSlack(): SlackMessage
->success()
->from($this->config()->notifications->slack->username, $this->config()->notifications->slack->icon)
->to($this->config()->notifications->slack->channel)
->content(trans('backup::notifications.healthy_backup_found_subject_title', ['application_name' => $this->applicationName()]))
->content($this->trans('backup::notifications.healthy_backup_found_subject_title', ['application_name' => $this->applicationName()]))
->attachment(function (SlackAttachment $attachment) {
$attachment->fields($this->backupDestinationProperties()->toArray());
});
Expand All @@ -47,7 +47,7 @@ public function toDiscord(): DiscordMessage
->success()
->from($this->config()->notifications->discord->username, $this->config()->notifications->discord->avatar_url)
->title(
trans('backup::notifications.healthy_backup_found_subject_title', [
$this->trans('backup::notifications.healthy_backup_found_subject_title', [
'application_name' => $this->applicationName(),
])
)->fields($this->backupDestinationProperties()->toArray());
Expand Down
Loading