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