From b4cf84295f4ffdf32644555bbaa9d626eff8f957 Mon Sep 17 00:00:00 2001 From: Nicolas Widart Date: Tue, 10 Oct 2017 16:11:25 +0200 Subject: [PATCH] Making the response message translatable --- .../Http/Controllers/Api/MoveMediaController.php | 15 ++++++++++++++- .../Translation/Resources/lang/media/en/media.php | 2 ++ .../Translation/Resources/lang/media/fr/media.php | 2 ++ .../Translation/Resources/lang/media/nl/media.php | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Modules/Media/Http/Controllers/Api/MoveMediaController.php b/Modules/Media/Http/Controllers/Api/MoveMediaController.php index a390b594f..a2b1e4597 100644 --- a/Modules/Media/Http/Controllers/Api/MoveMediaController.php +++ b/Modules/Media/Http/Controllers/Api/MoveMediaController.php @@ -44,8 +44,21 @@ public function __invoke(MoveMediaRequest $request) return response()->json([ 'errors' => $failedMoves > 0, - 'message' => $failedMoves > 0 ? 'Some files were not moved' : 'Files moved successfully', + 'message' => $this->getResponseMessage($failedMoves), 'folder_id' => $destination->id, ]); } + + /** + * @param int $failedMoves + * @return string + */ + protected function getResponseMessage(int $failedMoves) : string + { + if ($failedMoves > 0) { + return trans('media::media.some files not moved'); + } + + return trans('media::media.files moved successfully'); + } } diff --git a/Modules/Translation/Resources/lang/media/en/media.php b/Modules/Translation/Resources/lang/media/en/media.php index d557c9dc1..8069b0b9c 100644 --- a/Modules/Translation/Resources/lang/media/en/media.php +++ b/Modules/Translation/Resources/lang/media/en/media.php @@ -39,4 +39,6 @@ 'edit resource' => 'Edit media', 'destroy resource' => 'Delete media', 'file too large' => 'File is too large. Must be below :size MB.', + 'some files not moved' => 'Some files were not moved', + 'files moved successfully' => 'Files moved successfully', ]; diff --git a/Modules/Translation/Resources/lang/media/fr/media.php b/Modules/Translation/Resources/lang/media/fr/media.php index dc760c6d3..f6a259e09 100644 --- a/Modules/Translation/Resources/lang/media/fr/media.php +++ b/Modules/Translation/Resources/lang/media/fr/media.php @@ -34,4 +34,6 @@ 'Browse' => 'Parcourir...', 'upload file' => 'Uploadez un fichier', 'remove media' => 'Supprimez le fichier', + 'some files not moved' => 'Certains fichiers n\'ont pas été déplacés', + 'files moved successfully' => 'Fichiers déplacés avec succès', ]; diff --git a/Modules/Translation/Resources/lang/media/nl/media.php b/Modules/Translation/Resources/lang/media/nl/media.php index 5b7e1d88d..349e3ce7f 100644 --- a/Modules/Translation/Resources/lang/media/nl/media.php +++ b/Modules/Translation/Resources/lang/media/nl/media.php @@ -34,4 +34,6 @@ 'Browse' => 'Bladeren ...', 'upload file' => 'File uploaded', 'remove media' => 'File verwijderen', + 'some files not moved' => 'Sommige bestanden zijn niet verplaatst', + 'files moved successfully' => 'Bestanden zijn succesvol verplaatst', ];