Skip to content

Commit f858fdf

Browse files
committed
add command
1 parent c1a986e commit f858fdf

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Elegantly\Translator\Commands;
4+
5+
use Elegantly\Translator\Facades\Translator;
6+
use Illuminate\Console\Command;
7+
use Symfony\Component\Console\Helper\TableSeparator;
8+
9+
class ShowDeadTranslationsCommand extends Command
10+
{
11+
public $signature = 'translator:dead';
12+
13+
public $description = 'Show all dead translations defined in translations files but not used in the codebase.';
14+
15+
public function handle(): int
16+
{
17+
$rows = collect(Translator::getAllDeadTranslations())
18+
->flatMap(
19+
fn (array $namespaces, string $locale) => collect($namespaces)
20+
->flatMap(function (array $keys, string $namespace) use ($locale, $namespaces) {
21+
$values = array_map(fn (string $key) => [$locale, "{$namespace}.$key"], $keys);
22+
23+
if (array_key_last($namespaces) !== $namespace) {
24+
$values[] = [new TableSeparator, new TableSeparator];
25+
}
26+
27+
return $values;
28+
})
29+
)->toArray();
30+
31+
$this->table(
32+
headers: ['Language', 'Dead key'],
33+
rows: $rows
34+
);
35+
36+
return self::SUCCESS;
37+
}
38+
}

src/Facades/Translator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @method static Translations fixGrammarTranslations(string $locale, string $namespace, array $keys, ?GrammarServiceInterface $service)
1717
* @method static array<int, string> getMissingTranslations(string $referenceLocale, string $targetLocale, string $namespace)
1818
* @method static array getAllMissingTranslations(string $referenceLocale)
19+
* @method static array getAllDeadTranslations()
1920
* @method static void sortAllTranslations()
2021
*
2122
* @see \Elegantly\Translator\Translator

0 commit comments

Comments
 (0)