From b93187f2081473b8807da7bbd734c67c21585637 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 25 Nov 2020 15:46:25 +0100 Subject: [PATCH] LSformElement::labeledValue: add translate_labels parameter and fix translating it --- .../LSattr_html/LSattr_html_labeledValue.docbook | 8 ++++++++ .../class/class.LSformElement_labeledValue.php | 10 +++++++++- src/includes/class/class.LSlang.php | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook index bcd7ea62..21650ea4 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_labeledValue.docbook @@ -12,6 +12,7 @@ 'label2' => 'Libellé label2', [...] ), + 'translate_labels' => [booléen], ),]]> ... @@ -28,6 +29,13 @@ + + translate_labels + + Booléen permettant d'activer/désactiver la traduction des labels (Par defaut : Vrai). + + + diff --git a/src/includes/class/class.LSformElement_labeledValue.php b/src/includes/class/class.LSformElement_labeledValue.php index 36c6d270..cc03dcc4 100644 --- a/src/includes/class/class.LSformElement_labeledValue.php +++ b/src/includes/class/class.LSformElement_labeledValue.php @@ -50,8 +50,16 @@ class LSformElement_labeledValue extends LSformElement { foreach($this -> values as $val) { $parseValues[]=$this -> parseValue($val); } + + // Translate labels + $labels = $this -> getParam('html_options.labels', array()); + if ($this -> getParam('html_options.translate_labels', true, 'bool')) { + foreach($labels as $value => $label) + $labels[$value] = __($label); + } + $return['html'] = $this -> fetchTemplate(NULL,array( - 'labels' => $this -> getParam('html_options.labels'), + 'labels' => $labels, 'parseValues' => $parseValues, 'unrecognizedValueTxt' => __('(unrecognized value)'), 'unrecognizedLabelTxt' => __('(unrecognized label)'), diff --git a/src/includes/class/class.LSlang.php b/src/includes/class/class.LSlang.php index 8d80ca37..fae7e6d5 100644 --- a/src/includes/class/class.LSlang.php +++ b/src/includes/class/class.LSlang.php @@ -626,7 +626,8 @@ function cli_generate_lang_file($command_args) { } break; case 'labeledValue': - addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.labels.*"); + if (LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.translate_labels", True, "bool")) + addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.labels.*"); break; case 'password': addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.mail.subject");