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