File tree 1 file changed +33
-3
lines changed
1 file changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -18,20 +18,50 @@ public function generateFromPath($path)
18
18
19
19
$ locales = [];
20
20
$ dir = new DirectoryIterator ($ path );
21
+
21
22
foreach ($ dir as $ fileinfo ) {
22
23
if (!$ fileinfo ->isDot ()
23
- && $ fileinfo ->isDir ()
24
24
&& !in_array ($ fileinfo ->getFilename (), ['vendor ' ])
25
25
) {
26
- $ locales [$ fileinfo ->getFilename ()] =
27
- $ this ->allocateLocaleArray ($ path . '/ ' . $ fileinfo ->getFilename ());
26
+ $ noExt = $ this ->removeExtension ($ fileinfo ->getFilename ());
27
+
28
+ if ($ fileinfo ->isDir ()) {
29
+ $ local = $ this ->allocateLocaleArray ($ fileinfo ->getRealPath ());
30
+ } else {
31
+ $ local = $ this ->allocateLocaleJSON ($ fileinfo ->getRealPath ());
32
+ if ($ local === null ) continue ;
33
+ }
34
+
35
+ if (isset ($ locales [$ noExt ])) {
36
+ $ locales [$ noExt ] = array_merge ($ local , $ locales [$ noExt ]);
37
+ } else {
38
+ $ locales [$ noExt ] = $ local ;
39
+ }
28
40
}
29
41
}
30
42
31
43
return 'export default '
32
44
. json_encode ($ locales , JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ) . PHP_EOL ;
33
45
}
34
46
47
+ /**
48
+ * @param string $path
49
+ * @return array
50
+ */
51
+ private function allocateLocaleJSON ($ path )
52
+ {
53
+ // Ignore non *.json files (ex.: .gitignore, vim swap files etc.)
54
+ if (pathinfo ($ path , PATHINFO_EXTENSION ) !== 'json ' ) {
55
+ return null ;
56
+ }
57
+ $ tmp = (array ) json_decode (file_get_contents ($ path ));
58
+ if (gettype ($ tmp ) !== "array " ) {
59
+ throw new Exception ('Unexpected data while processing ' .$ path );
60
+ }
61
+
62
+ return $ tmp ;
63
+ }
64
+
35
65
/**
36
66
* @param string $path
37
67
* @return array
You can’t perform that action at this time.
0 commit comments