本文介绍了symfony2根据域名检测语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要设置一个具有2个语言环境的新网站,并且该语言环境应通过所使用的域名进行检测.知道怎么做吗?
i want to setup a new website with 2 locales and the locale should detected by the domain name that's used. Any idea how to do this?
for example locales: nl and fr
when www.somenldomainname.be is used then the nl locale should be detected
when www.somefrdomainname.be is used then the fr locale should be detected
如果我在nl或fr中生成一个网址,并且选择了正确的域名,那也很棒.
it would also be great if i generate an url in nl or fr the right domain name is selected.
亲切的问候,
大安
推荐答案
为此提供了一个捆绑包: https://github.com/schmittjoh/JMSI18nRoutingBundle .
There is a bundle for that: https://github.com/schmittjoh/JMSI18nRoutingBundle.
这是您在config.yml
中进行设置的方式:
This is how you set it up in config.yml
:
jms_i18n_routing:
default_locale: nl
locales: [nl, fr]
strategy: custom
hosts:
nl: www.somenldomainname.be
fr: www.somefrdomainname.be
redirect_to_host: true
有关更多详细信息,请参见有关使用情况的文档.
See documentation on usage scenarios for more details.
这篇关于symfony2根据域名检测语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!