From f3b8e64ec0f3c6aed3e2b80f0c283f77c4f4cc3a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 24 Oct 2025 17:11:35 +0200 Subject: [PATCH] Fix translation of label in export --- .../modules/export/export_tsv.modules.php | 22 ++++++++++++++----- .../core/modules/export/exportcsv.class.php | 7 +++--- htdocs/exports/class/export.class.php | 12 +++++----- htdocs/exports/export.php | 2 ++ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/htdocs/core/modules/export/export_tsv.modules.php b/htdocs/core/modules/export/export_tsv.modules.php index 3a40da916f3..7eb876abda3 100644 --- a/htdocs/core/modules/export/export_tsv.modules.php +++ b/htdocs/core/modules/export/export_tsv.modules.php @@ -77,7 +77,7 @@ class ExportTsv extends ModeleExports */ public function __construct($db) { - global $conf, $langs; + global $langs; $this->db = $db; $this->id = 'tsv'; // Same value then xxx in file name export_xxx.modules.php @@ -218,8 +218,6 @@ class ExportTsv extends ModeleExports public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types) { // phpcs:enable - $outputlangs->charset_output = getDolGlobalString('EXPORT_TSV_FORCE_CHARSET'); - $selectlabel = array(); foreach ($array_selected_sorted as $code => $value) { if (strpos($code, ' as ') == 0) { @@ -232,8 +230,12 @@ class ExportTsv extends ModeleExports continue; } - $newvalue = $outputlangs->transnoentities($array_export_fields_label[$code]); // newvalue is now $outputlangs->charset_output encoded - $newvalue = $this->tsv_clean($newvalue, $outputlangs->charset_output); + $newvalue = $array_export_fields_label[$code]; + if ($newvalue) { + $newvalue = $outputlangs->transnoentitiesnoconv($newvalue); + } + + $newvalue = $this->tsv_clean($newvalue, getDolGlobalString('EXPORT_TSV_FORCE_CHARSET')); fwrite($this->handle, $newvalue.$this->separator); $typefield = isset($array_types[$code]) ? $array_types[$code] : ''; @@ -347,9 +349,17 @@ class ExportTsv extends ModeleExports * @param string $charset Input AND Output character set * @return string Value cleaned */ - public function tsv_clean($newvalue, $charset) + public function tsv_clean($newvalue, $charset = '') { // phpcs:enable + global $langs; + + if (empty($charset)) { + $charset = getDolGlobalString('EXPORT_TSV_FORCE_CHARSET'); + } + + $newvalue = $langs->convToOutputCharset($newvalue, 'UTF-8', $charset); // newvalue is now encoded into $charset + // Rule Dolibarr: No HTML $newvalue = dol_string_nohtmltag($newvalue, 1, $charset); diff --git a/htdocs/core/modules/export/exportcsv.class.php b/htdocs/core/modules/export/exportcsv.class.php index 4b9f8dcd361..db3516c1bd8 100644 --- a/htdocs/core/modules/export/exportcsv.class.php +++ b/htdocs/core/modules/export/exportcsv.class.php @@ -194,8 +194,6 @@ class ExportCsv extends ModeleExports public function write_title($array_export_fields_label, $array_selected_sorted, $outputlangs, $array_types) { // phpcs:enable - $outputlangs->charset_output = getDolGlobalString('EXPORT_CSV_FORCE_CHARSET'); - $selectlabel = array(); foreach ($array_selected_sorted as $code => $value) { if (strpos($code, ' as ') == 0) { @@ -209,10 +207,13 @@ class ExportCsv extends ModeleExports } $newvalue = $array_export_fields_label[$code]; + if ($newvalue) { + $newvalue = $outputlangs->transnoentitiesnoconv($newvalue); + } // Clean data and add encloser if required (depending on value of USE_STRICT_CSV_RULES) include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $newvalue = csvClean($newvalue, $outputlangs->charset_output, $this->separator); + $newvalue = csvClean($newvalue, getDolGlobalString('EXPORT_CSV_FORCE_CHARSET'), $this->separator); fwrite($this->handle, $newvalue.$this->separator); $typefield = isset($array_types[$code]) ? $array_types[$code] : ''; diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index f8da3efa128..06f8093ef82 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -80,7 +80,7 @@ class Export /** * @var string[] */ - public $array_export_label = array(); // Tableau de "libelle de lots" + public $array_export_label = array(); // Array of "Translation key" to use for each export profile /** * @var string[] */ @@ -117,7 +117,7 @@ class Export /** * @var array> */ - public $array_export_special = array(); // array of special operations to do on field + public $array_export_special = array(); // array of special operations to do on fields /** * @var array> */ @@ -269,13 +269,13 @@ class Export $this->array_export_perms[$i] = $bool; // Icon $this->array_export_icon[$i] = (isset($module->export_icon[$r]) ? $module->export_icon[$r] : $module->picto); - // Code of the export dataset / Code du dataset export + // Code of the export dataset $this->array_export_code[$i] = $module->export_code[$r]; // Define a key for sort $this->array_export_code_for_sort[$i] = $module->module_position.'_'.$module->export_code[$r]; // Add a key into the module - // Export Dataset Label / Libelle du dataset export + // Export Dataset Label $this->array_export_label[$i] = $module->getExportDatasetLabel($r); - // Table of fields to export / Tableau des champ a exporter (cle=champ, valeur=libelle) + // Table of fields to export $this->array_export_fields[$i] = $module->export_fields_array[$r]; // Table of fields to be filtered (key=field, value1=data type) Verifies that the module has filters $this->array_export_TypeFields[$i] = (isset($module->export_TypeFields_array[$r]) ? $module->export_TypeFields_array[$r] : ''); @@ -283,7 +283,7 @@ class Export $this->array_export_entities[$i] = $module->export_entities_array[$r]; // Table of entities requiring to abandon DISTINCT (key=entity, valeur=field id child records) $this->array_export_dependencies[$i] = (!empty($module->export_dependencies_array[$r]) ? $module->export_dependencies_array[$r] : ''); - // Table of special field operations / Tableau des operations speciales sur champ + // Table of special field operations $this->array_export_special[$i] = (!empty($module->export_special_array[$r]) ? $module->export_special_array[$r] : ''); // Array of examples $this->array_export_examplevalues[$i] = (!empty($module->export_examplevalues_array[$r]) ? $module->export_examplevalues_array[$r] : null); diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index 6aecea6fdc5..d57ef24ec22 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -149,6 +149,7 @@ $entitytolang = array( 'inventory_line' => 'InventoryLine' ); + $array_selected = isset($_SESSION["export_selected_fields"]) ? $_SESSION["export_selected_fields"] : array(); $array_filtervalue = isset($_SESSION["export_filtered_fields"]) ? $_SESSION["export_filtered_fields"] : array(); $datatoexport = GETPOST("datatoexport", "aZ09"); @@ -163,6 +164,7 @@ $field = GETPOST("field", "alpha"); $objexport = new Export($db); $objexport->load_arrays($user, $datatoexport); + $objmodelexport = new ModeleExports($db); $form = new Form($db); $htmlother = new FormOther($db);