Skip to content

Commit

Permalink
[item] Allow output of untranslated attributes to csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
rastislav-chynoransky committed Dec 14, 2024
1 parent f0c259e commit 76913b4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/Console/Commands/DumpUntranslatedAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use Illuminate\Console\Command;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;
use League\Csv\Writer;

class DumpUntranslatedAttributes extends Command
{
protected $signature = 'items:dump-untranslated-attributes
{--prefix= : Filter by prefix}';
{--prefix= : Filter by prefix}
{--output= : Output to CSV file}';

private array $attributes = [
'work_type' => 'item.work_types',
Expand All @@ -25,12 +27,25 @@ public function handle(): int
$attribute = $this->choice('Select attribute', array_keys($this->attributes));
$locale = $this->choice('Select locale', config('translatable.locales'));
$prefix = $this->option('prefix');
$output = $this->option('output');

$rows = $this->getUntranslatedAttributes($attribute, $locale, $prefix)
->map(fn ($count, $value) => [$value, $count]);

$header = sprintf('%s (%s)', Str::ucfirst(trans("item.$attribute")), Str::upper($locale));
$this->table([$header, 'Count'], $rows);
$header = [
sprintf('%s (%s)', Str::ucfirst(trans("item.$attribute")), Str::upper($locale)),
'Count',
];

if ($output) {
$writer = Writer::createFromPath($output, 'w+');
$writer->insertOne($header);
$writer->insertAll($rows);

$this->info("Data has been exported to $output");
} else {
$this->table($header, $rows);
}

return self::SUCCESS;
}
Expand Down

0 comments on commit 76913b4

Please sign in to comment.