‪TYPO3CMS  10.4
LanguagePackCommand.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Symfony\Component\Console\Command\Command;
21 use Symfony\Component\Console\Helper\ProgressBar;
22 use Symfony\Component\Console\Input\InputArgument;
23 use Symfony\Component\Console\Input\InputInterface;
24 use Symfony\Component\Console\Input\InputOption;
25 use Symfony\Component\Console\Output\NullOutput;
26 use Symfony\Component\Console\Output\OutputInterface;
31 
35 class ‪LanguagePackCommand extends Command
36 {
40  private ‪$lateBootService;
41 
42  public function ‪__construct(
43  string $name,
45  ) {
46  $this->lateBootService = ‪$lateBootService;
47  parent::__construct($name);
48  }
52  protected function ‪configure()
53  {
54  $this->setDescription('Update the language files of all activated extensions')
55  ->addArgument(
56  'locales',
57  InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
58  'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.',
59  []
60  )
61  ->addOption(
62  'no-progress',
63  null,
64  InputOption::VALUE_NONE,
65  'Disable progress bar.'
66  )
67  ->addOption(
68  'skip-extension',
69  null,
70  InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
71  'Skip extension. Useful for e.g. for not public extensions, which don\'t have language packs.',
72  []
73  );
74  }
75 
85  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
86  {
87  $container = $this->lateBootService->loadExtLocalconfDatabaseAndExtTables(false);
88  $languagePackService = $container->get(LanguagePackService::class);
89  $noProgress = $input->getOption('no-progress') || ‪$output->isVerbose();
90  $isos = (array)$input->getArgument('locales');
91  $skipExtensions = (array)$input->getOption('skip-extension');
92 
93  // Condition for the scheduler command, e.g. "de fr pt"
94  if (count($isos) === 1 && strpos($isos[0], ' ') !== false) {
95  $isos = ‪GeneralUtility::trimExplode(' ', $isos[0], true);
96  }
97  if (empty($isos)) {
98  $isos = $languagePackService->getActiveLanguages();
99  }
100 
101  ‪$output->writeln(sprintf(
102  '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
103  implode('", "', $isos)
104  ));
105 
106  $extensions = $languagePackService->getExtensionLanguagePackDetails();
107 
108  if ($noProgress) {
109  $progressBarOutput = new NullOutput();
110  } else {
111  $progressBarOutput = ‪$output;
112  }
113  $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
114  $languagePackService->updateMirrorBaseUrl();
115  $hasErrors = false;
116  foreach ($isos as $iso) {
117  foreach ($extensions as $extension) {
118  if (in_array($extension['key'], $skipExtensions, true)) {
119  continue;
120  }
121  if ($noProgress) {
122  ‪$output->writeln(sprintf('<info>Fetching pack for language "%s" for extension "%s"</info>', $iso, $extension['key']), $output::VERBOSITY_VERY_VERBOSE);
123  }
124  $result = $languagePackService->languagePackDownload($extension['key'], $iso);
125  if ($noProgress) {
126  switch ($result) {
127  case 'failed':
128  ‪$output->writeln(sprintf('<error>Fetching pack for language "%s" for extension "%s" failed</error>', $iso, $extension['key']));
129  $hasErrors = true;
130  break;
131  case 'update':
132  ‪$output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
133  break;
134  case 'new':
135  ‪$output->writeln(sprintf('<info>Fetching new pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
136  break;
137  }
138  }
139  $progressBar->advance();
140  }
141  }
142  $languagePackService->setLastUpdatedIsoCode($isos);
143  $progressBar->finish();
144 
145  // Flush language cache
146  GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
147 
148  return $hasErrors ? 1 : 0;
149  }
150 }
‪TYPO3\CMS\Install\Command\LanguagePackCommand\__construct
‪__construct(string $name, LateBootService $lateBootService)
Definition: LanguagePackCommand.php:41
‪TYPO3\CMS\Install\Command\LanguagePackCommand\configure
‪configure()
Definition: LanguagePackCommand.php:51
‪TYPO3\CMS\Install\Command\LanguagePackCommand
Definition: LanguagePackCommand.php:36
‪TYPO3\CMS\Install\Command\LanguagePackCommand\$lateBootService
‪LateBootService $lateBootService
Definition: LanguagePackCommand.php:39
‪TYPO3\CMS\Install\Command
Definition: LanguagePackCommand.php:18
‪TYPO3\CMS\Install\Command\LanguagePackCommand\execute
‪int execute(InputInterface $input, OutputInterface $output)
Definition: LanguagePackCommand.php:84
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Install\Service\LateBootService
Definition: LateBootService.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪$output
‪$output
Definition: annotationChecker.php:119
‪TYPO3\CMS\Install\Service\LanguagePackService
Definition: LanguagePackService.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46