问题
All the routing of my website is realized based on the annotations. Now, I want to translate my routing. To realize that, I tried to use the bundle JMSI18nRoutingBundle.
Nevetheless, the documentation does not give any example how to specify the route for each locale.
This is an action with its routing, how to translate it?
/**
* @Route("/welcome", name="welcome")
* @Template()
*/
public function welcomeAction() {
return array();
}
Thanks,
Question after being edited
/**
* @Route("/welcome", name="welcome", defaults={"_locale" = "en"})
* @Route("/bienvenue", name="welcome", defaults={"_locale" = "fr"})
* @Route("/willkommen", name="welcome", defaults={"_locale" = "de"})
* @Template()
*/
public function welcomeAction() {
return array();
}
Now, what is happening with this new annotations:
the selected route is always the last one which is
/willkommen
(if you change the order the routes, the selected route is still the last one)the
_locale
is set the the locale of the last route which 'de' according to the annotation above.
So, any proposal? Thanks...
回答1:
I found the solution. You just have to set run the following command
php app/console translation:extract fr --bundle=MinnTestBundle --enable-extractor=jms_i18n_routing --output-format=yml
Then, minn/TestBundle/Ressources/translations/routes.fr.yml
file will be generated. Customize you route translations & that is it!
Hope it will help others...
回答2:
You can add multiple route annotations.
/**
* @Route("/welcome", name="welcome", defaults={"_locale" = "en"})
* @Route("/bienvenue", name="welcome", defaults={"_locale" = "fr"})
* @Template()
*/
来源:https://stackoverflow.com/questions/29301294/how-to-set-the-routing-translation-based-on-annotation