[FEATURE] Add task to auto update languages
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Controller / LanguageController.php
1 <?php
2 namespace TYPO3\CMS\Lang\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Sebastian Fischer <typo3@evoweb.de>
8 * 2012-2013 Kai Vogel <kai.vogel@speedprogs.de>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Language controller handling the selection of available languages and update of extension translations
30 *
31 * @author Sebastian Fischer <typo3@evoweb.de>
32 * @author Kai Vogel <kai.vogel@speedprogs.de>
33 */
34 class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
35
36 /**
37 * @var \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository
38 * @inject
39 */
40 protected $languageRepository;
41
42 /**
43 * @var \TYPO3\CMS\Lang\Domain\Repository\ExtensionRepository
44 * @inject
45 */
46 protected $extensionRepository;
47
48 /**
49 * @var \TYPO3\CMS\Lang\Service\UpdateTranslationService
50 * @inject
51 */
52 protected $updateTranslationService;
53
54 /**
55 * JSON actions
56 * @var array
57 */
58 protected $jsonActions = array('updateTranslation');
59
60 /**
61 * Force JSON output for defined actions
62 *
63 * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view The view to be initialized
64 * @return void
65 */
66 protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) {
67 $actionName = $this->request->getControllerActionName();
68 if (in_array($actionName, $this->jsonActions)) {
69 $viewObjectName = 'TYPO3\\CMS\\Lang\\View\\Language\\' . ucfirst($actionName) . 'Json';
70 $this->view = $this->objectManager->get($viewObjectName);
71 $this->view->setControllerContext($this->controllerContext);
72 $this->view->initializeView();
73 }
74 }
75
76 /**
77 * Index action
78 *
79 * @param \TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm
80 * @param mixed $extensions Extensions to show in form
81 * @return void
82 * @dontvalidate $languageSelectionForm
83 * @dontvalidate $extensions
84 */
85 public function indexAction(\TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm = NULL, $extensions = NULL) {
86 if ($languageSelectionForm === NULL) {
87 $languageSelectionForm = $this->objectManager->get('TYPO3\\CMS\\Lang\\Domain\\Model\\LanguageSelectionForm');
88 $languageSelectionForm->setLanguages($this->languageRepository->findAll());
89 $languageSelectionForm->setSelectedLanguages($this->languageRepository->findSelected());
90 }
91
92 if (empty($extensions)) {
93 $extensions = $this->extensionRepository->findAll();
94 }
95
96 $this->view->assign('languageSelectionForm', $languageSelectionForm);
97 $this->view->assign('extensions', $extensions);
98 }
99
100 /**
101 * Update the language selection form
102 *
103 * @param \TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm
104 * @return void
105 * @dontvalidate $languageSelectionForm
106 */
107 public function updateLanguageSelectionAction(\TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm) {
108 if ($languageSelectionForm !== NULL) {
109 $this->languageRepository->updateSelectedLanguages($languageSelectionForm->getSelectedLanguages());
110 }
111 $this->redirect('index');
112 }
113
114 /**
115 * Update translation for one extension.
116 * The view of this action returns JSON!
117 *
118 * @param string $extension The extension key
119 * @param string $locales Comma separated list of locales to update
120 * @return void
121 */
122 public function updateTranslationAction($extension, $locales) {
123 $locales = $this->updateTranslationService->updateTranslation($extension, $locales);
124 $this->view->assign('extension', $extension);
125 $this->view->assign('locales', $locales);
126 }
127
128 }
129 ?>