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

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

问题描述

我的网站的所有路由是基于注释实现。现在,我想翻译我的路由。为了实现这一点,我试图用捆绑 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,文档不给任何例如如何指定每个区域的路由。

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 设置在其中德根据上述注解的最后一条路由的语言环境。

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应用程序/台译:提取FR --bundle = MinnTestBundle
  --enable-提取= jms_i18n_routing --output格式=阳明

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

然后,将生成明尼苏达州/ TestBundle / Ressources /译/ 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天全站免登陆