File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments