Zend_Controller_Router:从翻译段获取语言
我想在我的网站上使用 URL 重写:
/:@controller/:@action/
所以我想在路线上使用翻译的片段,并且我想从这些翻译的片段中检测请求的语言。例如,如果用户请求这样的网址:
/user/profile/
那么我可以理解请求的语言是英语。如果用户请求这样的网址:
/kullanici/profil/
那么我可以理解请求的语言是土耳其语。我怎样才能用 Zend_Controller_Router 做到这一点?
I want to use a URL rewrite on my site:
/:@controller/:@action/
So I want to use translated segments on route and I want to detect requested language from these translated segments. For example, if user request a url like this:
/user/profile/
then I could understand that requested language is English. And if user request a url like this:
/kullanici/profil/
then I coult understand that requested language is Turkish. How can I do this with Zend_Controller_Router?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是不是一个好主意。因为为了做到这一点,您首先必须确定至少一个路线段的语言。为了做到这一点,您要么必须预先知道映射(即,这与配置文件路线匹配,所以它是英语还是土耳其语?),或者您需要根据土耳其语/英语路线段字典扫描路线段。前者将要求您为每条路线创建 2 条路线 - 一条是土耳其语,一条是英语,而后者将要求您在实际匹配实际所需的时间之外,在请求处理时间上支付惩罚。路线。 IMO 最好坚持使用典型的
:lang/:controller/:action
类型的路由构造。也就是说,如果您打算这样做,我会创建一个新的路由类型来处理 URI 与语言的匹配。然后,这将为您设置一个 i18n 语言参数,但它还应该将 URI 重置为特定的 basline 语言,您将实际将其与标准路由匹配。然后,我将使用 Zend_Controller_Router_Route_Chain 将两者链接在一起。
I dunno if thats such a good idea. Because in order to do that you first have to determine the language of at least one of the route segments. In order to do that you either have to know the mapping up front (ie. this matches the profile route so is it in english or tukish?) or you would need to scan the route segments against a dictionary of turkish/english route segments. The former is going to require you to make 2 routes for every route - one in turkish and one in english, while the latter is going to require you pay a penalty in request processing time on top of the time it already takes to actually match the route. IMO it would better to stick with the typical
:lang/:controller/:action
type of route construct.That said if youre going to do it i would Make a new route type to handle matching the URI to a language. This would then set a language paramter for you i18n, but it should also reset the URI to a specific basline language which you will actually match to the standard route. I would then use
Zend_Controller_Router_Route_Chain
to chain the two together.我们通过扩展 Zend_Controller_Router_Route 创建一个新的路由器来解决我们的问题。我们重写了类的“match”方法,并在原始匹配代码中添加了一些代码行。
We solved our problem by creating a new router with extending Zend_Controller_Router_Route. We overrode "match" method of class and added some lines of code to original match code.