Skip to content

Commit e170475

Browse files
committed
Merge pull request #23 from ahmedash95/master
specify the languages to display in langman:show
2 parents a490a1a + 10e2324 commit e170475

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

src/Commands/ShowCommand.php

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ShowCommand extends Command
1414
*
1515
* @var string
1616
*/
17-
protected $signature = 'langman:show {key} {--c|close}';
17+
protected $signature = 'langman:show {key} {--c|close} {--lang=}';
1818

1919
/**
2020
* The name and signature of the console command.
@@ -51,6 +51,13 @@ class ShowCommand extends Command
5151
*/
5252
protected $files;
5353

54+
/**
55+
* Array of selected languages.
56+
*
57+
* @var array
58+
*/
59+
protected $languages;
60+
5461
/**
5562
* ListCommand constructor.
5663
*
@@ -74,8 +81,18 @@ public function handle()
7481

7582
$this->files = $this->filesFromKey();
7683

84+
$this->languages = $this->manager->languages();
85+
86+
if ($this->option('lang') != null) {
87+
$languages = explode(',', $this->option('lang'));
88+
if (!empty($diffLangagues = array_diff($languages, $this->languages))) {
89+
return $this->error('Unknown Langauges [ '.implode($diffLangagues,',').' ]');
90+
}
91+
$this->languages = explode(',', $this->option('lang'));
92+
}
93+
7794
$this->table(
78-
array_merge(['key'], $this->manager->languages()),
95+
array_merge(['key'], $this->languages),
7996
$this->tableRows()
8097
);
8198
}
@@ -87,19 +104,17 @@ public function handle()
87104
*/
88105
private function tableRows()
89106
{
90-
$allLanguages = $this->manager->languages();
91-
92107
$output = [];
93108

94109
$filesContent = [];
95110

96111
foreach ($this->files as $languageKey => $file) {
97112
foreach ($filesContent[$languageKey] = Arr::dot($this->manager->getFileContent($file)) as $key => $value) {
98-
if (! $this->shouldShowKey($key)) {
113+
if (!$this->shouldShowKey($key)) {
99114
continue;
100115
}
101116

102-
$output[$key]['key'] = $key;
117+
$output[$key]['key'] = $key;
103118
$output[$key][$languageKey] = $value;
104119
}
105120
}
@@ -110,7 +125,7 @@ private function tableRows()
110125
foreach ($output as $key => $values) {
111126
$original = [];
112127

113-
foreach ($allLanguages as $languageKey) {
128+
foreach ($this->languages as $languageKey) {
114129
$original[$languageKey] = isset($values[$languageKey]) ? $values[$languageKey] : '<bg=red> MISSING </>';
115130
}
116131

@@ -179,11 +194,11 @@ private function shouldShowKey($key)
179194
return true;
180195
}
181196

182-
if (! $this->option('close') && $key != $this->key) {
197+
if (!$this->option('close') && $key != $this->key) {
183198
return false;
184199
}
185200

186-
if ($this->option('close') && ! Str::contains($key, $this->key)) {
201+
if ($this->option('close') && !Str::contains($key, $this->key)) {
187202
return false;
188203
}
189204
}

0 commit comments

Comments
 (0)