‪TYPO3CMS  11.5
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  'fail-on-warnings',
69  null,
70  InputOption::VALUE_NONE,
71  'Fail command when translation was not found on the server.'
72  )
73  ->addOption(
74  'skip-extension',
75  null,
76  InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
77  'Skip extension. Useful for e.g. for not public extensions, which don\'t have language packs.',
78  []
79  );
80  }
81 
91  protected function ‪execute(InputInterface $input, OutputInterface ‪$output)
92  {
93  $container = $this->lateBootService->loadExtLocalconfDatabaseAndExtTables(false, true);
94  $languagePackService = $container->get(LanguagePackService::class);
95  $noProgress = $input->getOption('no-progress') || ‪$output->isVerbose();
96  $isos = (array)$input->getArgument('locales');
97  $skipExtensions = (array)$input->getOption('skip-extension');
98  $failOnWarnings = (bool)$input->getOption('fail-on-warnings');
99  $status = 0;
100 
101  // Condition for the scheduler command, e.g. "de fr pt"
102  if (count($isos) === 1 && str_contains($isos[0], ' ')) {
103  $isos = ‪GeneralUtility::trimExplode(' ', $isos[0], true);
104  }
105  if (empty($isos)) {
106  $isos = $languagePackService->getActiveLanguages();
107  }
108 
109  ‪$output->writeln(sprintf(
110  '<info>Updating language packs of all activated extensions for locale(s) "%s"</info>',
111  implode('", "', $isos)
112  ));
113 
114  $extensions = $languagePackService->getExtensionLanguagePackDetails();
115 
116  if ($noProgress) {
117  $progressBarOutput = new NullOutput();
118  } else {
119  $progressBarOutput = ‪$output;
120  }
121  $progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions));
122  foreach ($isos as $iso) {
123  foreach ($extensions as $extension) {
124  if (in_array($extension['key'], $skipExtensions, true)) {
125  continue;
126  }
127  if ($noProgress) {
128  ‪$output->writeln(sprintf('<info>Fetching pack for language "%s" for extension "%s"</info>', $iso, $extension['key']), $output::VERBOSITY_VERY_VERBOSE);
129  }
130  $result = $languagePackService->languagePackDownload($extension['key'], $iso);
131  if ($noProgress) {
132  switch ($result) {
133  case 'failed':
134  ‪$output->writeln(sprintf('<comment>Fetching pack for language "%s" for extension "%s" failed</comment>', $iso, $extension['key']));
135  break;
136  case 'update':
137  ‪$output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
138  break;
139  case 'new':
140  ‪$output->writeln(sprintf('<info>Fetching new pack for language "%s" for extension "%s"</info>', $iso, $extension['key']));
141  break;
142  }
143  }
144 
145  // Fail only if --fail-on-warnings is set and a language pack was not found.
146  if ($failOnWarnings && $result === 'failed') {
147  $status = 1;
148  }
149 
150  $progressBar->advance();
151  }
152  }
153  $languagePackService->setLastUpdatedIsoCode($isos);
154  $progressBar->finish();
155  ‪$output->writeln('');
156  // Flush language cache
157  GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush();
158 
159  return $status;
160  }
161 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪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:90
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Install\Service\LateBootService
Definition: LateBootService.php:27
‪$output
‪$output
Definition: annotationChecker.php:121
‪TYPO3\CMS\Install\Service\LanguagePackService
Definition: LanguagePackService.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50