2019-09-11 01:10:57 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-21 16:06:24 +02:00
|
|
|
namespace App\Console\Command\Locale;
|
2019-09-11 01:10:57 +02:00
|
|
|
|
2020-09-21 16:06:24 +02:00
|
|
|
use App\Console\Command\CommandAbstract;
|
2022-01-07 09:26:40 +01:00
|
|
|
use App\Enums\SupportedLocales;
|
2020-12-03 05:18:06 +01:00
|
|
|
use App\Environment;
|
2022-04-27 19:50:39 +02:00
|
|
|
use Gettext\Generator\MoGenerator;
|
|
|
|
use Gettext\Loader\PoLoader;
|
2021-12-23 02:32:40 +01:00
|
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2019-09-11 01:10:57 +02:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
2021-12-23 02:32:40 +01:00
|
|
|
#[AsCommand(
|
2021-12-23 20:50:39 +01:00
|
|
|
name: 'azuracast:locale:import',
|
2021-12-23 02:32:40 +01:00
|
|
|
description: 'Convert translated locale files into PHP arrays.',
|
2021-12-23 20:50:39 +01:00
|
|
|
aliases: ['locale:import']
|
2021-12-23 02:32:40 +01:00
|
|
|
)]
|
2022-07-01 08:06:29 +02:00
|
|
|
final class ImportCommand extends CommandAbstract
|
2019-09-11 01:10:57 +02:00
|
|
|
{
|
2021-12-23 02:32:40 +01:00
|
|
|
public function __construct(
|
2022-07-01 08:06:29 +02:00
|
|
|
private readonly Environment $environment
|
2021-12-23 02:32:40 +01:00
|
|
|
) {
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
|
|
{
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
2020-10-05 08:27:12 +02:00
|
|
|
$io->title('Import Locales');
|
|
|
|
|
2022-10-07 23:29:57 +02:00
|
|
|
$localesBase = $this->environment->getBaseDirectory() . '/translations';
|
2021-10-27 08:03:16 +02:00
|
|
|
|
2022-01-07 09:26:40 +01:00
|
|
|
$supportedLocales = SupportedLocales::cases();
|
|
|
|
$defaultLocale = SupportedLocales::default();
|
|
|
|
|
2022-04-27 19:50:39 +02:00
|
|
|
$poLoader = new PoLoader();
|
|
|
|
$moGenerator = new MoGenerator();
|
|
|
|
|
2022-01-07 09:26:40 +01:00
|
|
|
foreach ($supportedLocales as $supportedLocale) {
|
|
|
|
if ($supportedLocale === $defaultLocale) {
|
2021-10-31 02:00:38 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-04-27 19:50:39 +02:00
|
|
|
$localeFolder = $localesBase . '/' . $supportedLocale->value . '/LC_MESSAGES';
|
|
|
|
$localeSource = $localeFolder . '/default.po';
|
|
|
|
$localeDest = $localeFolder . '/default.mo';
|
2021-10-27 08:03:16 +02:00
|
|
|
|
2022-04-27 19:50:39 +02:00
|
|
|
if (is_file($localeSource)) {
|
|
|
|
$translations = $poLoader->loadFile($localeSource);
|
|
|
|
$moGenerator->generateFile($translations, $localeDest);
|
2021-11-06 02:38:39 +01:00
|
|
|
|
2022-01-07 09:26:40 +01:00
|
|
|
$io->writeln(
|
2022-05-07 18:44:14 +02:00
|
|
|
sprintf(
|
|
|
|
__('Imported locale: %s'),
|
|
|
|
$supportedLocale->value . ' (' . $supportedLocale->getLocalName() . ')'
|
|
|
|
)
|
2022-01-07 09:26:40 +01:00
|
|
|
);
|
2019-09-11 01:10:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-05 08:27:12 +02:00
|
|
|
$io->success('Locales imported.');
|
2019-09-11 01:10:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|