2 namespace TYPO3\CMS\Lang\Command
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Package\PackageInterface
;
18 use TYPO3\CMS\Core\Package\PackageManager
;
21 * Language command controller updates translation packages
23 class LanguageCommandController
extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
26 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
28 protected $signalSlotDispatcher;
31 * @var \TYPO3\CMS\Lang\Service\RegistryService
33 protected $registryService;
36 * @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
38 public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher
$signalSlotDispatcher)
40 $this->signalSlotDispatcher
= $signalSlotDispatcher;
44 * @param \TYPO3\CMS\Lang\Service\RegistryService $registryService
46 public function injectRegistryService(\TYPO3\CMS\Lang\Service\RegistryService
$registryService)
48 $this->registryService
= $registryService;
52 * Update language file for each extension
54 * @param string $localesToUpdate Comma separated list of locales that needs to be updated
57 public function updateCommand($localesToUpdate = '')
59 /** @var $translationService \TYPO3\CMS\Lang\Service\TranslationService */
60 $translationService = $this->objectManager
->get(\TYPO3\CMS\Lang\Service\TranslationService
::class);
61 /** @var $languageRepository \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository */
62 $languageRepository = $this->objectManager
->get(\TYPO3\CMS\Lang\Domain\Repository\LanguageRepository
::class);
64 if (!empty($localesToUpdate)) {
65 $locales = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $localesToUpdate, true);
67 $languages = $languageRepository->findSelected();
68 foreach ($languages as $language) {
69 /** @var $language \TYPO3\CMS\Lang\Domain\Model\Language */
70 $locales[] = $language->getLocale();
73 /** @var PackageManager $packageManager */
74 $packageManager = $this->objectManager
->get(\TYPO3\CMS\Core\Package\PackageManager
::class);
75 $this->emitPackagesMayHaveChangedSignal();
76 $packages = $packageManager->getAvailablePackages();
77 $this->outputLine((sprintf('Updating language packs of all activated extensions for locales "%s"', implode(', ', $locales))));
78 $this->output
->progressStart(count($locales) * count($packages));
79 foreach ($locales as $locale) {
80 /** @var PackageInterface $package */
81 foreach ($packages as $package) {
82 $extensionKey = $package->getPackageKey();
83 $result = $translationService->updateTranslation($extensionKey, $locale);
84 if (empty($result[$extensionKey][$locale]['error'])) {
85 $this->registryService
->set($locale, $GLOBALS['EXEC_TIME']);
87 $this->output
->progressAdvance();
90 $this->output
->progressFinish();
94 * Emits packages may have changed signal
96 protected function emitPackagesMayHaveChangedSignal()
98 $this->signalSlotDispatcher
->dispatch('PackageManagement', 'packagesMayHaveChanged');