AzuraCast/src/Console/Command/Locale/ImportCommand.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2021-07-19 05:53:45 +00:00
declare(strict_types=1);
namespace App\Console\Command\Locale;
use App\Console\Command\CommandAbstract;
use App\Environment;
2021-07-08 20:03:54 +00:00
use App\Locale;
use Gettext\Translations;
use Symfony\Component\Console\Style\SymfonyStyle;
class ImportCommand extends CommandAbstract
{
public function __invoke(
SymfonyStyle $io,
Environment $environment
): int {
2020-10-05 06:27:12 +00:00
$io->title('Import Locales');
2021-07-08 20:03:54 +00:00
$locales = Locale::SUPPORTED_LOCALES;
$locale_base = $environment->getBaseDirectory() . '/resources/locale';
foreach ($locales as $locale_key => $locale_name) {
$locale_source = $locale_base . '/' . $locale_key . '/LC_MESSAGES/default.po';
if (file_exists($locale_source)) {
$translations = Translations::fromPoFile($locale_source);
$locale_dest = $locale_base . '/compiled/' . $locale_key . '.php';
$translations->toPhpArrayFile($locale_dest);
$io->writeln(__('Imported locale: %s', $locale_key . ' (' . $locale_name . ')'));
}
}
2020-10-05 06:27:12 +00:00
$io->success('Locales imported.');
return 0;
}
}