I have implemented the translatable extension. I use a Category (tree extension ) entity and a CategoryTranslation entity as shown in the documentation.
All my titles in the Category entity are in French.
I would like to translate my website in english so I add translations in locale 'en'
, for example, like this :
$cat = $em->getRepository('MyBundle:Category')->findOneByTitle('Nourriture');
$cat->addTranslation(new CategoryTranslation('en', 'title', 'Food'));
$em->persist($cat);
$em->flush();
But when I check the mywebsite.com/en, I find the Nourriture title and not the translation in english instead, while my default locale in config.yml is 'fr'
.
And when I check mywebsite.com/fr, there was no translation of my title which appears as blank. So I did the same thing that above but with 'fr'
and 'Nourriture' as a translation for the 'fr'
locale.
Then I recheck the mywebsite.com/fr and it works great I have my Nourriture title.
But it still not working for the en locale, I can't get the english translation. All happens as if the titles in my Category entity where in english, so it does not have to look for the 'en'
translations.
if you use stof bundle then the default locale is configured like that:
# app/config/config.yml
stof_doctrine_extensions:
default_locale: en_US
Otherwise you can set it directly in the listener Also you could read documentation carefully