-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doctrine extensions translatable not working in symfony 6.4 with orm 3.1 #2867
Comments
So had the same problem : I have So this is my original configuration,
I tried different things as it is deprecated to declared events like that but from this doc it should still works. https://symfony.com/doc/7.0/doctrine/events.html So I tried with the new way using AsDoctrineListener, and made a listener like this ;
|
You don't need to subclass the listener, just update your config to match the updated documentation. |
Thanks I was looking for something like that, looked in the wrong place. |
Thank you for your answers. |
In services.yaml I have : parameters: and
In doctrine.yaml, I have : doctrine:orm:mappings: And in translations.yaml, I have : framework: |
What is really strange is that in my entry in ext_translations table I change "fr_FR" to "fr", matching in fact with the $request->getLocale(), twig stills serving the field in english. So it's as if symfony wouldnt translate and ignores ext_translations entries. |
Reading the documentation again, at https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/frameworks/symfony.md#configuring-extensions-via-event-subscribers, I realize I didn't add the event listener. namespace App\EventListener; use Gedmo\Translatable\TranslatableListener; final class GedmoExtensionsEventSubscriber implements EventSubscriberInterface
}` |
In services.yam, I added : It works know ! |
Environment
Symfony 6.4
Doctrine ORM 3.1
Package
"gedmo/doctrine-extensions": "^3.16",
Doctrine packages
"doctrine/annotations": "^2.0",
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.1",
PHP version
Subject
I installed doctrine extensions and doctrine annotations.
in config/doctrine.yaml :
mappings : translatable: type: attribute is_bundle: false prefix: Gedmo\Translatable\Entity dir: '%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity' alias: GedmoTranslatable
I have a country entity :
`
...
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
#[ORM\Entity(repositoryClass: CountryRepository::class)]
class Country implements Translatable
{
...
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
...
`
I have also a fixture
... $repository = $em->getRepository('Gedmo\\Translatable\\Entity\\Translation'); ... $repository->translate($country, 'nom', 'fr', 'Allemagne')
But if I do that, I get error : The translation listener could not be found
Also if I open a form switching locale in french. I write a name of the country in french. I save.
After I switch to english. I write a name of the country in english. I save.
I expect that when something to be written in the table ext_translations, but nothing is written. The attribute #[Gedmo\Translatable] is ignored. My fields with this attribute aren't translatable.
The text was updated successfully, but these errors were encountered: