2018-03-19 02:31:43 +01: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;
|
2018-03-19 02:31:43 +01:00
|
|
|
|
2020-09-21 16:06:24 +02:00
|
|
|
use App\Console\Command\CommandAbstract;
|
2020-12-03 05:18:06 +01:00
|
|
|
use App\Environment;
|
2019-09-04 20:00:51 +02:00
|
|
|
use Gettext\Translations;
|
|
|
|
use RecursiveDirectoryIterator;
|
|
|
|
use RecursiveIteratorIterator;
|
|
|
|
use RecursiveRegexIterator;
|
|
|
|
use RegexIterator;
|
2019-09-11 01:10:57 +02:00
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
2018-03-19 02:31:43 +01:00
|
|
|
|
2020-09-21 16:06:24 +02:00
|
|
|
class GenerateCommand extends CommandAbstract
|
2018-03-19 02:31:43 +01:00
|
|
|
{
|
2019-09-11 01:10:57 +02:00
|
|
|
public function __invoke(
|
|
|
|
SymfonyStyle $io,
|
2020-12-03 05:18:06 +01:00
|
|
|
Environment $environment
|
2020-10-15 00:19:31 +02:00
|
|
|
): int {
|
2020-10-05 08:27:12 +02:00
|
|
|
$io->title('Generate Locales');
|
|
|
|
|
2020-12-03 05:18:06 +01:00
|
|
|
$dest_file = $environment->getBaseDirectory() . '/resources/locale/default.pot';
|
2020-10-15 00:19:31 +02:00
|
|
|
$translations = new Translations();
|
2018-03-19 02:31:43 +01:00
|
|
|
|
|
|
|
// Find all PHP/PHTML files in the application's code.
|
2018-08-30 02:39:51 +02:00
|
|
|
$translatable_folders = [
|
2020-12-03 05:18:06 +01:00
|
|
|
$environment->getBaseDirectory() . '/src',
|
|
|
|
$environment->getBaseDirectory() . '/config',
|
|
|
|
$environment->getViewsDirectory(),
|
2018-08-30 02:39:51 +02:00
|
|
|
];
|
2018-03-19 02:31:43 +01:00
|
|
|
|
2019-09-04 20:00:51 +02:00
|
|
|
foreach ($translatable_folders as $folder) {
|
|
|
|
$directory = new RecursiveDirectoryIterator($folder);
|
|
|
|
$iterator = new RecursiveIteratorIterator($directory);
|
|
|
|
$regex = new RegexIterator($iterator, '/^.+\.(phtml|php)$/i', RecursiveRegexIterator::GET_MATCH);
|
2018-08-30 02:39:51 +02:00
|
|
|
|
2019-09-04 20:00:51 +02:00
|
|
|
foreach ($regex as $path_match) {
|
2018-08-30 02:39:51 +02:00
|
|
|
$path = $path_match[0];
|
|
|
|
$translations->addFromPhpCodeFile($path);
|
|
|
|
}
|
2018-03-19 02:31:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$translations->toPoFile($dest_file);
|
|
|
|
|
2020-10-05 08:27:12 +02:00
|
|
|
$io->success('Locales generated.');
|
2018-05-07 03:57:06 +02:00
|
|
|
return 0;
|
2018-03-19 02:31:43 +01:00
|
|
|
}
|
2018-08-05 22:48:38 +02:00
|
|
|
}
|