@@ -26,7 +26,7 @@ class ExportLocalizations implements \JsonSerializable
26
26
/**
27
27
* @var string
28
28
*/
29
- protected $ excludePath = DIRECTORY_SEPARATOR . 'vendor ' . DIRECTORY_SEPARATOR ;
29
+ protected $ excludePath = DIRECTORY_SEPARATOR . 'vendor ' . DIRECTORY_SEPARATOR ;
30
30
31
31
/**
32
32
* @var string
@@ -41,29 +41,29 @@ class ExportLocalizations implements \JsonSerializable
41
41
public function export ()
42
42
{
43
43
// Check if value is cached and set array to cached version
44
- if ( Cache::has ( config ( 'laravel-localization.caches.key ' ) ) ) {
45
- $ this ->strings = Cache::get ( config ( 'laravel-localization.caches.key ' ) );
44
+ if (Cache::has (config ('laravel-localization.caches.key ' )) ) {
45
+ $ this ->strings = Cache::get (config ('laravel-localization.caches.key ' ) );
46
46
47
47
return $ this ;
48
48
}
49
49
50
50
// Collect language files and build array with translations
51
- $ files = $ this ->findLanguageFiles ( resource_path ( 'lang ' ) );
51
+ $ files = $ this ->findLanguageFiles (resource_path ('lang ' ) );
52
52
53
53
// Parse translations and create final array
54
- array_walk ( $ files [ 'lang ' ], [ $ this , 'parseLangFiles ' ] );
55
- array_walk ( $ files [ 'vendor ' ], [ $ this , 'parseVendorFiles ' ] );
54
+ array_walk ($ files ['lang ' ], [$ this , 'parseLangFiles ' ] );
55
+ array_walk ($ files ['vendor ' ], [$ this , 'parseVendorFiles ' ] );
56
56
57
57
// Trigger event for final translated array
58
- event ( new LaravelLocalizationExported ( $ this ->strings ) );
58
+ event (new LaravelLocalizationExported ($ this ->strings ) );
59
59
60
60
// If timeout > 0 save array to cache
61
- if ( config ( 'laravel-localization.caches.timeout ' , 0 ) > 0 ) {
62
- Cache::store ( config ( 'laravel-localization.caches.driver ' , 'file ' ) )
61
+ if (config ('laravel-localization.caches.timeout ' , 0 ) > 0 ) {
62
+ Cache::store (config ('laravel-localization.caches.driver ' , 'file ' ) )
63
63
->put (
64
- config ( 'laravel-localization.caches.key ' , 'localization.array ' ),
64
+ config ('laravel-localization.caches.key ' , 'localization.array ' ),
65
65
$ this ->strings ,
66
- config ( 'laravel-localization.caches.timeout ' , 60 )
66
+ config ('laravel-localization.caches.timeout ' , 60 )
67
67
);
68
68
}
69
69
@@ -77,40 +77,40 @@ public function export()
77
77
*
78
78
* @return array
79
79
*/
80
- protected function findLanguageFiles ( $ path )
80
+ protected function findLanguageFiles ($ path )
81
81
{
82
82
// Loop through directories
83
- $ dirIterator = new \RecursiveDirectoryIterator ( $ path , \RecursiveDirectoryIterator::SKIP_DOTS );
84
- $ recIterator = new \RecursiveIteratorIterator ( $ dirIterator );
83
+ $ dirIterator = new \RecursiveDirectoryIterator ($ path , \RecursiveDirectoryIterator::SKIP_DOTS );
84
+ $ recIterator = new \RecursiveIteratorIterator ($ dirIterator );
85
85
86
86
// Fetch only php files - skip others
87
87
$ phpFiles = array_values (
88
- array_map ( 'current ' ,
88
+ array_map ('current ' ,
89
89
iterator_to_array (
90
- new \RegexIterator ( $ recIterator , $ this ->phpRegex , \RecursiveRegexIterator::GET_MATCH )
90
+ new \RegexIterator ($ recIterator , $ this ->phpRegex , \RecursiveRegexIterator::GET_MATCH )
91
91
)
92
92
)
93
93
);
94
94
95
95
// Sort array by filepath
96
- sort ( $ phpFiles );
96
+ sort ($ phpFiles );
97
97
98
98
// Remove full path from items
99
- array_walk ( $ phpFiles , function ( &$ item ) {
100
- $ item = str_replace ( resource_path ( 'lang ' ), '' , $ item );
101
- } );
99
+ array_walk ($ phpFiles , function (&$ item ) {
100
+ $ item = str_replace (resource_path ('lang ' ), '' , $ item );
101
+ });
102
102
103
103
// Fetch non-vendor files from filtered php files
104
- $ nonVendorFiles = array_filter ( $ phpFiles , function ( $ file ) {
105
- return strpos ( $ file , $ this ->excludePath ) === false ;
106
- } );
104
+ $ nonVendorFiles = array_filter ($ phpFiles , function ($ file ) {
105
+ return strpos ($ file , $ this ->excludePath ) === false ;
106
+ });
107
107
108
108
// Fetch vendor files from filtered php files
109
- $ vendorFiles = array_diff ( $ phpFiles , $ nonVendorFiles );
109
+ $ vendorFiles = array_diff ($ phpFiles , $ nonVendorFiles );
110
110
111
111
return [
112
- 'lang ' => array_values ( $ nonVendorFiles ),
113
- 'vendor ' => array_values ( $ vendorFiles ),
112
+ 'lang ' => array_values ($ nonVendorFiles ),
113
+ 'vendor ' => array_values ($ vendorFiles ),
114
114
];
115
115
}
116
116
@@ -143,13 +143,13 @@ public function toArray()
143
143
*
144
144
* @return array
145
145
*/
146
- public function toFlat ( $ prefix = '. ' )
146
+ public function toFlat ($ prefix = '. ' )
147
147
{
148
148
$ results = [];
149
- foreach ( $ this ->strings as $ lang => $ strings ) {
150
- foreach ( $ strings as $ lang_array => $ lang_messages ) {
151
- $ key = $ lang . $ prefix . $ lang_array ;
152
- $ results [ $ key ] = $ lang_messages ;
149
+ foreach ($ this ->strings as $ lang => $ strings ) {
150
+ foreach ($ strings as $ lang_array => $ lang_messages ) {
151
+ $ key = $ lang. $ prefix. $ lang_array ;
152
+ $ results [$ key ] = $ lang_messages ;
153
153
}
154
154
}
155
155
@@ -163,29 +163,29 @@ public function toFlat( $prefix = '.' )
163
163
*/
164
164
public function toCollection ()
165
165
{
166
- return collect ( $ this ->strings );
166
+ return collect ($ this ->strings );
167
167
}
168
168
169
169
/**
170
170
* Method to parse language files.
171
171
*
172
172
* @param string $file
173
173
*/
174
- protected function parseLangFiles ( $ file )
174
+ protected function parseLangFiles ($ file )
175
175
{
176
176
// Base package name without file ending
177
- $ packageName = basename ( $ file , '.php ' );
177
+ $ packageName = basename ($ file , '.php ' );
178
178
179
179
// Get package, language and file contents from language file
180
180
// /<language_code>/(<package/)<filename>.php
181
- $ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 1 ];
182
- $ fileContents = require resource_path ( 'lang ' ) . DIRECTORY_SEPARATOR . $ file ;
181
+ $ language = explode (DIRECTORY_SEPARATOR , $ file)[ 1 ];
182
+ $ fileContents = require resource_path ('lang ' ). DIRECTORY_SEPARATOR . $ file ;
183
183
184
184
// Check if language already exists in array
185
- if ( array_key_exists ( $ language , $ this ->strings ) ) {
186
- $ this ->strings [ $ language ][ $ packageName ] = $ fileContents ;
185
+ if (array_key_exists ($ language , $ this ->strings ) ) {
186
+ $ this ->strings [$ language][ $ packageName ] = $ fileContents ;
187
187
} else {
188
- $ this ->strings [ $ language ] = [
188
+ $ this ->strings [$ language ] = [
189
189
$ packageName => $ fileContents ,
190
190
];
191
191
}
@@ -196,30 +196,27 @@ protected function parseLangFiles( $file )
196
196
*
197
197
* @param string $file
198
198
*/
199
- protected function parseVendorFiles ( $ file )
199
+ protected function parseVendorFiles ($ file )
200
200
{
201
201
// Base package name without file ending
202
- $ packageName = basename ( $ file , '.php ' );
202
+ $ packageName = basename ($ file , '.php ' );
203
203
204
204
// Get package, language and file contents from language file
205
205
// /vendor/<package>/<language_code>/<filename>.php
206
- $ package = explode ( DIRECTORY_SEPARATOR , $ file )[ 2 ];
207
- $ language = explode ( DIRECTORY_SEPARATOR , $ file )[ 3 ];
208
- $ fileContents = require resource_path ( 'lang ' ) . DIRECTORY_SEPARATOR . $ file ;
206
+ $ package = explode (DIRECTORY_SEPARATOR , $ file)[ 2 ];
207
+ $ language = explode (DIRECTORY_SEPARATOR , $ file)[ 3 ];
208
+ $ fileContents = require resource_path ('lang ' ). DIRECTORY_SEPARATOR . $ file ;
209
209
210
210
// Check if language already exists in array
211
- if ( array_key_exists ( $ language , $ this ->strings ) ) {
211
+ if (array_key_exists ($ language , $ this ->strings ) ) {
212
212
// Check if package already exists in language
213
- if ( array_key_exists ( $ package , $ this ->strings [ $ language ] ) ) {
214
-
215
- array_push ( $ this ->strings [ $ language ][ $ package ], [ $ packageName => $ fileContents ] );
213
+ if (array_key_exists ($ package , $ this ->strings [$ language ])) {
214
+ array_push ($ this ->strings [$ language ][$ package ], [$ packageName => $ fileContents ]);
216
215
} else {
217
-
218
- $ this ->strings [ $ language ][ $ package ] = [ $ packageName => $ fileContents ];
216
+ $ this ->strings [$ language ][$ package ] = [$ packageName => $ fileContents ];
219
217
}
220
-
221
218
} else {
222
- $ this ->strings [ $ language ] = [
219
+ $ this ->strings [$ language ] = [
223
220
224
221
$ package => [
225
222
0 commit comments