mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-24 12:54:44 +02:00
Started to make changed fields names in element edited log entry extra data translatable
This commit is contained in:
parent
1faeddccb2
commit
6b06ce9ac3
3 changed files with 478 additions and 51 deletions
|
@ -59,6 +59,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function Symfony\Component\Translation\t;
|
||||
|
||||
class LogDataTable implements DataTableTypeInterface
|
||||
{
|
||||
protected ElementTypeNameGenerator $elementTypeNameGenerator;
|
||||
|
@ -182,17 +184,17 @@ class LogDataTable implements DataTableTypeInterface
|
|||
]);
|
||||
|
||||
$dataTable->add('id', TextColumn::class, [
|
||||
'label' => $this->translator->trans('log.id'),
|
||||
'label' => 'log.id',
|
||||
'visible' => false,
|
||||
]);
|
||||
|
||||
$dataTable->add('timestamp', LocaleDateTimeColumn::class, [
|
||||
'label' => $this->translator->trans('log.timestamp'),
|
||||
'label' => 'log.timestamp',
|
||||
'timeFormat' => 'medium',
|
||||
]);
|
||||
|
||||
$dataTable->add('type', TextColumn::class, [
|
||||
'label' => $this->translator->trans('log.type'),
|
||||
'label' => 'log.type',
|
||||
'propertyPath' => 'type',
|
||||
'render' => function (string $value, AbstractLogEntry $context) {
|
||||
$text = $this->translator->trans('log.type.'.$value);
|
||||
|
@ -209,7 +211,7 @@ class LogDataTable implements DataTableTypeInterface
|
|||
]);
|
||||
|
||||
$dataTable->add('level', TextColumn::class, [
|
||||
'label' => $this->translator->trans('log.level'),
|
||||
'label' => 'log.level',
|
||||
'visible' => 'system_log' === $options['mode'],
|
||||
'propertyPath' => 'levelString',
|
||||
'render' => function (string $value, AbstractLogEntry $context) {
|
||||
|
@ -218,7 +220,7 @@ class LogDataTable implements DataTableTypeInterface
|
|||
]);
|
||||
|
||||
$dataTable->add('user', TextColumn::class, [
|
||||
'label' => $this->translator->trans('log.user'),
|
||||
'label' => 'log.user',
|
||||
'render' => function ($value, AbstractLogEntry $context) {
|
||||
$user = $context->getUser();
|
||||
|
||||
|
@ -244,7 +246,7 @@ class LogDataTable implements DataTableTypeInterface
|
|||
]);
|
||||
|
||||
$dataTable->add('target_type', TextColumn::class, [
|
||||
'label' => $this->translator->trans('log.target_type'),
|
||||
'label' => 'log.target_type',
|
||||
'visible' => false,
|
||||
'render' => function ($value, AbstractLogEntry $context) {
|
||||
$class = $context->getTargetClass();
|
||||
|
@ -257,12 +259,12 @@ class LogDataTable implements DataTableTypeInterface
|
|||
]);
|
||||
|
||||
$dataTable->add('target', LogEntryTargetColumn::class, [
|
||||
'label' => $this->translator->trans('log.target'),
|
||||
'label' => 'log.target',
|
||||
'show_associated' => 'element_history' !== $options['mode'],
|
||||
]);
|
||||
|
||||
$dataTable->add('extra', LogEntryExtraColumn::class, [
|
||||
'label' => $this->translator->trans('log.extra'),
|
||||
'label' => 'log.extra',
|
||||
]);
|
||||
|
||||
$dataTable->add('timeTravel', IconLinkColumn::class, [
|
||||
|
|
|
@ -154,7 +154,7 @@ class LogEntryExtraFormatter
|
|||
}
|
||||
|
||||
if ($context instanceof ElementEditedLogEntry && $context->hasChangedFieldsInfo()) {
|
||||
$array['log.element_edited.changed_fields'] = htmlspecialchars(implode(', ', $context->getChangedFields()));
|
||||
$array['log.element_edited.changed_fields'] = $this->getChangedFieldsTranslated($context);
|
||||
}
|
||||
|
||||
if ($context instanceof LegacyInstockChangedLogEntry) {
|
||||
|
@ -200,4 +200,21 @@ class LogEntryExtraFormatter
|
|||
|
||||
return $array;
|
||||
}
|
||||
|
||||
private function getChangedFieldsTranslated(ElementEditedLogEntry $entry): string
|
||||
{
|
||||
$output = [];
|
||||
|
||||
foreach($entry->getChangedFields() as $field) {
|
||||
$key = 'log.element_edited.changed_fields.'.$field;
|
||||
//If the key is not found, use the field name as a fallback
|
||||
$tmp = $this->translator->trans($key);
|
||||
if ($key === $tmp) {
|
||||
$tmp = $field;
|
||||
}
|
||||
$output[] = htmlspecialchars($tmp);
|
||||
}
|
||||
|
||||
return implode(', ', $output);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue