From cabd8632451b684ca214c281babcae2312ad5016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 4 May 2018 11:10:56 +0200 Subject: [PATCH] translate flash messages --- Controller/SingleTaskController.php | 29 +++++++++++++++++++---------- Controller/TaskController.php | 9 ++++++--- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Controller/SingleTaskController.php b/Controller/SingleTaskController.php index 4c813a404..002d92bd1 100644 --- a/Controller/SingleTaskController.php +++ b/Controller/SingleTaskController.php @@ -22,6 +22,7 @@ use Chill\PersonBundle\Entity\PersonRepository; use Chill\MainBundle\Entity\UserRepository; use Chill\TaskBundle\Event\TaskEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\Translation\TranslatorInterface; class SingleTaskController extends Controller { @@ -34,7 +35,8 @@ class SingleTaskController extends Controller */ public function newAction( Request $request, - EventDispatcherInterface $dispatcher + EventDispatcherInterface $dispatcher, + TranslatorInterface $translator ) { $task = (new SingleTask()) @@ -76,14 +78,14 @@ class SingleTaskController extends Controller $em->flush(); - $this->addFlash('success', "The task is created"); + $this->addFlash('success', $translator->trans("The task is created")); return $this->redirectToRoute('chill_task_singletask_list', [ 'person_id' => $task->getPerson()->getId() ]); } else { - $this->addFlash('error', "This form contains errors"); + $this->addFlash('error', $translator->trans("This form contains errors")); } } @@ -141,8 +143,11 @@ class SingleTaskController extends Controller * name="chill_task_single_task_edit" * ) */ - public function editAction(Request $request, $id) - { + public function editAction( + Request $request, + $id, + TranslatorInterface $translator + ) { /* @var $taskRepository SingleTaskRepository */ $taskRepository = $this->get('chill_task.single_task_repository'); @@ -180,14 +185,15 @@ class SingleTaskController extends Controller $em->flush(); - $this->addFlash('success', "The task has been updated"); + $this->addFlash('success', $translator + ->trans("The task has been updated")); return $this->redirectToRoute('chill_task_singletask_list', [ 'person_id' => $task->getPerson()->getId() ]); } else { - $this->addFlash('error', "This form contains errors"); + $this->addFlash('error', $translator->trans("This form contains errors")); } } @@ -204,8 +210,11 @@ class SingleTaskController extends Controller * name="chill_task_single_task_delete" * ) */ - public function deleteAction(Request $request, $id) - { + public function deleteAction( + Request $request, + $id, + TranslatorInterface $translator + ) { /* @var $taskRepository SingleTaskRepository */ $taskRepository = $this->get('chill_task.single_task_repository'); @@ -258,7 +267,7 @@ class SingleTaskController extends Controller $em->remove($task); $em->flush(); - $this->addFlash('success', $this->get('translator') + $this->addFlash('success', $translator ->trans("The task has been successfully removed.")); return $this->redirect($this->generateUrl( diff --git a/Controller/TaskController.php b/Controller/TaskController.php index 578c2f857..a24fa9ce9 100644 --- a/Controller/TaskController.php +++ b/Controller/TaskController.php @@ -10,6 +10,7 @@ use Symfony\Component\HttpFoundation\Response; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Component\Translation\TranslatorInterface; class TaskController extends Controller @@ -29,6 +30,7 @@ class TaskController extends Controller * @param Registry $registry * @param EntityManagerInterface $em * @param Request $request + * @param TranslatorInterface $translator * @return Response */ public function applyTransitionAction( @@ -38,7 +40,8 @@ class TaskController extends Controller SingleTaskRepository $singleTaskRepository, Registry $registry, EntityManagerInterface $em, - Request $request + Request $request, + TranslatorInterface $translator ) { switch ($kind) { case 'single-task': @@ -71,10 +74,10 @@ class TaskController extends Controller $em->flush(); - $this->addFlash('success', 'The transition is successfully applied'); + $this->addFlash('success', $translator->trans('The transition is successfully applied')); } else { - $this->addFlash('error', 'The transition could not be applied'); + $this->addFlash('error', $translator->trans('The transition could not be applied')); } return $this->redirect($request->query->get('return_path', $defaultReturnPath));