@@ -292,32 +292,63 @@ protected function writeTranslationFile($override_file = false)
292
292
}
293
293
}
294
294
295
- if ($ fd = fopen ($ file_path , 'w ' )) {
296
- // Get value of button save and stay
297
- $ save_and_stay = Tools::isSubmit ('submitTranslations ' .$ type .'AndStay ' );
298
-
299
- // Get language
300
- $ lang = strtolower (Tools::getValue ('lang ' ));
301
-
302
- // Unset all POST which are not translations
303
- unset(
304
- $ _POST ['submitTranslations ' .$ type ],
305
- $ _POST ['submitTranslations ' .$ type .'AndStay ' ],
306
- $ _POST ['lang ' ],
307
- $ _POST ['token ' ],
308
- $ _POST ['theme ' ],
309
- $ _POST ['type ' ]
310
- );
295
+ // Get value of button save and stay
296
+ $ save_and_stay = Tools::isSubmit ('submitTranslations ' .$ type .'AndStay ' );
297
+
298
+ // Get language
299
+ $ lang = strtolower (Tools::getValue ('lang ' ));
300
+
301
+ // Unset all POST which are not translations
302
+ unset(
303
+ $ _POST ['submitTranslations ' .$ type ],
304
+ $ _POST ['submitTranslations ' .$ type .'AndStay ' ],
305
+ $ _POST ['lang ' ],
306
+ $ _POST ['token ' ],
307
+ $ _POST ['theme ' ],
308
+ $ _POST ['type ' ]
309
+ );
310
+
311
+ // Get all POST which aren't empty
312
+ $ to_update = array ();
313
+ $ keysToUpdate = array ();
314
+ foreach ($ _POST as $ key => $ value ) {
315
+ $ keysToUpdate [] = $ key ;
316
+ $ to_update [$ key ] = $ value ;
317
+ }
318
+ include_once ($ file_path );
319
+ switch ($ this ->type_selected ) {
320
+ case 'front ' :
321
+ $ to_insert = $ GLOBALS ['_LANG ' ];
322
+ break ;
323
+ case 'back ' :
324
+ $ to_insert = $ GLOBALS ['_LANGADM ' ];
325
+ break ;
326
+ case 'errors ' :
327
+ $ to_insert = $ GLOBALS ['_ERRORS ' ];
328
+ break ;
329
+ case 'fields ' :
330
+ $ to_insert = $ GLOBALS ['_FIELDS ' ];
331
+ break ;
332
+ case 'pdf ' :
333
+ $ to_insert = $ GLOBALS ['_LANGPDF ' ];
334
+ break ;
311
335
312
- // Get all POST which aren't empty
313
- $ to_insert = array ();
314
- foreach ($ _POST as $ key => $ value ) {
315
- if (!empty ($ value )) {
316
- $ to_insert [$ key ] = $ value ;
336
+ }
337
+ foreach ($ to_insert as $ key => $ value ) {
338
+ if (in_array ($ key , $ keysToUpdate )) {
339
+ if ($ to_update [$ key ]) {
340
+ $ to_insert [$ key ] = $ to_update [$ key ];
341
+ } else {
342
+ unset($ to_insert [$ key ]);
317
343
}
344
+ unset($ to_update [$ key ]);
318
345
}
346
+ }
347
+ foreach ($ to_update as $ key => $ value ) {
348
+ $ to_insert [$ key ] = $ value ;
349
+ }
319
350
320
- // translations array is ordered by key (easy merge)
351
+ if ( $ fd = fopen ( $ file_path , ' w ' )) {
321
352
ksort ($ to_insert );
322
353
$ tab = $ translation_informations ['var ' ];
323
354
fwrite ($ fd , "<?php \n\nglobal \$" .$ tab ."; \n\$" .$ tab ." = array(); \n" );
@@ -929,9 +960,12 @@ protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_n
929
960
static $ cache_file = array ();
930
961
static $ str_write = '' ;
931
962
static $ array_check_duplicate = array ();
963
+ static $ module_existing_translations = array ();
932
964
933
965
// Set file_name in static var, this allow to open and wright the file just one time
934
966
if (!isset ($ cache_file [$ theme_name .'- ' .$ file_name ])) {
967
+ require $ file_name ;
968
+ $ module_existing_translations = $ _MODULE ;
935
969
$ str_write = '' ;
936
970
$ cache_file [$ theme_name .'- ' .$ file_name ] = true ;
937
971
if (!Tools::file_exists_cache (dirname ($ file_name ))) {
@@ -984,6 +1018,13 @@ protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_n
984
1018
$ this ->total_expression ++;
985
1019
}
986
1020
}
1021
+ foreach ($ module_existing_translations as $ key => $ value ) {
1022
+ if (!in_array ('\'' .$ key .'\'' , $ array_check_duplicate )) {
1023
+ $ str_write .= '$_MODULE[ \'' .$ key .'\'] = \'' .pSQL (str_replace (array ("\r\n" , "\r" , "\n" ), ' ' , $ value )).'\'; ' ."\n" ;
1024
+
1025
+ }
1026
+ }
1027
+
987
1028
}
988
1029
}
989
1030
0 commit comments