2012-02-14 33 views
2

我有一個多語種網站,有兩種語言:en(默認)和de(德語)。Symfony2:在多語言網站使用Doctrine2燈具

我要填補我的類別表默認類別英語,使用Doctrine賽程如下:

$subcategory1 = new Category(); 
    $subcategory1->setTitle('Comedy'); 
    $subcategory1->setParent($category); 
    $subcategory2 = new Category(); 
    $subcategory2->setTitle('Action'); 
    $manager->persist($subcategory1); 
    $manager->persist($subcategory2); 
    $manager->flush(); 

我使用學說擴展translatable有表的內容也在德國。如果我有做手工我在symfony中要做到:

$em = $this->getDoctrine()->getEntityManager(); 
    $category = $em->find('Tracker\MembersBundle\Entity\Category', 51); 
    $category->setTitle('Komödie'); 
    $category->setTranslatableLocale('de'); // change locale 
    $em->persist($category); 
    $em->flush(); 

我的問題是我怎麼能自動完成這一過程,使其工作而載入燈具?我有大約30個類別。

回答

0

試試這個方法:

$subcategory1 = new Category(); 
$subcategory1->setTitle('Comedy'); 
$subcategory1->setParent($category); 
$subcategory2 = new Category(); 
$subcategory2->setTitle('Action'); 

$manager->persist($subcategory1); 
$manager->persist($subcategory2); 
$manager->flush(); 

$subcategory1->setTranslatableLocale('de_DE'); 
$subcategory1->setTitle('ComedyDE'); 
$subcategorys->setTranslatableLocale('de_DE'); 
$subcategory2->setTitle('ActionDE'); 
$manager->flush();