I am trying to use the Gedmo translatable extension for Doctrine 2 in a Zend Framework 2 application.
I have it setup like this:
'doctrine' => array(
'eventmanager' => array(
'orm_default' => array(
'subscribers' => array(
'Gedmo\Translatable\TranslatableListener'
)
)
),
'driver' => array(
'application_entities' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Application/Entity')
),
'translatable_metadata_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
'vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity',
)
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'application_entities',
'Gedmo\Translatable\Entity' => 'translatable_metadata_driver'
)
)
),
),
Sample Entity:
<?php
namespace Application\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity (repositoryClass="Application\Repository\CategoryRepository")
*/
class Category {
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string")
* @Gedmo\Translatable
*/
private $name;
/**
* @Gedmo\Locale
*/
private $locale;
}
Persisting translations works fine and I can get them using the translatable repository.
I have two problems:
I cannot figure out how to get the translatable listener subscribed to the entitymanager. I would like to get it in the Module class to set the default locale on bootstrap.
When I have an entity object I cannot get the translations of translatable columns, only the standard values. As far as I can figure out, I should get a value translated to the default locale, and should be able to override the default locale by setting a variable in the Entity annotated with Locale, but it does not seem to work.
Any help would be greatly appreciated!
Glad to help you!