I'm looking for a solution to automatically translate the entities of my Symfony application. I'm stuck with a legacy database where translations are stored in the same table as extra fields:
id | name | name_de | name_fr
1 | cat | Katze | chat
2 | dog | Hund | chien
My entity is mapped accordinggly:
class Animal
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*
* @var integer
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=64, nullable=false)
*
* @var string
*/
private $name;
/**
* @ORM\Column(name="name_de", type="string", length=64, nullable=false)
*
* @var string
*/
private $nameDe;
/**
* @ORM\Column(name="name_fr", type="string", length=64, nullable=false)
*
* @var string
*/
private $nameFr;
/* Followed by getters and setters */
}
I've already looking into the Translatable extension, but that cannot match my database schema. I also started with a custom annotation hooking into the postLoad
event, but then I was stopped by the simple issue that postLoad
may be triggered in the proxy state of an entity.
Next I'd look into a custom query walker (basically a modified approach of the Translatable extension), but I'd hope there's a less complex solution out there.
Cheers Matthias