how to set the routing translation based on annotation?

送分小仙女□ 提交于 2019-12-07 11:50:32

问题


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:

  1. 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)

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!