1 | <?php namespace Arcanedev\LaravelLang\Commands; |
||
11 | class CheckCommand extends AbstractCommand |
||
12 | { |
||
13 | /* ----------------------------------------------------------------- |
||
14 | | Properties |
||
15 | | ----------------------------------------------------------------- |
||
16 | */ |
||
17 | |||
18 | /** |
||
19 | * The name and signature of the console command. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $signature = 'trans:check'; |
||
24 | |||
25 | /** |
||
26 | * The console command description. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $description = 'Check the missing translations.'; |
||
31 | |||
32 | /** |
||
33 | * The TransChecker instance. |
||
34 | * |
||
35 | * @var \Arcanedev\LaravelLang\Contracts\TransChecker |
||
36 | */ |
||
37 | private $checker; |
||
38 | |||
39 | /** |
||
40 | * Missing translations count. |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | private $count = 0; |
||
45 | |||
46 | /* ----------------------------------------------------------------- |
||
47 | | Constructor |
||
48 | | ----------------------------------------------------------------- |
||
49 | */ |
||
50 | |||
51 | /** |
||
52 | * Init the CheckCommand. |
||
53 | * |
||
54 | * @param \Arcanedev\LaravelLang\Contracts\TransChecker $checker |
||
55 | */ |
||
56 | 12 | public function __construct(TransChecker $checker) |
|
64 | |||
65 | /* ----------------------------------------------------------------- |
||
66 | | Main Methods |
||
67 | | ----------------------------------------------------------------- |
||
68 | */ |
||
69 | |||
70 | /** |
||
71 | * Execute the console command. |
||
72 | */ |
||
73 | public function handle() |
||
74 | { |
||
75 | $this->copyright(); |
||
76 | |||
77 | $this->info('Checking the missing translations...'); |
||
78 | $this->line(''); |
||
79 | |||
80 | $missing = $this->checker->check(); |
||
81 | |||
82 | $this->table(['locale', 'translations'], $this->prepareRows($missing)); |
||
83 | |||
84 | $this->line(''); |
||
85 | $this->showMessage(); |
||
86 | $this->line(''); |
||
87 | } |
||
88 | |||
89 | /* ------------------------------------------------------------------------------------------------ |
||
90 | | Other Functions |
||
91 | | ------------------------------------------------------------------------------------------------ |
||
92 | */ |
||
93 | /** |
||
94 | * Prepare table rows. |
||
95 | * |
||
96 | * @param array $missing |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | private function prepareRows(array $missing) |
||
101 | { |
||
102 | $rows = []; |
||
103 | |||
104 | foreach ($missing as $locale => $translations) { |
||
105 | foreach ($translations as $translation) { |
||
106 | $rows[] = [$locale, $translation]; |
||
107 | $this->count++; |
||
108 | } |
||
109 | $rows[] = $this->tableSeparator(); |
||
110 | } |
||
111 | |||
112 | $rows[] = ['Total', "{$this->count} translations are missing."]; |
||
113 | |||
114 | return $rows; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Show the message. |
||
119 | * |
||
120 | * @codeCoverageIgnore |
||
121 | */ |
||
122 | private function showMessage() |
||
129 | } |
||
130 |