-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathTranslationController.php
More file actions
120 lines (98 loc) · 4.26 KB
/
TranslationController.php
File metadata and controls
120 lines (98 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Lexik\Bundle\TranslationBundle\Controller;
use Lexik\Bundle\TranslationBundle\Form\Type\TransUnitType;
use Lexik\Bundle\TranslationBundle\Storage\StorageInterface;
use Lexik\Bundle\TranslationBundle\Util\Csrf\CsrfCheckerTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
/**
* @author Cédric Girard <c.girard@lexik.fr>
*/
class TranslationController extends Controller
{
use CsrfCheckerTrait;
/**
* Display an overview of the translation status per domain.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function overviewAction()
{
/** @var StorageInterface $storage */
$storage = $this->get('lexik_translation.translation_storage');
$stats = $this->get('lexik_translation.overview.stats_aggregator')->getStats();
return $this->render('LexikTranslationBundle:Translation:overview.html.twig', array(
'layout' => $this->container->getParameter('lexik_translation.base_layout'),
'locales' => $this->getManagedLocales(),
'domains' => $storage->getTransUnitDomains(),
'latestTrans' => $storage->getLatestUpdatedAt(),
'stats' => $stats,
));
}
/**
* Display the translation grid.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function gridAction()
{
$tokens = null;
if ($this->container->getParameter('lexik_translation.dev_tools.enable')) {
$tokens = $this->get('lexik_translation.token_finder')->find();
}
return $this->render('LexikTranslationBundle:Translation:grid.html.twig', array(
'layout' => $this->container->getParameter('lexik_translation.base_layout'),
'inputType' => $this->container->getParameter('lexik_translation.grid_input_type'),
'autoCacheClean' => $this->container->getParameter('lexik_translation.auto_cache_clean'),
'toggleSimilar' => $this->container->getParameter('lexik_translation.grid_toggle_similar'),
'locales' => $this->getManagedLocales(),
'tokens' => $tokens,
));
}
/**
* Remove cache files for managed locales.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function invalidateCacheAction(Request $request)
{
$this->get('lexik_translation.translator')->removeLocalesCacheFiles($this->getManagedLocales());
$message = $this->get('translator')->trans('translations.cache_removed', array(), 'LexikTranslationBundle');
if ($request->isXmlHttpRequest()) {
$this->checkCsrf();
return new JsonResponse(array('message' => $message));
}
$this->get('session')->getFlashBag()->add('success', $message);
return $this->redirect($this->generateUrl('lexik_translation_grid'));
}
/**
* Add a new trans unit with translation for managed locales.
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function newAction(Request $request)
{
$handler = $this->get('lexik_translation.form.handler.trans_unit');
$form = $this->createForm(TransUnitType::class, $handler->createFormData(), $handler->getFormOptions());
if ($handler->process($form, $request)) {
$message = $this->get('translator')->trans('translations.successfully_added', array(), 'LexikTranslationBundle');
$this->get('session')->getFlashBag()->add('success', $message);
$redirectUrl = $form->get('save_add')->isClicked() ? 'lexik_translation_new' : 'lexik_translation_grid';
return $this->redirect($this->generateUrl($redirectUrl));
}
return $this->render('LexikTranslationBundle:Translation:new.html.twig', array(
'layout' => $this->container->getParameter('lexik_translation.base_layout'),
'form' => $form->createView(),
));
}
/**
* Returns managed locales.
*
* @return array
*/
protected function getManagedLocales()
{
return $this->get('lexik_translation.locale.manager')->getLocales();
}
}