|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FaizShukri\Quran\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use FaizShukri\Quran\Supports\Config; |
|
6
|
|
|
use FaizShukri\Quran\Supports\Downloader; |
|
7
|
|
|
use FaizShukri\Quran\TanzilTranslations; |
|
8
|
|
|
use FaizShukri\Quran\Repositories\Source\XMLRepository; |
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
14
|
|
|
|
|
15
|
|
|
class TranslationAddCommand extends Command |
|
16
|
|
|
{ |
|
17
|
|
|
private $source; |
|
18
|
|
|
|
|
19
|
|
|
private $config; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct() |
|
22
|
|
|
{ |
|
23
|
|
|
parent::__construct(); |
|
24
|
|
|
$this->config = new Config; |
|
25
|
|
|
$this->source = new XMLRepository; |
|
26
|
|
|
$this->source->setConfig($this->config); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function configure() |
|
30
|
|
|
{ |
|
31
|
|
|
$this |
|
32
|
|
|
->setName('translation:add') |
|
33
|
|
|
->setDescription('Add new translation') |
|
34
|
|
|
->addArgument( |
|
35
|
|
|
'translation', |
|
36
|
|
|
InputArgument::OPTIONAL, |
|
37
|
|
|
'Translation to add' |
|
38
|
|
|
) |
|
39
|
|
|
->addUsage('ms.basmeih') |
|
40
|
|
|
; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
44
|
|
|
{ |
|
45
|
|
|
$translation = $input->getArgument('translation'); |
|
46
|
|
|
|
|
47
|
|
|
if($translation === null){ |
|
48
|
|
|
$this->translationTable($output, $this->allTranslations()); |
|
49
|
|
|
$output->writeln("<info>Please specify a </info><comment>translation ID</comment><info>. You can refer to the table above.</info>\n"); |
|
50
|
|
|
} else { |
|
51
|
|
|
$this->config->customTranslations($translation); |
|
52
|
|
|
// dump($this->config->get('translations')); |
|
53
|
|
|
$dw = new Downloader($this->config); |
|
54
|
|
|
$dw->sync(); |
|
55
|
|
|
$output->writeln("<info>$translation</info> has been added successfully.\n"); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function allTranslations() |
|
60
|
|
|
{ |
|
61
|
|
|
$tanzil = new TanzilTranslations; |
|
62
|
|
|
return $tanzil->get(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function translationTable($output, $translations) |
|
66
|
|
|
{ |
|
67
|
|
|
$table = new Table($output); |
|
68
|
|
|
$table |
|
69
|
|
|
->setHeaders(['ID', 'Language', 'Name', 'Translator']) |
|
70
|
|
|
->setRows($translations) |
|
71
|
|
|
; |
|
72
|
|
|
$table->render(); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|