@@ -23,33 +23,35 @@ class TranslationHelperCommand extends Command
23
23
*/
24
24
public function handle ()
25
25
{
26
- $ translationKeys = $ this ->findProjectTranslationsKeys ();
26
+ $ translationKeys = $ this ->findProjectTranslationsKeys ();
27
27
$ translationFiles = $ this ->getProjectTranslationFiles ();
28
28
29
29
foreach ($ translationFiles as $ file ) {
30
30
$ translationData = $ this ->getAlreadyTranslatedKeys ($ file );
31
- $ this ->line ("Language: " . str_replace ('.json ' , '' , basename ($ file )));
32
- $ added = [];
31
+ $ added = [];
32
+
33
+ $ this ->line ('Language: ' . str_replace ('.json ' , '' , basename ($ file )));
33
34
34
35
foreach ($ translationKeys as $ key ) {
35
36
if (!isset ($ translationData [$ key ])) {
36
- $ this ->warn (" - Added: {$ key }" );
37
37
$ translationData [$ key ] = '' ;
38
- $ added [] = $ key ;
38
+ $ added [] = $ key ;
39
+
40
+ $ this ->warn (" - Added: {$ key }" );
39
41
}
40
42
}
41
43
42
44
if ($ added ) {
43
- $ this ->line (" Updating translation file... " );
45
+ $ this ->line (' Updating translation file... ' );
44
46
45
47
$ this ->writeNewTranslationFile ($ file , $ translationData );
46
48
47
- $ this ->info (" Translation file have been updated! " );
49
+ $ this ->info (' Translation file have been updated! ' );
48
50
} else {
49
- $ this ->warn (" Nothing new found for this language. " );
51
+ $ this ->warn (' Nothing new found for this language. ' );
50
52
}
51
53
52
- $ this ->line ("" );
54
+ $ this ->line ('' );
53
55
}
54
56
}
55
57
@@ -58,11 +60,11 @@ public function handle()
58
60
*/
59
61
private function findProjectTranslationsKeys ()
60
62
{
61
- $ allKeys = [];
63
+ $ allKeys = [];
62
64
$ viewsDirectories = config ('translation-helper.scan_directories ' );
63
- $ fileExtensions = config ('translation-helper.file_extensions ' );
65
+ $ fileExtensions = config ('translation-helper.file_extensions ' );
64
66
65
- foreach ($ viewsDirectories as $ directory ) {
67
+ foreach ($ viewsDirectories as $ directory ) {
66
68
foreach ($ fileExtensions as $ extension ) {
67
69
$ this ->getTranslationKeysFromDir ($ allKeys , $ directory , $ extension );
68
70
}
@@ -102,11 +104,11 @@ private function getTranslationKeysFromFunction(&$keys, $functionName, $content)
102
104
103
105
preg_match_all ("# {$ functionName }\(\'(.*?)\'\)# " , $ content , $ matches );
104
106
105
- if ( ! empty ($ matches )) {
107
+ if (! empty ($ matches )) {
106
108
foreach ($ matches [1 ] as $ match ) {
107
109
$ match = str_replace ('" ' , "' " , str_replace ("\' " , "' " , $ match ));
108
110
109
- if ( ! empty ($ match )) {
111
+ if (! empty ($ match )) {
110
112
$ keys [$ match ] = $ match ;
111
113
}
112
114
}
@@ -118,7 +120,7 @@ private function getTranslationKeysFromFunction(&$keys, $functionName, $content)
118
120
*/
119
121
private function getProjectTranslationFiles ()
120
122
{
121
- $ path = config ('translation-helper.output_directory ' );
123
+ $ path = config ('translation-helper.output_directory ' );
122
124
$ files = glob ("{$ path }/*.json " , GLOB_BRACE );
123
125
124
126
return $ files ;
@@ -143,7 +145,7 @@ private function getAlreadyTranslatedKeys($filePath)
143
145
*/
144
146
private function writeNewTranslationFile ($ filePath , $ translations )
145
147
{
146
- file_put_contents ($ filePath , json_encode ($ translations , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ));
148
+ file_put_contents ($ filePath , json_encode ($ translations , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ));
147
149
}
148
150
149
151
/**
0 commit comments