#132 - clean up notifications (#147)

* #132 - added translations

* wip

* #132 - added translations

* #132 - cs fix

* #132 - cs fix

Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl>
This commit is contained in:
Ewelina Lasowy 2022-05-17 15:17:09 +02:00 committed by GitHub
parent 74f33d6c0b
commit 7154caa340
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 92 additions and 46 deletions

View File

@ -27,9 +27,10 @@ class VacationRequestCreatedNotification extends Notification
public function toSlack(): SlackMessage public function toSlack(): SlackMessage
{ {
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]); $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
$seeDetails = __("See details");
return (new SlackMessage()) return (new SlackMessage())
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>"); ->text("{$this->buildDescription()}\n <${url}|${seeDetails}>");
} }
/** /**
@ -97,8 +98,8 @@ class VacationRequestCreatedNotification extends Notification
$name = $this->vacationRequest->name; $name = $this->vacationRequest->name;
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) { if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
return __("The vacation request :title from user :user has been created successfully.", [ return __("The vacation request :title has been created successfully.", [
"user" => $this->vacationRequest->user->profile->full_name, "requester" => $this->vacationRequest->user->profile->full_name,
"title" => $name, "title" => $name,
]); ]);
} }

View File

@ -29,9 +29,10 @@ class VacationRequestStatusChangedNotification extends Notification
public function toSlack(): SlackMessage public function toSlack(): SlackMessage
{ {
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]); $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
$seeDetails = __("See details");
return (new SlackMessage()) return (new SlackMessage())
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>"); ->text("{$this->buildDescription()}\n <${url}|${seeDetails}>");
} }
/** /**

View File

@ -30,9 +30,10 @@ class VacationRequestWaitsForApprovalNotification extends Notification
public function toSlack(): SlackMessage public function toSlack(): SlackMessage
{ {
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]); $url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
$seeDetails = __("See details");
return (new SlackMessage()) return (new SlackMessage())
->text("{$this->buildDescription()}\n <${url}|Zobacz szczegóły>"); ->text("{$this->buildDescription()}\n <${url}|${seeDetails}>");
} }
/** /**

View File

@ -29,7 +29,7 @@ class VacationRequestsSummaryNotification extends Notification
public function toSlack(): SlackMessage public function toSlack(): SlackMessage
{ {
return (new SlackMessage()) return (new SlackMessage())
->text("Wnioski oczekujące na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:") ->text(__("Requests wait for your approval - status for day :date:", ["date" => $this->day->toDisplayString()]))
->withAttachment(new VacationRequestsAttachment($this->vacationRequests)); ->withAttachment(new VacationRequestsAttachment($this->vacationRequests));
} }
@ -55,16 +55,18 @@ class VacationRequestsSummaryNotification extends Notification
"user" => $user, "user" => $user,
]), ]),
) )
->line("Lista wniosków oczekujących na Twoją akcję - stan na dzień {$this->day->toDisplayString()}:") ->line (__("Requests list waits for your approval - status for day :date:", ["date" => $this->day->toDisplayString()]))
->subject("Wnioski oczekujące na akcje - stan na dzień {$this->day->toDisplayString()}"); ->subject(__("Requests wait for your approval - status for day :date:", ["date" => $this->day->toDisplayString()]));
foreach ($this->vacationRequests as $request) { foreach ($this->vacationRequests as $request) {
$url = route("vacation.requests.show", ["vacationRequest" => $request->id]);
$message->line( $message->line(
"Wniosek nr {$request->name} użytkownika {$request->user->profile->full_name} ({$request->from->toDisplayString()} - {$request->to->toDisplayString()})", __("- [request no. :request](:url) of user :user (:startDate - :endDate)", ["request" => $request->name, "url" => $url, "user" => $request->user->profile->full_name, "startDate" => $request->from->toDisplayString(), "endDate" => $request->to->toDisplayString()]),
); );
} }
return $message return $message
->action("Przejdź do wniosków", $url); ->action(__("Go to requests"), $url);
} }
} }

View File

@ -18,7 +18,7 @@ use Toby\Infrastructure\Slack\Elements\RemotesAttachment;
class SendDailySummaryToSlack extends Command class SendDailySummaryToSlack extends Command
{ {
protected $signature = "toby:slack:daily-summary {--f|force}"; protected $signature = "toby:slack:daily-summary {--f|force}";
protected $description = "Sent daily summary to slack"; protected $description = "Sent daily summary to Slack";
public function handle(DailySummaryRetriever $dailySummaryRetriever): void public function handle(DailySummaryRetriever $dailySummaryRetriever): void
{ {
@ -37,7 +37,7 @@ class SendDailySummaryToSlack extends Command
Http::withToken($this->getSlackClientToken()) Http::withToken($this->getSlackClientToken())
->post($this->getUrl(), [ ->post($this->getUrl(), [
"channel" => $this->getSlackChannel(), "channel" => $this->getSlackChannel(),
"text" => "Podsumowanie dla dnia {$now->toDisplayString()}", "text" => __("Daily summary for day :day", ["day" => $now->toDisplayString()]),
"attachments" => $attachments, "attachments" => $attachments,
]); ]);
} }

View File

@ -19,6 +19,6 @@ class YearPeriodExists implements Rule
public function message(): string public function message(): string
{ {
return "The year period for given year doesn't exist."; return __("The year period for given year does not exist.");
} }
} }

View File

@ -14,9 +14,9 @@ class AbsencesAttachment extends ListAttachment
parent::__construct(); parent::__construct();
$this $this
->setTitle("Nieobecności :palm_tree:") ->setTitle(__("Absences :palm_tree:"))
->setColor("#eab308") ->setColor("#eab308")
->setItems($absences->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name)) ->setItems($absences->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
->setEmptyText("Wszyscy dzisiaj pracują :muscle:"); ->setEmptyText(__("Everybody works today :muscle:"));
} }
} }

View File

@ -14,9 +14,9 @@ class BirthdaysAttachment extends ListAttachment
parent::__construct(); parent::__construct();
$this $this
->setTitle("Urodziny :birthday:") ->setTitle(__("Birthdays :birthday:"))
->setColor("#3c5f97") ->setColor("#3c5f97")
->setItems($birthdays->map(fn(User $user): string => $user->profile->full_name)) ->setItems($birthdays->map(fn(User $user): string => $user->profile->full_name))
->setEmptyText("Dzisiaj nikt nie ma urodzin :cry:"); ->setEmptyText(__("Nobody has a birthday today :cry:"));
} }
} }

View File

@ -16,6 +16,6 @@ class KeysAttachment extends ListAttachment
$this $this
->setColor("#3c5f97") ->setColor("#3c5f97")
->setItems($keys->map(fn(Key $key): string => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>")) ->setItems($keys->map(fn(Key $key): string => "Klucz nr {$key->id} - <@{$key->user->profile->slack_id}>"))
->setEmptyText("Nie ma żadnych kluczy w tobym"); ->setEmptyText(__("There are no keys in toby"));
} }
} }

View File

@ -14,9 +14,9 @@ class RemotesAttachment extends ListAttachment
parent::__construct(); parent::__construct();
$this $this
->setTitle("Praca zdalna :house_with_garden:") ->setTitle(__("Remote work :house_with_garden:"))
->setColor("#527aba") ->setColor("#527aba")
->setItems($remoteDays->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name)) ->setItems($remoteDays->map(fn(Vacation $vacation): string => $vacation->user->profile->full_name))
->setEmptyText("Wszyscy dzisiaj są w biurze :boom:"); ->setEmptyText(__("Everybody is in the office :boom:"));
} }
} }

View File

@ -27,7 +27,12 @@ class VacationRequestsAttachment extends ListAttachment
? "{$request->from->toDisplayString()}" ? "{$request->from->toDisplayString()}"
: "{$request->from->toDisplayString()} - {$request->to->toDisplayString()}"; : "{$request->from->toDisplayString()} - {$request->to->toDisplayString()}";
return "<{$url}|Wniosek nr {$request->name}> użytkownika {$request->user->profile->full_name} ({$date})"; return __("<:url|Request no. :request> for user :user (:date)", [
"url" => $url,
"request" => $request->name,
"user" => $request->user->profile->full_name,
"date" => $date,
]);
}); });
} }
} }

View File

@ -24,7 +24,7 @@ class CatchAll extends BaseHandler
$handlers = $this->findAvailableHandlers(); $handlers = $this->findAvailableHandlers();
$attachmentFields = $this->mapHandlersToAttachments($handlers); $attachmentFields = $this->mapHandlersToAttachments($handlers);
return $this->respondToSlack(":x: Nie rozpoznaję polecenia. Lista wszystkich poleceń:") return $this->respondToSlack(__(":x: I don't recognize the command. List of all commands:"))
->withAttachment( ->withAttachment(
Attachment::create() Attachment::create()
->setColor("danger") ->setColor("danger")

View File

@ -16,7 +16,7 @@ use Toby\Infrastructure\Slack\Elements\RemotesAttachment;
class DailySummary extends SignatureHandler class DailySummary extends SignatureHandler
{ {
protected $signature = "toby dzisiaj"; protected $signature = "toby dzisiaj";
protected $description = "Codzienne podsumowanie"; protected $description = "Daily summary";
public function handle(Request $request): Response public function handle(Request $request): Response
{ {
@ -30,7 +30,7 @@ class DailySummary extends SignatureHandler
new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)), new BirthdaysAttachment($dailySummaryRetriever->getBirthdays($now)),
]); ]);
return $this->respondToSlack("Podsumowanie dla dnia {$now->toDisplayString()}") return $this->respondToSlack(__("Summary for the day :day", ["day" => $now->toDisplayString()]))
->withAttachments($attachments->all()); ->withAttachments($attachments->all());
} }
} }

View File

@ -18,7 +18,7 @@ class GiveKeysTo extends SignatureHandler
use FindsUserBySlackId; use FindsUserBySlackId;
protected $signature = "toby klucze:dla {user}"; protected $signature = "toby klucze:dla {user}";
protected $description = "Przekaż klucze wskazanemu użytkownikowi"; protected $description = "Give the keys to the specified user";
/** /**
* @throws UserNotFoundException * @throws UserNotFoundException
@ -35,12 +35,12 @@ class GiveKeysTo extends SignatureHandler
$key = $authUser->keys()->first(); $key = $authUser->keys()->first();
if (!$key) { if (!$key) {
throw ValidationException::withMessages(["key" => "Nie masz żadnego klucza do przekazania"]); throw ValidationException::withMessages(["key" => __("You don't have any key to give")]);
} }
if ($user->is($authUser)) { if ($user->is($authUser)) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
"key" => "Nie możesz przekazać sobie kluczy :dzban:", "key" => __("You can't give the keys to yourself :dzban:"),
]); ]);
} }
@ -51,7 +51,7 @@ class GiveKeysTo extends SignatureHandler
$key->notify(new KeyHasBeenGivenNotification($authUser, $user)); $key->notify(new KeyHasBeenGivenNotification($authUser, $user));
return $this->respondToSlack( return $this->respondToSlack(
":white_check_mark: Klucz nr {$key->id} został przekazany użytkownikowi <@{$user->profile->slack_id}>", __(":white_check_mark: Key no. :key has been given to <@:user>", ["key" => $key->id, "user" => $user->profile->slack_id]),
); );
} }
@ -65,7 +65,7 @@ class GiveKeysTo extends SignatureHandler
protected function getMessages(): array protected function getMessages(): array
{ {
return [ return [
"user.required" => "Musisz podać użytkownika, któremu chcesz przekazać klucze", "user.required" => "You must specified the user to whom you want to give the keys",
]; ];
} }
} }

View File

@ -14,7 +14,7 @@ class Help extends SignatureHandler
use ListsHandlers; use ListsHandlers;
protected $signature = "toby pomoc"; protected $signature = "toby pomoc";
protected $description = "Wyświetl wszystkie dostępne polecenia"; protected $description = "Show all available commands";
public function handle(Request $request): Response public function handle(Request $request): Response
{ {
@ -22,7 +22,7 @@ class Help extends SignatureHandler
$attachmentFields = $this->mapHandlersToAttachments($handlers); $attachmentFields = $this->mapHandlersToAttachments($handlers);
return $this->respondToSlack("Dostępne polecenia:") return $this->respondToSlack(__("Available commands:"))
->withAttachment( ->withAttachment(
Attachment::create() Attachment::create()
->setColor("good") ->setColor("good")

View File

@ -18,18 +18,18 @@ class HomeOffice extends SignatureHandler
use FindsUserBySlackId; use FindsUserBySlackId;
protected $signature = "toby zdalnie"; protected $signature = "toby zdalnie";
protected $description = "Pracuj dzisiaj zdalnie"; protected $description = "Work remotely today";
public function handle(Request $request): Response public function handle(Request $request): Response
{ {
$user = $this->findUserBySlackId($request->userId); $user = $this->findUserBySlackId($request->userId);
$this->createRemoteday($user, Carbon::today()); $this->createRemoteDay($user, Carbon::today());
return $this->respondToSlack(":white_check_mark: Pracujesz dzisiaj zdalnie"); return $this->respondToSlack(__(":white_check_mark: You work remotely today"));
} }
protected function createRemoteday(User $user, Carbon $date): void protected function createRemoteDay(User $user, Carbon $date): void
{ {
$yearPeriod = YearPeriod::findByYear($date->year); $yearPeriod = YearPeriod::findByYear($date->year);

View File

@ -12,7 +12,7 @@ use Toby\Infrastructure\Slack\Elements\KeysAttachment;
class KeyList extends SignatureHandler class KeyList extends SignatureHandler
{ {
protected $signature = "toby klucze"; protected $signature = "toby klucze";
protected $description = "Lista wszystkich kluczy"; protected $description = "List of all keys";
public function handle(Request $request): Response public function handle(Request $request): Response
{ {
@ -20,7 +20,7 @@ class KeyList extends SignatureHandler
->orderBy("id") ->orderBy("id")
->get(); ->get();
return $this->respondToSlack("Lista kluczy :key:") return $this->respondToSlack(__("Keys list :key:"))
->withAttachment(new KeysAttachment($keys)); ->withAttachment(new KeysAttachment($keys));
} }
} }

View File

@ -18,7 +18,7 @@ class TakeKeysFrom extends SignatureHandler
use FindsUserBySlackId; use FindsUserBySlackId;
protected $signature = "toby klucze:od {user}"; protected $signature = "toby klucze:od {user}";
protected $description = "Zabierz klucze wskazanemu użytkownikowi"; protected $description = "Take keys from specified user";
/** /**
* @throws UserNotFoundException|ValidationException * @throws UserNotFoundException|ValidationException
@ -35,13 +35,13 @@ class TakeKeysFrom extends SignatureHandler
if (!$key) { if (!$key) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
"key" => "Użytkownik <@{$user->profile->slack_id}> nie ma żadnych kluczy", "key" => __("User <@:user> does not have any keys", ["user" => $user->profile->slack_id]),
]); ]);
} }
if ($key->user()->is($authUser)) { if ($key->user()->is($authUser)) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
"key" => "Nie możesz zabrać sobie kluczy :dzban:", "key" => __("You can't take the keys from yourself :dzban:"),
]); ]);
} }
@ -51,7 +51,7 @@ class TakeKeysFrom extends SignatureHandler
$key->notify(new KeyHasBeenTakenNotification($authUser, $user)); $key->notify(new KeyHasBeenTakenNotification($authUser, $user));
return $this->respondToSlack(":white_check_mark: Klucz nr {$key->id} został zabrany użytkownikowi <@{$user->profile->slack_id}>"); return $this->respondToSlack(__(":white_check_mark: Key no. :key has been taken from user <@:user>", ["key" => $key->id, "user" => $user->profile->slack_id]));
} }
protected function getRules(): array protected function getRules(): array
@ -64,7 +64,7 @@ class TakeKeysFrom extends SignatureHandler
protected function getMessages(): array protected function getMessages(): array
{ {
return [ return [
"user.required" => "Musisz podać użytkownika, któremu chcesz zabrać klucze", "user.required" => __("You must specified the user you want to take the keys from"),
]; ];
} }
} }

View File

@ -19,6 +19,6 @@ class SlackUserExistsRule implements Rule
public function message(): string public function message(): string
{ {
return "Użytkownik :input nie istnieje w tobym"; return __("User :input does not exist in toby");
} }
} }

View File

@ -30,7 +30,7 @@ trait FindsUserBySlackId
$user = $this->findUserBySlackId($slackId); $user = $this->findUserBySlackId($slackId);
if (!$user) { if (!$user) {
throw new UserNotFoundException("Użytkownik {$slackId} nie istnieje w tobym"); throw new UserNotFoundException(__("User :input does not exist in toby", ["input" => $slackId]));
} }
return $user; return $user;

View File

@ -37,7 +37,7 @@ trait ListsHandlers
) )
->map( ->map(
fn(SignatureHandler $handler): AttachmentField => AttachmentField::create( fn(SignatureHandler $handler): AttachmentField => AttachmentField::create(
$handler->getDescription(), __($handler->getDescription()),
"`/{$handler->getSignature()}`", "`/{$handler->getSignature()}`",
), ),
) )

View File

@ -73,5 +73,41 @@
"Key no :number has been taken from :user.": "Klucz nr :number został zabrany użytkownikowi :user.", "Key no :number has been taken from :user.": "Klucz nr :number został zabrany użytkownikowi :user.",
"Key no :number has been given to :user.": "Klucz nr :number został przekazany użytkownikowi :user.", "Key no :number has been given to :user.": "Klucz nr :number został przekazany użytkownikowi :user.",
":sender gives key no :key to :recipient": ":sender przekazuje klucz nr :key :recipient", ":sender gives key no :key to :recipient": ":sender przekazuje klucz nr :key :recipient",
":recipient takes key no :key from :sender": ":recipient zabiera klucz nr :key :sender" ":recipient takes key no :key from :sender": ":recipient zabiera klucz nr :key :sender",
"The vacation request :title has been created successfully.": "Wniosek urlopowy :title został utworzony pomyślnie.",
":x: I don't recognize the command. List of all commands:": ":x: Nie rozpoznaję polecenia. Lista wszystkich poleceń:",
"Summary for the day :day": "Podsumowanie dla dnia :day",
"Daily summary": "Podsumowanie dnia",
"Give the keys to the specified user": "Przekaż klucze wskazanemu użytkownikowi",
"You don't have any key to give": "Nie masz żadnego klucza do przekazania",
"You can't give the keys to yourself :dzban:": "Nie możesz przekazać sobie kluczy :dzban:",
":white_check_mark: Key no. :key has been given to <@:user>": ":white_check_mark: Klucz nr :key został przekazany użytkownikowi <@:user>",
"You must specified the user to whom you want to give the keys": "Musisz podać użytkownika, któremu chcesz przekazać klucze",
"Show all available commands": "Wyświetl wszystkie dostępne polecenia",
"Available commands:": "Dostępne polecenia:",
"Work remotely today": "Pracuj dzisiaj zdalnie",
":white_check_mark: You work remotely today": ":white_check_mark: Pracujesz dzisiaj zdalnie",
"List of all keys": "Lista wszystkich kluczy",
"Keys list :key:": "Lista kluczy :key:",
"Take keys from specified user": "Zabierz klucze wskazanemu użytkownikowi",
"User <@:user> does not have any keys": "Użytkownik <@:user> nie ma żadnych kluczy",
"You can't take the keys from yourself :dzban:": "Nie możesz zabrać sobie kluczy :dzban:",
"You must specified the user you want to take the keys from": "Musisz podać użytkownika, któremu chcesz zabrać klucze",
"User :input does not exist in toby": "Użytkownik :input nie istnieje w tobym",
":white_check_mark: Key no. :key has been taken from user <@:user>": ":white_check_mark: Klucz nr :key został zabrany użytkownikowi <@:user>",
"Absences :palm_tree:": "Nieobecności :palm_tree:",
"Everybody works today :muscle:": "Wszyscy dzisiaj pracują :muscle:",
"Birthdays :birthday:": "Urodziny :birthday:",
"Nobody has a birthday today :cry:": "Dzisiaj nikt nie ma urodzin :cry:",
"Remote work :house_with_garden:": "Praca zdalna :house_with_garden:",
"Everybody is in the office :boom:": "Wszyscy dzisiaj są w biurze :boom:",
"There are no keys in toby": "Nie ma żadnych kluczy w tobym",
"<:url|Request no. :request> for user :user (:date)": "<:url Wniosek urlopowy nr :request użytkownika :user (:date)",
"The year period for given year does not exist.": "Okres roczny dla danego roku nie istnieje",
"Daily summary for day :day": "Podsumowanie dla dnia :day",
"Requests wait for your approval - status for day :date:": "Wnioski oczekujące na Twoją akcję - stan na dzień :date:",
"Requests list waits for your approval - status for day :date:": "Lista wniosków oczekujących na Twoją akcję - stan na dzień :date:",
"- [request no. :request](:url) of user :user (:startDate - :endDate)": "- [wniosek nr :request](:url) użytkownika :user (:startDate - :endDate)",
"Go to requests": "Przejdź do wniosków",
"See details": "Zobacz szczegóły"
} }