1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\TranslatorExtractor\Command; |
6
|
|
|
|
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
|
13
|
|
|
use Yiisoft\TranslatorExtractor\Extractor; |
14
|
|
|
use Yiisoft\Yii\Console\ExitCode; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Console command that allows extracting translator IDs from files. |
18
|
|
|
*/ |
19
|
|
|
final class ExtractCommand extends Command |
20
|
|
|
{ |
21
|
|
|
protected static $defaultName = 'translator/extract'; |
22
|
|
|
protected static $defaultDescription = 'Extracts translator IDs from files'; |
23
|
|
|
|
24
|
|
|
private string $defaultCategory = 'app'; |
25
|
|
|
|
26
|
|
|
private Extractor $extractor; |
27
|
|
|
|
28
|
6 |
|
public function __construct(Extractor $extractor) |
29
|
|
|
{ |
30
|
6 |
|
$this->extractor = $extractor; |
31
|
6 |
|
parent::__construct(); |
32
|
6 |
|
} |
33
|
|
|
|
34
|
6 |
|
protected function configure(): void |
35
|
|
|
{ |
36
|
|
|
$this |
37
|
6 |
|
->addOption('languages', 'L', InputOption::VALUE_OPTIONAL, 'Comma separated list of languages to write message sources for. By default it is `en`.', 'en') |
38
|
6 |
|
->addOption('category', 'C', InputOption::VALUE_OPTIONAL, 'Default message category to use when category is not set.', $this->defaultCategory) |
39
|
6 |
|
->addOption('except', 'E', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Exclude path from extracting.', []) |
40
|
6 |
|
->addOption('only', 'O', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Use the only specified path for extracting.', []) |
41
|
6 |
|
->addArgument('path', InputArgument::OPTIONAL, 'Path for extracting message IDs.') |
42
|
6 |
|
->setHelp('This command Extracts translator IDs from files within a given path.'); |
43
|
6 |
|
} |
44
|
|
|
|
45
|
6 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
46
|
|
|
{ |
47
|
|
|
/** @var string */ |
48
|
6 |
|
$path = $input->getArgument('path') ?? getcwd(); |
49
|
|
|
|
50
|
|
|
/** @var string */ |
51
|
6 |
|
$languages = $input->getOption('languages'); |
52
|
|
|
|
53
|
|
|
/** @var string */ |
54
|
6 |
|
$category = $input->getOption('category'); |
55
|
|
|
|
56
|
|
|
/** @var string[] */ |
57
|
6 |
|
$except = $input->getOption('except'); |
58
|
|
|
|
59
|
|
|
/** @var string[] */ |
60
|
6 |
|
$only = $input->getOption('only'); |
61
|
|
|
|
62
|
|
|
/** @var string[] */ |
63
|
6 |
|
$languagesList = explode(',', $languages); |
64
|
|
|
|
65
|
6 |
|
$this->extractor->setExcept($except); |
66
|
6 |
|
$this->extractor->setOnly($only); |
67
|
|
|
|
68
|
6 |
|
$this->extractor->process($path, $category, $languagesList, $output); |
69
|
|
|
|
70
|
6 |
|
return ExitCode::OK; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|