diff --git a/public/main/inc/ajax/model.ajax.php b/public/main/inc/ajax/model.ajax.php index 065a3872c4..635433478a 100644 --- a/public/main/inc/ajax/model.ajax.php +++ b/public/main/inc/ajax/model.ajax.php @@ -2413,7 +2413,7 @@ switch ($action) { get_lang('No') ); foreach ($result as $item) { - $item['display_text'] = $item['displayText']; + $item['display_text'] = ExtraField::translateDisplayName($item['variable'], $item['displayText']); $item['value_type'] = $obj->get_field_type_by_id($item['valueType']); $item['changeable'] = $item['changeable'] ? $checkIcon : $timesIcon; $item['visible_to_self'] = $item['visibleToSelf'] ? $checkIcon : $timesIcon; diff --git a/public/main/inc/lib/extra_field.lib.php b/public/main/inc/lib/extra_field.lib.php index 98a012cd23..3f8ee1e30f 100644 --- a/public/main/inc/lib/extra_field.lib.php +++ b/public/main/inc/lib/extra_field.lib.php @@ -639,7 +639,7 @@ class ExtraField extends Model $extraFieldId = $row['id']; /** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */ $extraField = $extraFieldRepo->find($extraFieldId); - $row['display_text'] = $extraField->getDisplayText(); + $row['display_text'] = ExtraField::translateDisplayName($row['variable'],$row['display_text']); // All the tags of the field $sql = "SELECT * FROM $this->table_field_tag @@ -794,6 +794,30 @@ class ExtraField extends Model return $extra; } + + /** + * Translate the display text for a extra field. + * + * @param string $variable + * @param string $defaultDisplayText + * + * @return string + */ + public static function translateDisplayName($variable, $defaultDisplayText): string + { + // 1st priority variable. + $translatedVariable = get_lang(api_underscore_to_camel_case($variable)); + if (api_underscore_to_camel_case($variable) !== $translatedVariable) { + return $translatedVariable; + } + + // 2nd priority display text. + $translatedDisplayText = get_lang($defaultDisplayText); + if ($defaultDisplayText !== $translatedDisplayText) { + return $translatedDisplayText; + } + return $defaultDisplayText; + } /** * Return an array of all the extra fields available for this item. @@ -924,7 +948,7 @@ class ExtraField extends Model $extraFieldId = $extraField['id']; /** @var \Chamilo\CoreBundle\Entity\ExtraField $field */ $field = $extraFieldRepo->find($extraFieldId); - $extraField['display_text'] = $field->getDisplayText(); + $extraField['display_text'] = self::translateDisplayName($extraField['variable'], $extraField['display_text']); $extraField['options'] = $option->get_field_options_by_field( $extraField['id'], false, @@ -1114,7 +1138,7 @@ class ExtraField extends Model //$translatedDisplayText = $field_details['display_text']; /** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */ $extraField = $extraFieldRepo->find($field_details['id']); - $translatedDisplayText = get_lang($extraField->getDisplayText()); + $translatedDisplayText = ExtraField::translateDisplayName($field_details['variable'],$field_details['display_text']); $translatedDisplayHelpText = ''; if ($help) { @@ -2066,7 +2090,7 @@ class ExtraField extends Model $extraFieldId = $row['id']; /** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */ $field = $extraFieldRepo->find($extraFieldId); - $row['display_text'] = $field->getDisplayText(); + $row['display_text'] = $this->translateDisplayName($row['variable'], $row['display_text']); // All the options of the field $sql = "SELECT * FROM $this->table_field_options @@ -2495,7 +2519,7 @@ class ExtraField extends Model $extraFieldRepo = Container::getExtraFieldRepository(); /** @var \Chamilo\CoreBundle\Entity\ExtraField $extraField */ $field = $extraFieldRepo->find($id); - $info['display_text'] = $field->getDisplayText(); + $info['display_text'] = ExtraField::translateDisplayName($info['variable'],$info['display_text']); } return $info; diff --git a/public/main/inc/lib/extra_field_option.lib.php b/public/main/inc/lib/extra_field_option.lib.php index 29cd9e8bf2..83b33dfc43 100644 --- a/public/main/inc/lib/extra_field_option.lib.php +++ b/public/main/inc/lib/extra_field_option.lib.php @@ -549,7 +549,7 @@ class ExtraFieldOption extends Model 'id' => $row->getId(), 'field_id' => $row->getField()->getId(), 'option_value' => $row->getValue(), - 'display_text' => $row->getDisplayText(), + 'display_text' => \ExtraField::translateDisplayName($row->getValue(), $row->getDisplayText()), 'priority' => $row->getPriority(), 'priority_message' => $row->getPriorityMessage(), 'option_order' => $row->getOptionOrder(), @@ -591,7 +591,7 @@ class ExtraFieldOption extends Model 'id' => $subOption->getId(), 'field_id' => $subOption->getField()->getId(), 'option_value' => $subOption->getValue(), - 'display_text' => $subOption->getDisplayText(), + 'display_text' => \ExtraField::translateDisplayName($subOption->getValue(), $subOption->getDisplayText()), 'priority' => $subOption->getPriority(), 'priority_message' => $subOption->getPriorityMessage(), 'option_order' => $subOption->getOptionOrder(), @@ -862,7 +862,7 @@ class ExtraFieldOption extends Model if ($info && $translateDisplayText) { $extraFieldOptionsRepo = Container::getExtraFieldOptionsRepository(); $option = $extraFieldOptionsRepo->find($id); - $info['display_text'] = $option->getDisplayText(); + $info['display_text'] = \ExtraField::translateDisplayName($option->getValue(), $option->getDisplayText()); } return $info; @@ -875,7 +875,7 @@ class ExtraFieldOption extends Model foreach ($result as &$row) { $extraFieldOptionsRepo = Container::getExtraFieldOptionsRepository(); $option = $extraFieldOptionsRepo->find($row['id']); - $row['display_text'] = $option->getDisplayText(); + $row['display_text'] = \ExtraField::translateDisplayName($option->getValue(), $option->getDisplayText()); } return $result;