Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/Commands/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ShowCommand extends Command
*
* @var string
*/
protected $signature = 'langman:show {key} {--c|close}';
protected $signature = 'langman:show {key} {--c|close} {--lang=}';

/**
* The name and signature of the console command.
Expand Down Expand Up @@ -51,6 +51,13 @@ class ShowCommand extends Command
*/
protected $files;

/**
* Array of selected languages.
*
* @var array
*/
protected $languages;

/**
* ListCommand constructor.
*
Expand All @@ -74,8 +81,18 @@ public function handle()

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

$this->languages = $this->manager->languages();

if ($this->option('lang') != null) {
$languages = explode(',', $this->option('lang'));
if (!empty($diffLangagues = array_diff($languages, $this->languages))) {
return $this->error('Unknown Langauges [ '.implode($diffLangagues,',').' ]');
}
$this->languages = explode(',', $this->option('lang'));
}

$this->table(
array_merge(['key'], $this->manager->languages()),
array_merge(['key'], $this->languages),
$this->tableRows()
);
}
Expand All @@ -87,19 +104,17 @@ public function handle()
*/
private function tableRows()
{
$allLanguages = $this->manager->languages();

$output = [];

$filesContent = [];

foreach ($this->files as $languageKey => $file) {
foreach ($filesContent[$languageKey] = Arr::dot($this->manager->getFileContent($file)) as $key => $value) {
if (! $this->shouldShowKey($key)) {
if (!$this->shouldShowKey($key)) {
continue;
}

$output[$key]['key'] = $key;
$output[$key]['key'] = $key;
$output[$key][$languageKey] = $value;
}
}
Expand All @@ -110,7 +125,7 @@ private function tableRows()
foreach ($output as $key => $values) {
$original = [];

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

Expand Down Expand Up @@ -179,11 +194,11 @@ private function shouldShowKey($key)
return true;
}

if (! $this->option('close') && $key != $this->key) {
if (!$this->option('close') && $key != $this->key) {
return false;
}

if ($this->option('close') && ! Str::contains($key, $this->key)) {
if ($this->option('close') && !Str::contains($key, $this->key)) {
return false;
}
}
Expand Down