|
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
|
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Install\Command; |
|
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; |
|
27
|
|
|
use TYPO3\CMS\Core\Cache\CacheManager; |
|
28
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
29
|
|
|
use TYPO3\CMS\Install\Service\LanguagePackService; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Core function for updating language packs |
|
33
|
|
|
*/ |
|
34
|
|
|
class LanguagePackCommand extends Command |
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Configure the command by defining the name, options and arguments |
|
38
|
|
|
*/ |
|
39
|
|
|
protected function configure() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->setDescription('Update the language files of all activated extensions') |
|
42
|
|
|
->addArgument( |
|
43
|
|
|
'locales', |
|
44
|
|
|
InputArgument::IS_ARRAY | InputArgument::OPTIONAL, |
|
45
|
|
|
'Provide iso codes separated by space to update only selected language packs. Example `bin/typo3 language:update de ja`.', |
|
46
|
|
|
[] |
|
47
|
|
|
) |
|
48
|
|
|
->addOption( |
|
49
|
|
|
'no-progress', |
|
50
|
|
|
null, |
|
51
|
|
|
InputOption::VALUE_NONE, |
|
52
|
|
|
'Disable progress bar.' |
|
53
|
|
|
) |
|
54
|
|
|
->addOption( |
|
55
|
|
|
'skip-extension', |
|
56
|
|
|
null, |
|
57
|
|
|
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
58
|
|
|
'Skip extension. Useful for e.g. for not public extensions, which don\'t have language packs.', |
|
59
|
|
|
[] |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Update language packs of all active languages for all active extensions |
|
65
|
|
|
* |
|
66
|
|
|
* @param InputInterface $input |
|
67
|
|
|
* @param OutputInterface $output |
|
68
|
|
|
* @throws \InvalidArgumentException |
|
69
|
|
|
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException |
|
70
|
|
|
* @return int |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
73
|
|
|
{ |
|
74
|
|
|
$languagePackService = GeneralUtility::makeInstance(LanguagePackService::class); |
|
75
|
|
|
$noProgress = $input->getOption('no-progress') || $output->isVerbose(); |
|
76
|
|
|
$isos = (array)$input->getArgument('locales'); |
|
77
|
|
|
$skipExtensions = (array)$input->getOption('skip-extension'); |
|
78
|
|
|
|
|
79
|
|
|
// Condition for the scheduler command, e.g. "de fr pt" |
|
80
|
|
|
if (count($isos) === 1 && strpos($isos[0], ' ') !== false) { |
|
81
|
|
|
$isos = GeneralUtility::trimExplode(' ', $isos[0], true); |
|
82
|
|
|
} |
|
83
|
|
|
if (empty($isos)) { |
|
84
|
|
|
$isos = $languagePackService->getActiveLanguages(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$output->writeln(sprintf( |
|
88
|
|
|
'<info>Updating language packs of all activated extensions for locale(s) "%s"</info>', |
|
89
|
|
|
implode('", "', $isos) |
|
90
|
|
|
)); |
|
91
|
|
|
|
|
92
|
|
|
$extensions = $languagePackService->getExtensionLanguagePackDetails(); |
|
93
|
|
|
|
|
94
|
|
|
if ($noProgress) { |
|
95
|
|
|
$progressBarOutput = new NullOutput(); |
|
96
|
|
|
} else { |
|
97
|
|
|
$progressBarOutput = $output; |
|
98
|
|
|
} |
|
99
|
|
|
$progressBar = new ProgressBar($progressBarOutput, count($isos) * count($extensions)); |
|
100
|
|
|
$hasErrors = false; |
|
101
|
|
|
foreach ($isos as $iso) { |
|
102
|
|
|
foreach ($extensions as $extension) { |
|
103
|
|
|
if (in_array($extension['key'], $skipExtensions, true)) { |
|
104
|
|
|
continue; |
|
105
|
|
|
} |
|
106
|
|
|
if ($noProgress) { |
|
107
|
|
|
$output->writeln(sprintf('<info>Fetching pack for language "%s" for extension "%s"</info>', $iso, $extension['key']), $output::VERBOSITY_VERY_VERBOSE); |
|
108
|
|
|
} |
|
109
|
|
|
$result = $languagePackService->languagePackDownload($extension['key'], $iso); |
|
110
|
|
|
if ($noProgress) { |
|
111
|
|
|
switch ($result) { |
|
112
|
|
|
case 'failed': |
|
113
|
|
|
$output->writeln(sprintf('<error>Fetching pack for language "%s" for extension "%s" failed</error>', $iso, $extension['key'])); |
|
114
|
|
|
$hasErrors = true; |
|
115
|
|
|
break; |
|
116
|
|
|
case 'update': |
|
117
|
|
|
$output->writeln(sprintf('<info>Updated pack for language "%s" for extension "%s"</info>', $iso, $extension['key'])); |
|
118
|
|
|
break; |
|
119
|
|
|
case 'new': |
|
120
|
|
|
$output->writeln(sprintf('<info>Fetching new pack for language "%s" for extension "%s"</info>', $iso, $extension['key'])); |
|
121
|
|
|
break; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
$progressBar->advance(); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
$languagePackService->setLastUpdatedIsoCode($isos); |
|
128
|
|
|
$progressBar->finish(); |
|
129
|
|
|
|
|
130
|
|
|
// Flush language cache |
|
131
|
|
|
GeneralUtility::makeInstance(CacheManager::class)->getCache('l10n')->flush(); |
|
132
|
|
|
|
|
133
|
|
|
return $hasErrors ? 1 : 0; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|