【问题标题】:Translate routes itself in Symfony2在 Symfony2 中翻译路线本身
【发布时间】:2014-05-15 03:32:19
【问题描述】:

我目前在我的 Symfony2 项目中使用 JMSI18nRoutingBundle,到目前为止它运行良好,但我还需要能够翻译路线本身,例如:

英文路线

/en/my-route/whatever/XXX

西班牙语路线

/es/mi-ruta/lo-que-sea/XXX

总结起来,我需要能够在我的控制器中定义以下内容:

/**
 * @Route("route.my_route/route.whatever/XXX")
 */

route.my_route 是来自翻译文件的消息:

messages.en.yml

route:
    my_route: my-route

messages.es.yml

route:
    my_route: mi-ruta

有谁知道这个捆绑包是否可以做到这一点?如果没有,有没有其他方法可以达到预期的效果?

【问题讨论】:

    标签: php symfony routing


    【解决方案1】:

    为了自行回答这个问题,我最终创建了自己的包来处理这种特殊情况。现在我可以使用特殊的[] 表示法翻译路线,如:

    /**
     * @Route("[route.my_route]/[route.whatever]/XXX")
     */
    

    如果您碰巧遇到同样的问题,这里是捆绑包的链接。希望对您有用:

    https://github.com/albertofem/TranslatableRoutePathBundle

    【讨论】:

      猜你喜欢
      • 2012-02-22
      • 1970-01-01
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      相关资源
      最近更新 更多