I have an entity category that has code. This code is internal, and we use it for each language. For example, imagine the following:
Categories: ---- id:1 Code: "Bread" ---- id:2 Code: "Butter"
I have a form with a form field entity. I want to order it using the translated shortcut.
In English, for example, it will display
Bread Butter
But, for example, in French the order is different
Beurre (butter) Pain (bread)
Therefore, I cannot use the orderBy of the entity field.
I have a manual solution, very dirty . I use the select box with label translation
$categories_translated =array(); $categories= $this->em->getRepository('MyRepo')->findAll(); foreach($categories as $category){ $categories_translated[$category->getId()]= $this->translator->trans($category); } asort($categories_translated);
Do you have the right way to do this?
source share