StofDoctrineExtensionsBundle icon indicating copy to clipboard operation
StofDoctrineExtensionsBundle copied to clipboard

Translatable doesn't work

Open yannissgarra opened this issue 9 years ago • 2 comments

Hi ! I try to use Doctrine Extension Translatable, but it doesn't work.

So, this is my configuration :

In my composer

"stof/doctrine-extensions-bundle": "^1.2"

In my config.yml

doctrine:
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            gedmo_translatable:
                type: annotation
                prefix: Gedmo\Translatable\Entity
                dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
                alias: GedmoTranslatable
                is_bundle: false

stof_doctrine_extensions:
    default_locale: en
    translation_fallback: true
    orm:
        default:
            translatable: true

My Shop Class

<?php

namespace ShopBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;

/**
 * Shop implements Translatable
 *
 * @ORM\Table(name="shop")
 * @ORM\Entity(repositoryClass="ShopBundle\Repository\ShopRepository")
 */
class Shop
{
    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="description", type="string", length=255)
     */
    private $description;

    /**
     * @var string
     * 
     * @Gedmo\Locale
     */
    private $local;

    /**
     * Set description
     *
     * @param string $description
     * @return Shop
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set translatable local
     *
     * @param string $locale
     * @return Shop
     */
    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;

        return $this;
    }
}

My Fixtures

<?php

namespace GeographyBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use ShopBundle\Entity\Shop;

/**
 * Load Shop Data
 */
class LoadShopData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * Load
     *
     * @param \Doctrine\Common\Persistence\ObjectManager $manager
     */
    public function load(ObjectManager $manager)
    {
        $shop = new Shop();
        $shop->setDescription('This is shop 1 !');
        $manager->persist($shop);
        $manager->flush();

        $shop->setTranslatableLocale('fr');
        $shop->setDescription("Ceci est le shop 1 !");
        $manager->flush();
    }
}

Table ext_translation was created on php app/console doctrine:schema:create, but no data was insert on php app/console doctrine:fixtures:load and description field was juste updated on shop table.

What's wrong with my code ?

Thanks for any help.

yannissgarra avatar May 04 '16 07:05 yannissgarra

Same here! :(

The Solution on Stackoverflow doesn't work, too.

Is there anybody who is maintaining this bundle, @stof ?

FireLizard avatar Jan 26 '17 10:01 FireLizard