/**
  * Update language file for each extension
  *
  * @param string $localesToUpdate Comma separated list of locales that needs to be updated
  * @return void
  */
 public function updateCommand($localesToUpdate = '')
 {
     /** @var $translationService \TYPO3\CMS\Lang\Service\TranslationService */
     $translationService = $this->objectManager->get(\TYPO3\CMS\Lang\Service\TranslationService::class);
     /** @var $languageRepository \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository */
     $languageRepository = $this->objectManager->get(\TYPO3\CMS\Lang\Domain\Repository\LanguageRepository::class);
     $locales = array();
     if (!empty($localesToUpdate)) {
         $locales = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $localesToUpdate, TRUE);
     } else {
         $languages = $languageRepository->findSelected();
         foreach ($languages as $language) {
             /** @var $language \TYPO3\CMS\Lang\Domain\Model\Language */
             $locales[] = $language->getLocale();
         }
     }
     /** @var PackageManager $packageManager */
     $packageManager = $this->objectManager->get(\TYPO3\CMS\Core\Package\PackageManager::class);
     $this->emitPackagesMayHaveChangedSignal();
     $packages = $packageManager->getAvailablePackages();
     $this->outputLine(sprintf('Updating language packs of all activated extensions for locales "%s"', implode(', ', $locales)));
     $this->output->progressStart(count($locales) * count($packages));
     foreach ($locales as $locale) {
         /** @var PackageInterface $package */
         foreach ($packages as $package) {
             $extensionKey = $package->getPackageKey();
             $result = $translationService->updateTranslation($extensionKey, $locale);
             if (empty($result[$extensionKey][$locale]['error'])) {
                 $this->registryService->set($locale, $GLOBALS['EXEC_TIME']);
             }
             $this->output->progressAdvance();
         }
     }
     $this->output->progressFinish();
 }
예제 #2
0
 /**
  * Returns all objects of this repository
  *
  * @return \TYPO3\CMS\Lang\Domain\Model\Language[] The language objects
  */
 public function findAll()
 {
     if (!count($this->languages)) {
         $languages = $this->locales->getLanguages();
         array_shift($languages);
         foreach ($languages as $locale => $language) {
             $label = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:setup/mod/locallang.xlf:lang_' . $locale));
             if ($label === '') {
                 $label = htmlspecialchars($language);
             }
             $this->languages[$locale] = $this->objectManager->get(\TYPO3\CMS\Lang\Domain\Model\Language::class, $locale, $label, in_array($locale, $this->selectedLocales), $this->registryService->get($locale));
         }
         usort($this->languages, function ($a, $b) {
             /** @var $a \TYPO3\CMS\Lang\Domain\Model\Language */
             /** @var $b \TYPO3\CMS\Lang\Domain\Model\Language */
             if ($a->getLabel() == $b->getLabel()) {
                 return 0;
             }
             return $a->getLabel() < $b->getLabel() ? -1 : 1;
         });
     }
     return $this->languages;
 }
예제 #3
0
 /**
  * Fetch all translations for given locale
  *
  * @param array $data The request data
  * @return void
  */
 public function updateLanguageAction(array $data)
 {
     $response = array('success' => FALSE, 'progress' => 0);
     if (!empty($data['locale'])) {
         $extension = $this->extensionRepository->findOneByOffset((int) $data['count']);
         if (!empty($extension)) {
             $allCount = (int) $this->extensionRepository->countAll();
             $offset = (int) $data['count'];
             $extensionKey = $extension->getKey();
             $result = $this->translationService->updateTranslation($extensionKey, $data['locale']);
             $progress = round(($offset + 1) * 100 / $allCount, 2);
             if (empty($result[$extensionKey][$data['locale']]['error'])) {
                 $this->registryService->set($data['locale'], $GLOBALS['EXEC_TIME']);
                 $response = array('success' => TRUE, 'result' => $result, 'timestamp' => $GLOBALS['EXEC_TIME'], 'progress' => $progress > 100 ? 100 : $progress);
             }
         }
     }
     $this->view->assign('response', $response);
 }
 /**
  * Fetch all translations for given locale
  *
  * @param array $data The request data
  * @return void
  */
 public function updateLanguageAction(array $data)
 {
     $numberOfExtensionsToUpdate = 10;
     $response = array('success' => false, 'progress' => 0);
     $progress = 0;
     if (!empty($data['locale'])) {
         $allCount = 0;
         for ($i = 0; $i < $numberOfExtensionsToUpdate; $i++) {
             $offset = (int) $data['count'] * $numberOfExtensionsToUpdate + $i;
             /** @var Extension $extension */
             $extension = $this->extensionRepository->findOneByOffset($offset);
             if (empty($extension)) {
                 // No more extensions to update
                 break;
             }
             if ($allCount === 0) {
                 $allCount = (int) $this->extensionRepository->countAll();
             }
             $extensionKey = $extension->getKey();
             $result = $this->translationService->updateTranslation($extensionKey, $data['locale']);
             $progress = round(($offset + 1) * 100 / $allCount, 2);
             $response['result'][$data['locale']][$extensionKey] = $result[$data['locale']];
             if (empty($result[$extensionKey][$data['locale']]['error'])) {
                 $response['success'] = true;
             } else {
                 // Could not update an extension, stop here!
                 $response['success'] = false;
                 break;
             }
         }
     }
     if ($response['success']) {
         $this->registryService->set($data['locale'], $GLOBALS['EXEC_TIME']);
         $response['timestamp'] = $GLOBALS['EXEC_TIME'];
         $response['progress'] = $progress > 100 ? 100 : $progress;
     }
     $this->view->assign('response', $response);
     // Flush language cache
     GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
 }