Symfony2 - translatable field - The class 'Gedmo\Translatable\Entity\Translation' was not found in the chain configured namespaces
Asked Answered
S

2

10

I'm trying to translate some fields of my entity and I have the following error when I'm try create an object...

<?php

namespace XXXX\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * Line
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="XXXX\Entity\LineRepository")
 */
class Line implements Translatable
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Line
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

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

    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }
}

And the error:

[Doctrine\Common\Persistence\Mapping\MappingException]
The class 'Gedmo\Translatable\Entity\Translation' was not found in the chain configured namespaces

I'm using Symfony 2.5, but in 2.4 occurs too. Any idea how I can solve this?

Stramonium answered 25/6, 2014 at 9:56 Comment(0)
J
17

You need to configure the translatable Entity to use as well. In config.yml:

orm:
    (....)
    mappings:
        translatable:
            type: annotation
            is_bundle: false
            prefix: Gedmo\Translatable\Entity
            dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
            alias: GedmoTranslatable
Jodee answered 17/7, 2015 at 17:16 Comment(3)
Precision for Symfony 3.4.x & 4.x.x, file to edit : {rootProjectDir}/config/packages/doctrine.yamlSchott
I think your tough is valable only in flex situation. I'm still in 3.4 but standard edition and i don't have this path in my projetcsJodee
Yeah I should have been more specific ! ThanksSchott
M
6

Update for Symfony 5 : Configure the /config/packages/doctrine.yaml file and add the following

orm:
    (....)
    mappings:
        translatable:
            type: annotation
            is_bundle: false
            prefix: Gedmo\Translatable\Entity
            dir: '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity'
            alias: GedmoTranslatable
Marmion answered 23/11, 2020 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.