@@ -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,25 @@ 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 ;
194
+ }
187
195
}
188
196
}
189
197
}
190
198
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 )) {
202
+ $ buffer = array_keys (
203
+ get_object_vars ($ default_json_strings )
204
+ );
205
+
206
+ $ results [$ default_key ] = array_combine ($ buffer , $ buffer );
207
+ }
208
+
191
209
return $ results ;
192
210
}
193
211
0 commit comments