FIX Translation of widget label into combo

This commit is contained in:
Laurent Destailleur 2024-09-19 13:29:07 +02:00
parent 5eff8e366e
commit f00a07e564
4 changed files with 27 additions and 14 deletions

View file

@ -103,32 +103,37 @@ class ModeleBoxes // Can't be abstract as it is instantiated to build "empty" bo
public $box_order;
/**
* @var int User ID
* @var int User ID
*/
public $fk_user;
/**
* @var string Source file
* @var string Source file
*/
public $sourcefile;
/**
* @var string Class name
* @var string Class name
*/
public $class;
/**
* @var string ID
* @var string ID
*/
public $box_id;
/**
* @var string Alphanumeric ID
* @var string Box language file if it needs a specific language file.
*/
public $lang;
/**
* @var string Alphanumeric ID
*/
public $boxcode;
/**
* @var string Note
* @var string Note
*/
public $note;

View file

@ -1211,7 +1211,7 @@ class FormOther
/**
* Get array with HTML tabs with boxes of a particular area including personalized choices of user.
* Get array with HTML tabs with widgets/boxes of a particular area including personalized choices of user.
* Class 'Form' must be known.
*
* @param User $user Object User
@ -1237,8 +1237,14 @@ class FormOther
if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
$boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
}
if (!empty($box->lang)) {
$langs->loadLangs(array($box->lang));
$box->boxlabel = $langs->transnoentitiesnoconv($box->boxlabel);
}
}
// Define selectboxlist
$arrayboxtoactivatelabel = array();
if (!empty($user->conf->$confuserzone)) {
@ -1248,6 +1254,7 @@ class FormOther
if (!empty($boxidactivatedforuser[$box->id])) {
continue; // Already visible for user
}
$label = $langs->transnoentitiesnoconv($box->boxlabel);
//if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {

View file

@ -141,7 +141,7 @@ class InfoBox
// TODO PERF Do not make "dol_include_once" here, nor "new" later. This means, we must store a 'depends' field to store modules list, then
// the "enabled" condition for modules forbidden for external users and the depends condition can be done.
// Goal is to avoid making a "new" done for each boxes returned by select.
// Goal is to avoid to make a "new" done for each boxes returned by select.
dol_include_once($relsourcefile);
if (class_exists($boxname)) {
$box = new $boxname($dbs, $obj->note); // Constructor may set properties like box->enabled. obj->note is note into box def, not user params.

View file

@ -50,7 +50,12 @@ class mymodulewidget1 extends ModeleBoxes
/**
* @var string Box label (in configuration page)
*/
public $boxlabel;
public $boxlabel = 'MyWidget';
/**
* @var string Box language file if it needs a specific language file.
*/
public $lang = 'mymodule@mymodule';
/**
* @var string[] Module dependencies
@ -71,14 +76,10 @@ class mymodulewidget1 extends ModeleBoxes
*/
public function __construct(DoliDB $db, $param = '')
{
global $user, $conf, $langs;
// Translations
$langs->loadLangs(array("boxes", "mymodule@mymodule"));
global $user;
parent::__construct($db, $param);
$this->boxlabel = $langs->transnoentitiesnoconv("MyWidget");
$this->param = $param;
// Condition when module is enabled or not