简体   繁体   English

使用JMS i18n在Symfony中使用不同的主机和路由

[英]Different host and routes in Symfony witho JMS i18n

I want different host and different routes in my multicountry web with Symfony 3. I used the JMS i18n routing for this. 我想在使用Symfony 3的多国网络中使用不同的主机和不同的路由。为此,我使用了JMS i18n路由。 My config YML file: 我的配置YML文件:

jms_i18n_routing:
    default_locale: es_ES
    locales: [es_ES, fr_FR, en_GB]
    strategy: custom
    hosts:
        es_ES: www.aaa.local
        fr_FR: www.aaa-fr.local
        en_GB: www.aaa-uk.local
    redirect_to_host: true

With this, I can use different host correctly, but I don't know how I can "translate" the routes, f.ex: /contacto /contact and /contact . 这样,我可以正确使用其他主机,但是我不知道如何“翻译”路由,例如: /contacto /contact/contact

I want load differents routing.yml depends on the locale. 我想加载不同的routing.yml取决于语言环境。

When using the JMSI18nRoutingBundle your routes are being Translated automatically based on your route_name using the routes domain (Symfony Translation Component). 使用JMSI18nRoutingBundle时,将使用routes域(Symfony翻译组件)根据您的route_name自动转换您的routes So, assumed your route_name is contact, just create a Translations like this: 因此,假设您的route_name是contact,只需创建如下所示的Translations:

id/source: contact
domain: routes
locale: en
translation/target: /contact

id/source: contact
domain: routes
locale: es
translation/target: /contacto

Now your routes using the Symfony router (which is wrapped by the one from the bundle) will return automatically the translated route from the current locale. 现在,使用Symfony router (由捆绑包中的一个包裹)的路由将自动从当前语言环境返回转换后的路由。 If you want to translate it to a specific locale, just add the route parameter _locale like this: 如果要将其转换为特定的语言环境,只需添加如下路径参数_locale

{{ path("contact", {"_locale": "es"}) }}

or 要么

$this->get('router')->generate('contact', array('_locale' => 'es'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM