Grails i18n UrlMappings [英] Grails i18n UrlMappings

查看:98
本文介绍了Grails i18n UrlMappings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理以下问题。在我们的项目中,我们为同一个网站推出了不同的国际化域名。
UrlMappings适用于不同语言的问题。例如:



  • 英文:name contact:/ contact(controller:'static',action:'index' ){id ='/ contact'}

  • 德语:name deContact:/ kontakt(controller:'static',action:'index'){id ='/ contact'}



重复所有的代码。有没有一种解决方案将两个url映射分组以使用相同的控制器,动作和逻辑?例如,如果有类似的东西会很好:
姓名联系人:[/contact|/kontakt/etc..]\"(controller:'static',action:'index'){id ='/ contact'}
给可调用相同代码的网址。



预先感谢

解决方案

URLMapping块是一个dsl ,但您可以在其中使用Groovy。



您可以执行以下操作:

  ['contact','kontact']。each {
/ $ {it}(view:/ blah)
}

它会创建您要求的路线。这个例子非常简单,但是你可能会像i18n消息包那样钩入类似的东西来做类似于

  getKeysFor('contact ').each {
...您在这里的映射
}

它感觉这是你的控制器应该处理的东西,因为国际化的支持可能比在url映射层面更好。



我很确定这会打破了你使用命名的URL映射的能力。


I am dealing with the following problem. In our project we have launched different internationalized domains for the same website. The problem comes with the UrlMappings for the different languages. for example:

  • English: name contact: "/contact"(controller: 'static', action: 'index') { id = '/contact' }
  • German: name deContact: "/kontakt"(controller: 'static', action: 'index') { id = '/contact' }

repeating all the code again and again. Is there a solution to group both url mappings to use the same controller, action and logic ?

for example it would be nice to have something similar like this: name contact: "[/contact|/kontakt/etc..]"(controller: 'static', action: 'index') { id = '/contact' } Giving optional urls that calls the same code.

Thanks in advance

解决方案

The URLMapping block is a dsl, but you can use Groovy inside of it.

You could do something like:

['contact', 'kontact'].each{
    "/${it}"( view: "/blah")
}

which does create the routings you are asking for. This example is pretty simplistic, but you could potentially hook into things like the i18n message bundles to do something like

getKeysFor( 'contact' ).each{
    ... your mapping here
}

it feels like this is something that your controller should be handling, since the i18n support is likely to be better there than at the url mapping level.

I am pretty sure this would break your ability to use named url mappings though.

这篇关于Grails i18n UrlMappings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆