Skip to content

Commit 9c902a2

Browse files
committed
Added translation-check command
php artisan translation-check {LANG} For example: php artisan translation-check de
1 parent 62ed464 commit 9c902a2

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Support\Facades\File;
7+
use Illuminate\Support\Arr;
8+
9+
class CheckTranslations extends Command
10+
{
11+
protected $signature = 'translation-check {language}';
12+
protected $description = 'Check if translation files are up to date';
13+
14+
public function handle()
15+
{
16+
$defaultLanguage = 'en';
17+
$languageCode = $this->argument('language');
18+
$defaultTranslations = include base_path("resources/lang/{$defaultLanguage}/messages.php");
19+
$translations = include base_path("resources/lang/{$languageCode}/messages.php");
20+
21+
$missingKeys = $this->getMissingKeys($defaultTranslations, $translations);
22+
23+
if (count($missingKeys) > 0) {
24+
$this->output->error("{$languageCode} translation file is out of date!");
25+
$this->output->table(['Missing Keys'], $missingKeys);
26+
$this->output->error('Number of missing keys: ' . count($missingKeys));
27+
} else {
28+
$this->output->success("{$languageCode} translation file is up to date!");
29+
}
30+
}
31+
32+
protected function getMissingKeys(array $default, array $translations)
33+
{
34+
$missingKeys = [];
35+
36+
foreach (Arr::dot($default) as $key => $value) {
37+
if (!Arr::has($translations, $key)) {
38+
$missingKeys[] = [$key];
39+
}
40+
}
41+
42+
return $missingKeys;
43+
}
44+
}

0 commit comments

Comments
 (0)