I suggest you to use the KnpDoctrineBehavious Bundle. It makes is very simple to translate any property of your entity:
class BlogPost
{
use ORMBehaviors\Translatable\Translation;
// anything that should not be translated
// follows in this class
}
And add a translation entity:
class BlogPostTranslation
{
/**
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(length=128)
*/
private $slug;
// ...
}
Now you can acces any translation like this:
$blogPost->getSlug(); // default language slug
$blogPost->translate('en')->getSlug(); // English slug
$blogPost->translate('fr')->getSlug(); // French slug
Don't forget to call $entity->mergeNewTranslations();
after $em->persist($entity);
to update the translation table.
Edit:
Note that the DoctrineBehaviours Bundle also supports a way better Sluggable
. Use it like it's shown in their documentation.