Spaces:
No application file
No application file
File size: 2,355 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
<?php
namespace Mautic\CoreBundle\Update\Step;
use Mautic\CoreBundle\Helper\LanguageHelper;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
final class UpdateTranslationsStep implements StepInterface
{
public function __construct(
private TranslatorInterface $translator,
private LanguageHelper $languageHelper,
private LoggerInterface $logger
) {
}
public function getOrder(): int
{
return 40;
}
public function shouldExecuteInFinalStage(): bool
{
return true;
}
public function execute(ProgressBar $progressBar, InputInterface $input, OutputInterface $output): void
{
// Update languages
$supportedLanguages = $this->languageHelper->getSupportedLanguages();
// If there is only one language, assume it is 'en_US' and skip this
if (count($supportedLanguages) <= 1) {
return;
}
$progressBar->setMessage($this->translator->trans('mautic.core.command.update.step.update_languages'));
$progressBar->advance();
// First, update the cached language data
$result = $this->languageHelper->fetchLanguages(true);
// Only continue if not in error
if (isset($result['error'])) {
$this->logger->error('UPDATE ERROR: '.$result['error']);
return;
}
foreach ($supportedLanguages as $locale => $name) {
$this->updateLanguage($locale, $name);
}
}
private function updateLanguage(string $locale, string $name): void
{
// We don't need to update en_US, that comes with the main package
if ('en_US' === $locale) {
return;
}
// Update time
$extractResult = $this->languageHelper->extractLanguagePackage($locale);
if (empty($extractResult['error'])) {
return;
}
$this->logger->error(
'UPDATE ERROR: '.
$this->translator->trans(
'mautic.core.update.error_updating_language',
[
'%language%' => $name,
]
)
);
}
}
|