-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissingTranslationsCommand.php
More file actions
61 lines (48 loc) · 1.84 KB
/
Copy pathMissingTranslationsCommand.php
File metadata and controls
61 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace ADT\Utils;
use Kdyby\Console\Exception\InvalidArgumentException;
use Kdyby\Translation\Translator;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class MissingTranslationsCommand extends Command {
/** @var Translator */
protected $translator;
protected function configure() {
$this->setName("adt:missing-translations")->setDescription('Return missing translations.');
$this->addOption('from', null,InputOption::VALUE_REQUIRED, 'String, for example "en"');
$this->addArgument('locale', InputArgument::REQUIRED, 'String, for example "en"');
$this->addUsage('<locale>');
}
protected function initialize(InputInterface $input, OutputInterface $output) {
$this->translator = $this->getHelper("container")->getByType(Translator::class);
}
protected function validate(InputInterface $input, OutputInterface $output) {
if (!$input->getArgument('locale')) {
throw new InvalidArgumentException('Specify <locale>.');
}
return true;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($this->validate($input, $output) !== true) {
return 1;
}
$catalogueTo = $this->translator->getCatalogue($input->getArgument('locale'));
if ($input->getOption('from')) {
$catalogueFrom = $this->translator->getCatalogue($input->getOption('from'));
}
else {
$catalogueFrom = $this->translator->getCatalogue($this->translator->getDefaultLocale());
}
foreach ($catalogueFrom->all() as $domain => $translations) {
foreach ($translations as $key => $translation) {
if (!$catalogueTo->defines($key, $domain)) {
echo $domain . '.' . $key . ': ' . $translation . PHP_EOL;
}
}
}
}
}