LSformElement::labeledValue: add translate_labels parameter and fix translating it

This commit is contained in:
Benjamin Renard 2020-11-25 15:46:25 +01:00
parent b00f59af2e
commit b93187f208
3 changed files with 19 additions and 2 deletions

View file

@ -12,6 +12,7 @@
'label2' => 'Libellé label2', 'label2' => 'Libellé label2',
[...] [...]
), ),
'translate_labels' => [booléen],
),]]> ),]]>
... ...
</programlisting> </programlisting>
@ -28,6 +29,13 @@
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term>translate_labels</term>
<listitem>
<simpara>Booléen permettant d'activer/désactiver la traduction des labels (Par defaut : <literal>Vrai</literal>).</simpara>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</sect4> </sect4>

View file

@ -50,8 +50,16 @@ class LSformElement_labeledValue extends LSformElement {
foreach($this -> values as $val) { foreach($this -> values as $val) {
$parseValues[]=$this -> parseValue($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( $return['html'] = $this -> fetchTemplate(NULL,array(
'labels' => $this -> getParam('html_options.labels'), 'labels' => $labels,
'parseValues' => $parseValues, 'parseValues' => $parseValues,
'unrecognizedValueTxt' => __('(unrecognized value)'), 'unrecognizedValueTxt' => __('(unrecognized value)'),
'unrecognizedLabelTxt' => __('(unrecognized label)'), 'unrecognizedLabelTxt' => __('(unrecognized label)'),

View file

@ -626,6 +626,7 @@ function cli_generate_lang_file($command_args) {
} }
break; break;
case 'labeledValue': case 'labeledValue':
if (LSconfig :: get("LSobjects.$obj.attrs.$attr.html_options.translate_labels", True, "bool"))
addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.labels.*"); addFromLSconfig("LSobjects.$obj.attrs.$attr.html_options.labels.*");
break; break;
case 'password': case 'password':