2 namespace TYPO3\CMS\Lang\Service
;
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\SingletonInterface
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
19 use TYPO3\CMS\Extbase\SignalSlot\Dispatcher
;
20 use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper
;
25 class TranslationService
implements SingletonInterface
28 * Status codes for AJAX response
30 const TRANSLATION_NOT_AVAILABLE
= 0;
31 const TRANSLATION_AVAILABLE
= 1;
32 const TRANSLATION_FAILED
= 2;
33 const TRANSLATION_OK
= 3;
34 const TRANSLATION_INVALID
= 4;
35 const TRANSLATION_UPDATED
= 5;
38 * @var \TYPO3\CMS\Lang\Service\TerService
40 protected $terService;
43 * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
45 protected $signalSlotDispatcher;
50 protected $mirrorUrl = '';
53 * @param \TYPO3\CMS\Lang\Service\TerService $terService
55 public function injectTerService(TerService
$terService)
57 $this->terService
= $terService;
61 * @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
63 public function injectSignalSlotDispatcher(Dispatcher
$signalSlotDispatcher)
65 $this->signalSlotDispatcher
= $signalSlotDispatcher;
69 * @param \TYPO3\CMS\Extensionmanager\Utility\Repository\Helper $helper The helper
71 public function injectRepositoryHelper(Helper
$helper)
73 $this->mirrorUrl
= $helper->getMirrors(false)->getMirrorUrl();
77 * Update translation for given extension
79 * @param string $extensionKey The extension key
80 * @param mixed $locales Comma separated list or array of locales
81 * @return array Update information
83 public function updateTranslation($extensionKey, $locales)
85 if (is_string($locales)) {
86 $locales = GeneralUtility
::trimExplode(',', $locales);
88 $locales = array_flip((array) $locales);
89 foreach ($locales as $locale => $key) {
90 $state = static::TRANSLATION_INVALID
;
93 $state = $this->updateTranslationForExtension($extensionKey, $locale);
94 } catch (\Exception
$exception) {
95 $error = $exception->getMessage();
97 $locales[$locale] = array(
106 * Update the translation for an extension
108 * @param string $extensionKey The extension key
109 * @param string $locale Locale to update
110 * @return int Translation state
112 protected function updateTranslationForExtension($extensionKey, $locale)
114 if (empty($extensionKey) ||
empty($locale)) {
115 return static::TRANSLATION_INVALID
;
117 $state = static::TRANSLATION_FAILED
;
119 $updateResult = $this->terService
->updateTranslation($extensionKey, $locale, $this->getMirrorUrl($extensionKey));
120 if ($updateResult === true) {
121 $state = static::TRANSLATION_UPDATED
;
127 * Returns the mirror URL for a given extension.
129 * @param string $extensionKey
132 protected function getMirrorUrl($extensionKey)
134 $this->signalSlotDispatcher
->dispatch(
136 'postProcessMirrorUrl',
138 'extensionKey' => $extensionKey,
139 'mirrorUrl' => &$this->mirrorUrl
,
143 return $this->mirrorUrl
;