translate flash messages

This commit is contained in:
Julien Fastré 2018-05-04 11:10:56 +02:00
parent a12701b97f
commit cabd863245
2 changed files with 25 additions and 13 deletions

View File

@ -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(

View File

@ -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));