如何设置基于注解的路由翻译? [英] how to set the routing translation based on annotation?

查看:25
本文介绍了如何设置基于注解的路由翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我网站的所有路由都是基于注解实现的.现在,我想翻译我的路由.为了意识到这一点,我尝试使用包 JMSI18nRoutingBundle.

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();
}

谢谢,

/**
 * @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. 选择的路线总是最后一个,也就是/willkommen(如果你改变路线的顺序,选择的路线仍然是最后一个)

  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)

_locale 是根据上面的注释'de'的最后一条路由的locale.

the _locale is set the the locale of the last route which 'de' according to the annotation above.

那么,有什么建议吗?谢谢...

So, any proposal? Thanks...

推荐答案

我找到了解决方案.你只需要设置运行以下命令

I found the solution. You just have to set run the following command

php app/console 翻译:extract fr --bundle=MinnTestBundle--enable-extractor=jms_i18n_routing --output-format=yml

php app/console translation:extract fr --bundle=MinnTestBundle --enable-extractor=jms_i18n_routing --output-format=yml

然后会生成minn/TestBundle/Ressources/translations/routes.fr.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...

这篇关于如何设置基于注解的路由翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆