@@ -66,11 +66,11 @@ public function export()
66
66
// If timeout > 0 save array to cache
67
67
if (config ('laravel-localization.caches.timeout ' , 0 ) > 0 ) {
68
68
Cache::store (config ('laravel-localization.caches.driver ' , 'file ' ))
69
- ->put (
70
- config ('laravel-localization.caches.key ' , 'localization.array ' ),
71
- $ this ->strings ,
72
- config ('laravel-localization.caches.timeout ' , 60 )
73
- );
69
+ ->put (
70
+ config ('laravel-localization.caches.key ' , 'localization.array ' ),
71
+ $ this ->strings ,
72
+ config ('laravel-localization.caches.timeout ' , 60 )
73
+ );
74
74
}
75
75
76
76
return $ this ;
@@ -170,6 +170,9 @@ public function toArray()
170
170
public function toFlat ($ prefix = '. ' )
171
171
{
172
172
$ results = [];
173
+ $ default_locale = config ('laravel-localization.js.default_locale ' );
174
+ $ default_json_strings = null ;
175
+
173
176
foreach ($ this ->strings as $ lang => $ strings ) {
174
177
if ($ lang !== 'json ' ) {
175
178
foreach ($ strings as $ lang_array => $ lang_messages ) {
@@ -184,10 +187,24 @@ public function toFlat($prefix = '.')
184
187
} else {
185
188
$ results [$ key ] = $ json_strings ;
186
189
}
190
+
191
+ // Pick only the first $json_strings
192
+ if (!$ default_json_strings )
193
+ $ default_json_strings = $ json_strings ;
187
194
}
188
195
}
189
196
}
190
197
198
+ // Create a JSON key value pair for the default language
199
+ $ default_key = $ default_locale . $ prefix . '__JSON__ ' ;
200
+ if (!array_key_exists ($ default_key , $ results )) {
201
+ $ buffer = array_keys (
202
+ get_object_vars ($ default_json_strings )
203
+ );
204
+
205
+ $ results [$ default_key ] = array_combine ($ buffer , $ buffer );
206
+ }
207
+
191
208
return $ results ;
192
209
}
193
210
0 commit comments