Skip to content

Commit

Permalink
Merge pull request #2 from andvla/patch-1
Browse files Browse the repository at this point in the history
Drop empty strings on download
  • Loading branch information
appelsiini authored May 18, 2020
2 parents 4d974f2 + 871ef96 commit 851b2c8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Commands/DownloadTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handle(ApiClient $client, Translator $translator, FilesystemMana
'ext' => 'json',
]);

$translations = json_decode((string)$res, JSON_OBJECT_AS_ARRAY);
$translations = $this->dropEmptyString(json_decode((string)$res, JSON_OBJECT_AS_ARRAY));
$fs = $storage->createLocalDriver(['root' => resource_path('lang')]);

foreach ($translations as $lang => $groups) {
Expand All @@ -51,4 +51,18 @@ public function handle(ApiClient $client, Translator $translator, FilesystemMana

$this->info("✔ All translations downloaded");
}

protected function dropEmptyString(array $array) {
$array = array_map(function ($value) {
if (is_array($value)) {
return $this->dropEmptyString($value);
}

return $value;
}, $array);

return array_filter($array, function($value) {
return !is_null($value) && $value !== '';
});
}
}

0 comments on commit 851b2c8

Please sign in to comment.