@@ -33,6 +33,14 @@ class LangJsGenerator
33
33
*/
34
34
protected $ messagesIncluded = [];
35
35
36
+ /**
37
+ * Name of the domain in which all string-translation should be stored under.
38
+ * More about string-translation: https://laravel.com/docs/master/localization#retrieving-translation-strings
39
+ *
40
+ * @var string
41
+ */
42
+ protected $ stringsDomain = 'strings ' ;
43
+
36
44
/**
37
45
* Construct a new LangJsGenerator instance.
38
46
*
@@ -116,8 +124,8 @@ protected function getMessages()
116
124
117
125
foreach ($ this ->file ->allFiles ($ path ) as $ file ) {
118
126
$ pathName = $ file ->getRelativePathName ();
119
-
120
- if ($ this -> file -> extension ( $ pathName ) !== 'php ' ) {
127
+ $ extension = $ this -> file -> extension ( $ pathName );
128
+ if ($ extension != 'php ' && $ extension != ' json ' ) {
121
129
continue ;
122
130
}
123
131
@@ -128,12 +136,19 @@ protected function getMessages()
128
136
$ key = substr ($ pathName , 0 , -4 );
129
137
$ key = str_replace ('\\' , '. ' , $ key );
130
138
$ key = str_replace ('/ ' , '. ' , $ key );
131
-
139
+
132
140
if (starts_with ($ key , 'vendor ' )) {
133
141
$ key = $ this ->getVendorKey ($ key );
134
142
}
135
143
136
- $ messages [$ key ] = include $ path . DIRECTORY_SEPARATOR . $ pathName ;
144
+ $ fullPath = $ path .DIRECTORY_SEPARATOR .$ pathName ;
145
+ if ($ extension == 'php ' ) {
146
+ $ messages [$ key ] = include $ fullPath ;
147
+ } else {
148
+ $ key = $ key .$ this ->stringsDomain ;
149
+ $ fileContent = file_get_contents ($ fullPath );
150
+ $ messages [$ key ] = json_decode ($ fileContent , true );
151
+ }
137
152
}
138
153
139
154
$ this ->sortMessages ($ messages );
0 commit comments