Skip to content

Commit acafe22

Browse files
authored
Merge pull request #861 from shreesh-webkul/gli-1645
Updated: When translating text in QloApps only update the fields that are changed
2 parents e398e69 + c2af89b commit acafe22

File tree

5 files changed

+97
-22
lines changed

5 files changed

+97
-22
lines changed

admin/themes/default/template/controllers/translations/helpers/view/translation_errors.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{extends file="helpers/view/view.tpl"}
2727

2828
{block name="override_tpl"}
29+
{include file="./translation_inputs_update.tpl"}
2930
{if $mod_security_warning}
3031
<div class="alert alert-warning">
3132
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'}

admin/themes/default/template/controllers/translations/helpers/view/translation_form.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{extends file="helpers/view/view.tpl"}
2727

2828
{block name="override_tpl"}
29+
{include file="./translation_inputs_update.tpl"}
2930
{if $mod_security_warning}
3031
<div class="alert alert-warning">
3132
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{**
2+
* 2010-2023 Webkul.
3+
*
4+
* NOTICE OF LICENSE
5+
*
6+
* All right is reserved,
7+
* Please go through LICENSE.txt file inside our module
8+
*
9+
* DISCLAIMER
10+
*
11+
* Do not edit or add to this file if you wish to upgrade this module to newer
12+
* versions in the future. If you wish to customize this module for your
13+
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
14+
*
15+
* @author Webkul IN
16+
* @copyright 2010-2023 Webkul IN
17+
* @license LICENSE.txt
18+
*}
19+
20+
<script type="text/javascript">
21+
$(document).ready(function(){
22+
$('#translations_form input:text,textarea').each(function(){
23+
$(this).data('name',$(this).attr('name'));
24+
$(this).removeAttr('name');
25+
});
26+
$('#translations_form').on('change','input:text,textarea',function(){
27+
var name = $(this).data('name');
28+
if(name) $(this).attr('name',name);
29+
});
30+
});
31+
</script>

admin/themes/default/template/controllers/translations/helpers/view/translation_modules.tpl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{extends file="helpers/view/view.tpl"}
2727

2828
{block name="override_tpl"}
29+
{include file="./translation_inputs_update.tpl"}
2930
{if $mod_security_warning}
3031
<div class="alert alert-warning">
3132
{l s='Apache mod_security is activated on your server. This could result in some Bad Request errors'}

controllers/admin/AdminTranslationsController.php

+63-22
Original file line numberDiff line numberDiff line change
@@ -292,32 +292,63 @@ protected function writeTranslationFile($override_file = false)
292292
}
293293
}
294294

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;
311335

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]);
317343
}
344+
unset($to_update[$key]);
318345
}
346+
}
347+
foreach ($to_update as $key => $value) {
348+
$to_insert[$key] = $value;
349+
}
319350

320-
// translations array is ordered by key (easy merge)
351+
if ($fd = fopen($file_path, 'w')) {
321352
ksort($to_insert);
322353
$tab = $translation_informations['var'];
323354
fwrite($fd, "<?php\n\nglobal \$".$tab.";\n\$".$tab." = array();\n");
@@ -929,9 +960,12 @@ protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_n
929960
static $cache_file = array();
930961
static $str_write = '';
931962
static $array_check_duplicate = array();
963+
static $module_existing_translations = array();
932964

933965
// Set file_name in static var, this allow to open and wright the file just one time
934966
if (!isset($cache_file[$theme_name.'-'.$file_name])) {
967+
require $file_name;
968+
$module_existing_translations = $_MODULE;
935969
$str_write = '';
936970
$cache_file[$theme_name.'-'.$file_name] = true;
937971
if (!Tools::file_exists_cache(dirname($file_name))) {
@@ -984,6 +1018,13 @@ protected function findAndWriteTranslationsIntoFile($file_name, $files, $theme_n
9841018
$this->total_expression++;
9851019
}
9861020
}
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+
9871028
}
9881029
}
9891030

0 commit comments

Comments
 (0)