44
55use Illuminate \Contracts \Console \PromptsForMissingInput ;
66
7+ use function Laravel \Prompts \info ;
78use function Laravel \Prompts \intro ;
89use function Laravel \Prompts \note ;
910use function Laravel \Prompts \table ;
1011
1112class MissingCommand extends TranslatorCommand implements PromptsForMissingInput
1213{
13- public $ signature = 'translator:missing {locale} {--driver=} ' ;
14+ public $ signature = 'translator:missing {locale} {--sync : Add the missing keys to your driver} {-- driver=} ' ;
1415
1516 public $ description = 'Display all the translation keys found in the codebase but not in the driver. ' ;
1617
1718 public function handle (): int
1819 {
1920 $ locale = $ this ->argument ('locale ' );
21+ $ sync = (bool ) $ this ->option ('sync ' );
2022
2123 $ translator = $ this ->getTranslator ();
2224
23- $ undefined = $ translator ->getMissingTranslations ($ locale );
25+ $ missing = $ translator ->getMissingTranslations ($ locale );
2426
2527 intro ('Using driver: ' .$ translator ->driver ::class);
2628
27- note (count ($ undefined ).' missing keys detected. ' );
29+ note (count ($ missing ).' missing keys detected. ' );
2830
2931 table (
3032 headers: ['Key ' , 'Count ' , 'Files ' ],
31- rows: collect ($ undefined )
33+ rows: collect ($ missing )
3234 ->map (function ($ value , $ key ) {
3335 return [
3436 str ($ key )->limit (20 )->value (),
@@ -43,6 +45,17 @@ public function handle(): int
4345 })->values ()->all ()
4446 );
4547
48+ if ($ sync ) {
49+
50+ $ translator ->setTranslations (
51+ locale: $ locale ,
52+ values: array_map (fn () => null , $ missing )
53+ );
54+
55+ info (count ($ missing ).' missing keys added to the driver. ' );
56+
57+ }
58+
4659 return self ::SUCCESS ;
4760 }
4861}
0 commit comments