@@ -293,27 +293,34 @@ public function saveChanges() {
293
293
unset($ realPost ['type ' ]);
294
294
}
295
295
296
-
297
-
298
- switch ($ type ) {
299
- case 'missing ' :
300
- $ this ->updateSourceStrings ($ realPost , $ locale );
301
- break ;
302
- default :
303
- throw new Exception ('No handler for saving this type of record is implemented ' );
304
- break ;
305
- }
296
+ $ this ->updateSourceStrings ($ realPost , $ locale , $ type );
306
297
307
298
return true ;
308
299
}
309
300
310
301
/***
311
302
* @param $strings array The strings passed in from the HTML form.
312
303
*/
313
- private function updateSourceStrings ($ strings , $ locale ) {
304
+ private function updateSourceStrings ($ strings , $ locale , $ type ) {
305
+
314
306
foreach ($ strings as $ key =>$ value ) {
315
- if ($ value == '' ) continue ;
316
- array_push ($ this ->localeStrings [$ locale ], array ($ key , $ value ));
307
+
308
+
309
+ if ($ type == 'matching ' ) {
310
+ $ i = 0 ;
311
+ foreach ($ this ->localeStrings [$ locale ] as $ localeString ) {
312
+ if ($ key == $ localeString [0 ]) {
313
+ $ this ->localeStrings [$ locale ][$ i ][1 ] = $ value ;
314
+ continue ;
315
+ }
316
+ $ i ++;
317
+ }
318
+ }
319
+
320
+ if ($ type == 'missing ' ) {
321
+ if ($ value == '' ) continue ;
322
+ array_push ($ this ->localeStrings [$ locale ], array ($ key , $ value ));
323
+ }
317
324
}
318
325
319
326
$ this ->saveSourceStringsToFile ($ locale );
@@ -324,8 +331,16 @@ private function saveSourceStringsToFile($locale) {
324
331
$ output = '{ ' ;
325
332
326
333
for ($ i = 0 ; $ i < count ($ this ->localeStrings [$ locale ]); $ i ++) {
334
+
335
+ if ($ this ->localeStrings [$ locale ][$ i ][1 ] == '' ) continue ;
336
+
327
337
$ output .= '" ' . $ this ->localeStrings [$ locale ][$ i ][0 ] . '": " ' ;
328
- $ output .= str_replace ("\n" , '\n ' , $ this ->localeStrings [$ locale ][$ i ][1 ]);
338
+
339
+ if (strpos ($ this ->localeStrings [$ locale ][$ i ][1 ], "\n" ) !== false ) {
340
+ $ output .= str_replace ("\r\n" , "\\n " , $ this ->localeStrings [$ locale ][$ i ][1 ]);
341
+ } else {
342
+ $ output .= $ this ->localeStrings [$ locale ][$ i ][1 ];
343
+ }
329
344
$ output .= ($ i == count ($ this ->localeStrings [$ locale ]) -1 ) ? '" ' : '", ' ;
330
345
}
331
346
0 commit comments