Skip to content

Commit

Permalink
feat: use translated categories labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolocarpignoli committed May 8, 2024
1 parent 32e80fd commit fe9c229
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Model/ObjectsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,15 @@ protected function dangerouslyTranslateFields(ObjectEntity $object, string|null
return $object;
}

if (!empty($object->get('categories'))) {
foreach ($object->categories as &$category) {
if (array_key_exists($lang, $category->labels)) {
$category->label = $category->labels[$lang];
}
}
unset($category);
}

/** @var \BEdita\Core\Model\Entity\Translation|null $requestedTranslation */
$requestedTranslation = collection($object->translations ?? [])
->filter(fn (Translation $tr): bool => $tr->lang === $lang)
Expand All @@ -450,6 +459,7 @@ protected function dangerouslyTranslateFields(ObjectEntity $object, string|null
$originalFields = [
'lang' => $object->lang,
];

$object->lang = $requestedTranslation->lang;
$object->setDirty('lang', false);

Expand Down

0 comments on commit fe9c229

Please sign in to comment.