@@ -52,13 +52,24 @@ public function export()
52
52
return $ this ;
53
53
}
54
54
55
- // Collect language files and build array with translations
56
- $ files = $ this ->findLanguageFiles ( resource_path ( 'lang ' ) );
55
+ foreach ( config ( 'laravel-localization.paths.lang_dirs ' ) as $ dir ) {
57
56
58
- // Parse translations and create final array
59
- array_walk ( $ files [ 'lang ' ], [ $ this , 'parseLangFiles ' ] );
60
- array_walk ( $ files [ 'vendor ' ], [ $ this , 'parseVendorFiles ' ] );
61
- array_walk ( $ files [ 'json ' ], [ $ this , 'parseJsonFiles ' ] );
57
+ try {
58
+
59
+ // Collect language files and build array with translations
60
+ $ files = $ this ->findLanguageFiles ( $ dir );
61
+
62
+ // Parse translations and create final array
63
+ array_walk ( $ files [ 'lang ' ], [ $ this , 'parseLangFiles ' ], $ dir );
64
+ array_walk ( $ files [ 'vendor ' ], [ $ this , 'parseVendorFiles ' ], $ dir );
65
+ array_walk ( $ files [ 'json ' ], [ $ this , 'parseJsonFiles ' ], $ dir );
66
+
67
+ } catch ( \Exception $ exception ) {
68
+
69
+ \Log::critical ( 'Can \'t read lang directory ' . $ dir . ', error: ' . $ exception ->getMessage () );
70
+ }
71
+
72
+ }
62
73
63
74
// Trigger event for final translated array
64
75
event ( new LaravelLocalizationExported ( $ this ->strings ) );
@@ -112,8 +123,8 @@ protected function findLanguageFiles( $path )
112
123
sort ( $ files );
113
124
114
125
// Remove full path from items
115
- array_walk ( $ files , function ( &$ item ) {
116
- $ item = str_replace ( resource_path ( ' lang ' ) , '' , $ item );
126
+ array_walk ( $ files , function ( &$ item ) use ( $ path ) {
127
+ $ item = str_replace ( $ path , '' , $ item );
117
128
} );
118
129
119
130
// Fetch non-vendor files from filtered php files
@@ -224,19 +235,29 @@ public function toCollection()
224
235
*
225
236
* @param string $file
226
237
*/
227
- protected function parseLangFiles ( $ file )
238
+ protected function parseLangFiles ( $ file, $ key , $ dir )
228
239
{
229
240
// Base package name without file ending
230
241
$ packageName = basename ( $ file , '.php ' );
231
242
232
243
// Get package, language and file contents from language file
233
244
// /<language_code>/(<package/)<filename>.php
234
245
$ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 1 ];
235
- $ fileContents = require resource_path ( ' lang ' ) . DIRECTORY_SEPARATOR . $ file ;
246
+ $ fileContents = require $ dir . DIRECTORY_SEPARATOR . $ file ;
236
247
237
248
// Check if language already exists in array
238
249
if ( array_key_exists ( $ language , $ this ->strings ) ) {
239
- $ this ->strings [ $ language ][ $ packageName ] = $ fileContents ;
250
+
251
+ if ( array_key_exists ( $ packageName , $ this ->strings [ $ language ] ) ) {
252
+
253
+ $ this ->strings [ $ language ][ $ packageName ] =
254
+ array_replace_recursive ( (array ) $ this ->strings [ $ language ][ $ packageName ], (array )
255
+ $ fileContents );
256
+ } else {
257
+
258
+ $ this ->strings [ $ language ][ $ packageName ] = $ fileContents ;
259
+ }
260
+
240
261
} else {
241
262
$ this ->strings [ $ language ] = [
242
263
$ packageName => $ fileContents ,
@@ -249,7 +270,7 @@ protected function parseLangFiles( $file )
249
270
*
250
271
* @param string $file
251
272
*/
252
- protected function parseVendorFiles ( $ file )
273
+ protected function parseVendorFiles ( $ file, $ key , $ dir )
253
274
{
254
275
// Base package name without file ending
255
276
$ packageName = basename ( $ file , '.php ' );
@@ -258,14 +279,26 @@ protected function parseVendorFiles( $file )
258
279
// /vendor/<package>/<language_code>/<filename>.php
259
280
$ package = explode ( DIRECTORY_SEPARATOR , $ file )[ 2 ];
260
281
$ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 3 ];
261
- $ fileContents = require resource_path ( ' lang ' ) . DIRECTORY_SEPARATOR . $ file ;
282
+ $ fileContents = require $ dir . DIRECTORY_SEPARATOR . $ file ;
262
283
263
284
// Check if language already exists in array
264
285
if ( array_key_exists ( $ language , $ this ->strings ) ) {
265
286
// Check if package already exists in language
266
287
if ( array_key_exists ( $ package , $ this ->strings [ $ language ] ) ) {
267
- $ this ->strings [ $ language ][ $ package ][ $ packageName ] = $ fileContents ;
288
+
289
+ if ( array_key_exists ( $ packageName , $ this ->strings [ $ language ][ $ package ] ) ) {
290
+
291
+ $ this ->strings [ $ language ][ $ package ][ $ packageName ] =
292
+ array_replace_recursive ( (array ) $ this ->strings [ $ language ][ $ package ][ $ packageName ],
293
+ (array )
294
+ $ fileContents );
295
+
296
+ } else {
297
+
298
+ $ this ->strings [ $ language ][ $ package ][ $ packageName ] = $ fileContents ;
299
+ }
268
300
} else {
301
+
269
302
$ this ->strings [ $ language ][ $ package ] = [ $ packageName => $ fileContents ];
270
303
}
271
304
} else {
@@ -279,19 +312,26 @@ protected function parseVendorFiles( $file )
279
312
}
280
313
}
281
314
282
- protected function parseJsonFiles ( $ file )
315
+ protected function parseJsonFiles ( $ file, $ key , $ dir )
283
316
{
284
317
// Base package name without file ending
285
318
$ language = basename ( $ file , '.json ' );
286
319
287
320
// Get package, language and file contents from language file
288
321
// /<language_code>/(<package/)<filename>.php
289
- $ fileContents = json_decode ( file_get_contents ( resource_path ( ' lang ' ) . $ file ) );
322
+ $ fileContents = json_decode ( file_get_contents ( $ dir . $ file ) );
290
323
291
324
// Check if language already exists in array
292
325
if ( array_key_exists ( 'json ' , $ this ->strings ) ) {
293
326
294
- $ this ->strings [ 'json ' ][ $ language ] = $ fileContents ;
327
+ if ( array_key_exists ( $ language , $ this ->strings [ 'json ' ] ) ) {
328
+
329
+ $ this ->strings [ 'json ' ][ $ language ] =
330
+ array_replace_recursive ( (array ) $ this ->strings [ 'json ' ][ $ language ], (array ) $ fileContents );
331
+
332
+ } else {
333
+ $ this ->strings [ 'json ' ][ $ language ] = $ fileContents ;
334
+ }
295
335
} else {
296
336
$ this ->strings [ 'json ' ] = [
297
337
0 commit comments