Started to make changed fields names in element edited log entry extra data translatable

This commit is contained in:
Jan Böhmer 2023-02-11 23:39:11 +01:00
parent 1faeddccb2
commit 6b06ce9ac3
3 changed files with 478 additions and 51 deletions

View file

@ -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);
}
}