@@ -31,7 +31,7 @@ class ExportLocalizations implements \JsonSerializable
31
31
/**
32
32
* @var string
33
33
*/
34
- protected $ excludePath = DIRECTORY_SEPARATOR . 'vendor ' . DIRECTORY_SEPARATOR ;
34
+ protected $ excludePath = DIRECTORY_SEPARATOR . 'vendor ' . DIRECTORY_SEPARATOR ;
35
35
36
36
/**
37
37
* @var string
@@ -46,30 +46,30 @@ class ExportLocalizations implements \JsonSerializable
46
46
public function export ()
47
47
{
48
48
// Check if value is cached and set array to cached version
49
- if ( Cache::has ( config ( 'laravel-localization.caches.key ' ) ) ) {
50
- $ this ->strings = Cache::get ( config ( 'laravel-localization.caches.key ' ) );
49
+ if (Cache::has (config ('laravel-localization.caches.key ' )) ) {
50
+ $ this ->strings = Cache::get (config ('laravel-localization.caches.key ' ) );
51
51
52
52
return $ this ;
53
53
}
54
54
55
55
// Collect language files and build array with translations
56
- $ files = $ this ->findLanguageFiles ( resource_path ( 'lang ' ) );
56
+ $ files = $ this ->findLanguageFiles (resource_path ('lang ' ) );
57
57
58
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 ' ] );
59
+ array_walk ($ files ['lang ' ], [$ this , 'parseLangFiles ' ] );
60
+ array_walk ($ files ['vendor ' ], [$ this , 'parseVendorFiles ' ] );
61
+ array_walk ($ files ['json ' ], [$ this , 'parseJsonFiles ' ] );
62
62
63
63
// Trigger event for final translated array
64
- event ( new LaravelLocalizationExported ( $ this ->strings ) );
64
+ event (new LaravelLocalizationExported ($ this ->strings ) );
65
65
66
66
// If timeout > 0 save array to cache
67
- if ( config ( 'laravel-localization.caches.timeout ' , 0 ) > 0 ) {
68
- Cache::store ( config ( 'laravel-localization.caches.driver ' , 'file ' ) )
67
+ if (config ('laravel-localization.caches.timeout ' , 0 ) > 0 ) {
68
+ Cache::store (config ('laravel-localization.caches.driver ' , 'file ' ) )
69
69
->put (
70
- config ( 'laravel-localization.caches.key ' , 'localization.array ' ),
70
+ config ('laravel-localization.caches.key ' , 'localization.array ' ),
71
71
$ this ->strings ,
72
- config ( 'laravel-localization.caches.timeout ' , 60 )
72
+ config ('laravel-localization.caches.timeout ' , 60 )
73
73
);
74
74
}
75
75
@@ -83,58 +83,58 @@ public function export()
83
83
*
84
84
* @return array
85
85
*/
86
- protected function findLanguageFiles ( $ path )
86
+ protected function findLanguageFiles ($ path )
87
87
{
88
88
// Loop through directories
89
- $ dirIterator = new \RecursiveDirectoryIterator ( $ path , \RecursiveDirectoryIterator::SKIP_DOTS );
90
- $ recIterator = new \RecursiveIteratorIterator ( $ dirIterator );
89
+ $ dirIterator = new \RecursiveDirectoryIterator ($ path , \RecursiveDirectoryIterator::SKIP_DOTS );
90
+ $ recIterator = new \RecursiveIteratorIterator ($ dirIterator );
91
91
92
92
// Fetch only php files - skip others
93
93
$ phpFiles = array_values (
94
- array_map ( 'current ' ,
94
+ array_map ('current ' ,
95
95
iterator_to_array (
96
- new \RegexIterator ( $ recIterator , $ this ->phpRegex , \RecursiveRegexIterator::GET_MATCH )
96
+ new \RegexIterator ($ recIterator , $ this ->phpRegex , \RecursiveRegexIterator::GET_MATCH )
97
97
)
98
98
)
99
99
);
100
100
101
101
$ jsonFiles = array_values (
102
- array_map ( 'current ' ,
102
+ array_map ('current ' ,
103
103
iterator_to_array (
104
- new \RegexIterator ( $ recIterator , $ this ->jsonRegex , \RecursiveRegexIterator::GET_MATCH )
104
+ new \RegexIterator ($ recIterator , $ this ->jsonRegex , \RecursiveRegexIterator::GET_MATCH )
105
105
)
106
106
)
107
107
);
108
108
109
- $ files = array_merge ( $ phpFiles , $ jsonFiles );
109
+ $ files = array_merge ($ phpFiles , $ jsonFiles );
110
110
111
111
// Sort array by filepath
112
- sort ( $ files );
112
+ sort ($ files );
113
113
114
114
// Remove full path from items
115
- array_walk ( $ files , function ( &$ item ) {
116
- $ item = str_replace ( resource_path ( 'lang ' ), '' , $ item );
117
- } );
115
+ array_walk ($ files , function (&$ item ) {
116
+ $ item = str_replace (resource_path ('lang ' ), '' , $ item );
117
+ });
118
118
119
119
// Fetch non-vendor files from filtered php files
120
- $ nonVendorFiles = array_filter ( $ files , function ( $ file ) {
121
- return strpos ( $ file , $ this ->excludePath ) === false && strpos ( $ file , '.json ' ) === false ;
122
- } );
120
+ $ nonVendorFiles = array_filter ($ files , function ($ file ) {
121
+ return strpos ($ file , $ this ->excludePath ) === false && strpos ($ file , '.json ' ) === false ;
122
+ });
123
123
124
124
// Fetch vendor files from filtered php files
125
- $ vendorFiles = array_filter ( array_diff ( $ files , $ nonVendorFiles ), function ( $ file ) {
126
- return strpos ( $ file , 'json ' ) === false ;
127
- } );
125
+ $ vendorFiles = array_filter (array_diff ($ files , $ nonVendorFiles ), function ($ file ) {
126
+ return strpos ($ file , 'json ' ) === false ;
127
+ });
128
128
129
129
// Fetch .json files from filtered files
130
- $ jsonFiles = array_filter ( $ files , function ( $ file ) {
131
- return strpos ( $ file , '.json ' ) !== false ;
132
- } );
130
+ $ jsonFiles = array_filter ($ files , function ($ file ) {
131
+ return strpos ($ file , '.json ' ) !== false ;
132
+ });
133
133
134
134
return [
135
- 'lang ' => array_values ( $ nonVendorFiles ),
136
- 'vendor ' => array_values ( $ vendorFiles ),
137
- 'json ' => array_values ( $ jsonFiles ),
135
+ 'lang ' => array_values ($ nonVendorFiles ),
136
+ 'vendor ' => array_values ($ vendorFiles ),
137
+ 'json ' => array_values ($ jsonFiles ),
138
138
];
139
139
}
140
140
@@ -167,43 +167,43 @@ public function toArray()
167
167
*
168
168
* @return array
169
169
*/
170
- public function toFlat ( $ prefix = '. ' )
170
+ public function toFlat ($ prefix = '. ' )
171
171
{
172
- $ results = [];
173
- $ default_locale = config ( 'laravel-localization.js.default_locale ' );
172
+ $ results = [];
173
+ $ default_locale = config ('laravel-localization.js.default_locale ' );
174
174
$ default_json_strings = null ;
175
175
176
- foreach ( $ this ->strings as $ lang => $ strings ) {
177
- if ( $ lang !== 'json ' ) {
178
- foreach ( $ strings as $ lang_array => $ lang_messages ) {
179
- $ key = $ lang . $ prefix . $ lang_array ;
180
- $ results [ $ key ] = $ lang_messages ;
176
+ foreach ($ this ->strings as $ lang => $ strings ) {
177
+ if ($ lang !== 'json ' ) {
178
+ foreach ($ strings as $ lang_array => $ lang_messages ) {
179
+ $ key = $ lang. $ prefix. $ lang_array ;
180
+ $ results [$ key ] = $ lang_messages ;
181
181
}
182
182
} else {
183
- foreach ( $ strings as $ json_lang => $ json_strings ) {
184
- $ key = $ json_lang . $ prefix . '__JSON__ ' ;
185
- if ( array_key_exists ( $ key , $ results ) ) {
186
- $ results [ $ key ] = $ json_strings ;
183
+ foreach ($ strings as $ json_lang => $ json_strings ) {
184
+ $ key = $ json_lang. $ prefix. '__JSON__ ' ;
185
+ if (array_key_exists ($ key , $ results) ) {
186
+ $ results [$ key ] = $ json_strings ;
187
187
} else {
188
- $ results [ $ key ] = $ json_strings ;
188
+ $ results [$ key ] = $ json_strings ;
189
189
}
190
190
191
191
// Pick only the first $json_strings
192
- if ( ! $ default_json_strings ) {
192
+ if (! $ default_json_strings ) {
193
193
$ default_json_strings = $ json_strings ;
194
194
}
195
195
}
196
196
}
197
197
}
198
198
199
199
// Create a JSON key value pair for the default language
200
- $ default_key = $ default_locale . $ prefix . '__JSON__ ' ;
201
- if ( ! array_key_exists ( $ default_key , $ results ) ) {
200
+ $ default_key = $ default_locale. $ prefix. '__JSON__ ' ;
201
+ if (! array_key_exists ($ default_key , $ results) ) {
202
202
$ buffer = array_keys (
203
- $ default_json_strings ? get_object_vars ( $ default_json_strings ) : []
203
+ $ default_json_strings ? get_object_vars ($ default_json_strings ) : []
204
204
);
205
205
206
- $ results [ $ default_key ] = array_combine ( $ buffer , $ buffer );
206
+ $ results [$ default_key ] = array_combine ($ buffer , $ buffer );
207
207
}
208
208
209
209
return $ results ;
@@ -216,29 +216,29 @@ public function toFlat( $prefix = '.' )
216
216
*/
217
217
public function toCollection ()
218
218
{
219
- return collect ( $ this ->strings );
219
+ return collect ($ this ->strings );
220
220
}
221
221
222
222
/**
223
223
* Method to parse language files.
224
224
*
225
225
* @param string $file
226
226
*/
227
- protected function parseLangFiles ( $ file )
227
+ protected function parseLangFiles ($ file )
228
228
{
229
229
// Base package name without file ending
230
- $ packageName = basename ( $ file , '.php ' );
230
+ $ packageName = basename ($ file , '.php ' );
231
231
232
232
// Get package, language and file contents from language file
233
233
// /<language_code>/(<package/)<filename>.php
234
- $ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 1 ];
235
- $ fileContents = require resource_path ( 'lang ' ) . DIRECTORY_SEPARATOR . $ file ;
234
+ $ language = explode (DIRECTORY_SEPARATOR , $ file)[ 1 ];
235
+ $ fileContents = require resource_path ('lang ' ). DIRECTORY_SEPARATOR . $ file ;
236
236
237
237
// Check if language already exists in array
238
- if ( array_key_exists ( $ language , $ this ->strings ) ) {
239
- $ this ->strings [ $ language ][ $ packageName ] = $ fileContents ;
238
+ if (array_key_exists ($ language , $ this ->strings ) ) {
239
+ $ this ->strings [$ language][ $ packageName ] = $ fileContents ;
240
240
} else {
241
- $ this ->strings [ $ language ] = [
241
+ $ this ->strings [$ language ] = [
242
242
$ packageName => $ fileContents ,
243
243
];
244
244
}
@@ -249,27 +249,27 @@ protected function parseLangFiles( $file )
249
249
*
250
250
* @param string $file
251
251
*/
252
- protected function parseVendorFiles ( $ file )
252
+ protected function parseVendorFiles ($ file )
253
253
{
254
254
// Base package name without file ending
255
- $ packageName = basename ( $ file , '.php ' );
255
+ $ packageName = basename ($ file , '.php ' );
256
256
257
257
// Get package, language and file contents from language file
258
258
// /vendor/<package>/<language_code>/<filename>.php
259
- $ package = explode ( DIRECTORY_SEPARATOR , $ file )[ 2 ];
260
- $ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 3 ];
261
- $ fileContents = require resource_path ( 'lang ' ) . DIRECTORY_SEPARATOR . $ file ;
259
+ $ package = explode (DIRECTORY_SEPARATOR , $ file)[ 2 ];
260
+ $ language = explode (DIRECTORY_SEPARATOR , $ file)[ 3 ];
261
+ $ fileContents = require resource_path ('lang ' ). DIRECTORY_SEPARATOR . $ file ;
262
262
263
263
// Check if language already exists in array
264
- if ( array_key_exists ( $ language , $ this ->strings ) ) {
264
+ if (array_key_exists ($ language , $ this ->strings ) ) {
265
265
// Check if package already exists in language
266
- if ( array_key_exists ( $ package , $ this ->strings [ $ language ] ) ) {
267
- $ this ->strings [ $ language ][ $ package ][ $ packageName ] = $ fileContents ;
266
+ if (array_key_exists ($ package , $ this ->strings [$ language]) ) {
267
+ $ this ->strings [$ language][ $ package][ $ packageName ] = $ fileContents ;
268
268
} else {
269
- $ this ->strings [ $ language ][ $ package ] = [ $ packageName => $ fileContents ];
269
+ $ this ->strings [$ language][ $ package ] = [$ packageName => $ fileContents ];
270
270
}
271
271
} else {
272
- $ this ->strings [ $ language ] = [
272
+ $ this ->strings [$ language ] = [
273
273
274
274
$ package => [
275
275
@@ -279,21 +279,20 @@ protected function parseVendorFiles( $file )
279
279
}
280
280
}
281
281
282
- protected function parseJsonFiles ( $ file )
282
+ protected function parseJsonFiles ($ file )
283
283
{
284
284
// Base package name without file ending
285
- $ language = basename ( $ file , '.json ' );
285
+ $ language = basename ($ file , '.json ' );
286
286
287
287
// Get package, language and file contents from language file
288
288
// /<language_code>/(<package/)<filename>.php
289
- $ fileContents = json_decode ( file_get_contents ( resource_path ( 'lang ' ) . $ file ) );
289
+ $ fileContents = json_decode (file_get_contents (resource_path ('lang ' ). $ file) );
290
290
291
291
// Check if language already exists in array
292
- if ( array_key_exists ( 'json ' , $ this ->strings ) ) {
293
-
294
- $ this ->strings [ 'json ' ][ $ language ] = $ fileContents ;
292
+ if (array_key_exists ('json ' , $ this ->strings )) {
293
+ $ this ->strings ['json ' ][$ language ] = $ fileContents ;
295
294
} else {
296
- $ this ->strings [ 'json ' ] = [
295
+ $ this ->strings ['json ' ] = [
297
296
298
297
$ language => $ fileContents ,
299
298
];
0 commit comments