2019-09-10 23:10:57 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
namespace App\Console\Command\Locale;
|
2019-09-10 23:10:57 +00:00
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
use App\Console\Command\CommandAbstract;
|
2020-12-03 04:18:06 +00:00
|
|
|
use App\Environment;
|
2021-07-08 20:03:54 +00:00
|
|
|
use App\Locale;
|
2019-09-10 23:10:57 +00:00
|
|
|
use Gettext\Translations;
|
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
|
2020-09-21 14:06:24 +00:00
|
|
|
class ImportCommand extends CommandAbstract
|
2019-09-10 23:10:57 +00:00
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-12-03 04:18:06 +00:00
|
|
|
Environment $environment
|
2020-10-14 22:19:31 +00:00
|
|
|
): 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;
|
2020-12-03 04:18:06 +00:00
|
|
|
$locale_base = $environment->getBaseDirectory() . '/resources/locale';
|
2019-09-10 23:10:57 +00:00
|
|
|
|
|
|
|
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.');
|
2019-09-10 23:10:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|