1
|
|
|
<?php namespace Arcanedev\LaravelLang\Commands; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelLang\Contracts\TransChecker; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class CheckCommand |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\LaravelLang\Commands |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
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 $missingTranslations = 0; |
45
|
|
|
|
46
|
|
|
/* ----------------------------------------------------------------- |
47
|
|
|
| Constructor |
48
|
|
|
| ----------------------------------------------------------------- |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Init the CheckCommand. |
53
|
|
|
* |
54
|
|
|
* @param \Arcanedev\LaravelLang\Contracts\TransChecker $checker |
55
|
|
|
*/ |
56
|
20 |
|
public function __construct(TransChecker $checker) |
57
|
|
|
{ |
58
|
20 |
|
$this->name = $this->signature; |
59
|
20 |
|
$this->checker = $checker; |
60
|
20 |
|
$this->missingTranslations = 0; |
61
|
|
|
|
62
|
20 |
|
parent::__construct(); |
63
|
20 |
|
} |
64
|
|
|
|
65
|
|
|
/* ----------------------------------------------------------------- |
66
|
|
|
| Main Methods |
67
|
|
|
| ----------------------------------------------------------------- |
68
|
|
|
*/ |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Execute the console command. |
72
|
|
|
*/ |
73
|
4 |
|
public function handle() |
74
|
|
|
{ |
75
|
4 |
|
$this->copyright(); |
76
|
|
|
|
77
|
4 |
|
$this->info('Checking the missing translations...'); |
78
|
4 |
|
$this->line(''); |
79
|
|
|
|
80
|
4 |
|
$missing = $this->checker->check(); |
81
|
|
|
|
82
|
4 |
|
$this->table(['locale', 'translations'], $this->prepareRows($missing)); |
83
|
|
|
|
84
|
4 |
|
$this->line(''); |
85
|
4 |
|
$this->showMessage(); |
86
|
4 |
|
$this->line(''); |
87
|
4 |
|
|
88
|
|
|
return $this->getExitCode(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/* ----------------------------------------------------------------- |
92
|
|
|
| Other Methods |
93
|
|
|
| ----------------------------------------------------------------- |
94
|
|
|
*/ |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Prepare table rows. |
98
|
|
|
* |
99
|
|
|
* @param array $missing |
100
|
4 |
|
* |
101
|
|
|
* @return array |
102
|
4 |
|
*/ |
103
|
|
|
private function prepareRows(array $missing) |
104
|
4 |
|
{ |
105
|
4 |
|
$rows = []; |
106
|
4 |
|
|
107
|
4 |
|
foreach ($missing as $locale => $translations) { |
108
|
|
|
foreach ($translations as $translation) { |
109
|
4 |
|
$rows[] = [$locale, $translation]; |
110
|
|
|
$this->missingTranslations++; |
111
|
|
|
} |
112
|
4 |
|
$rows[] = $this->tableSeparator(); |
113
|
|
|
} |
114
|
4 |
|
|
115
|
|
|
$rows[] = ['Total', "{$this->missingTranslations} translations are missing."]; |
116
|
|
|
|
117
|
|
|
return $rows; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Show the message. |
122
|
|
|
* |
123
|
|
|
* @codeCoverageIgnore |
124
|
|
|
*/ |
125
|
|
|
private function showMessage() |
126
|
|
|
{ |
127
|
|
|
if ($this->hasMissingTranslations()) |
128
|
|
|
$this->comment('Try to fix your translations and run again the `trans:check` command.'); |
129
|
|
|
else |
130
|
|
|
$this->info('No missing translations, YOU ROCK !! (^_^)b'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the exit code. |
135
|
|
|
* |
136
|
|
|
* @return int |
137
|
|
|
*/ |
138
|
|
|
protected function getExitCode() |
139
|
|
|
{ |
140
|
|
|
return $this->hasMissingTranslations() ? 1 : 0; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Check if has missing translations. |
145
|
|
|
* |
146
|
|
|
* @return bool |
147
|
|
|
*/ |
148
|
|
|
protected function hasMissingTranslations() |
149
|
|
|
{ |
150
|
|
|
return $this->missingTranslations > 0; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|