我有一个国际化的 Scala Play 2.7.x WebApp 并且有通常的路线,例如
GET / controllers.ApplicationController.index
GET /page/somePage/ controllers.SomeController.somePage
GET /contact controllers.ContactController.view
现在我想添加一条新路由,它基本上将更改语言重定向到任何目标路由。我通过在上面添加一个额外的路由来实现这个用例routes
:
GET /$lang<(en|es)> controllers.ApplicationController.langRedirect(lang: String, target: String = "")
这个想法是,每次你做例如
http://localhost:9000/en => will go to home page in english
http://localhost:9000/en/contact => will go to contact page in english
http://localhost:9000/es => will go to home page in spanish
http://localhost:9000/es/contact => will go to contact page in spanish
等等。不幸的是,它并不总是有效,例如包含在/en/page/somePage/
它之前的那个将无法正确匹配第一条规则:
GET /$lang<(en|es)> controllers.ApplicationController.langRedirect(lang: String, target: String = "")
大概是因为中间/
...我该如何解决?
为了完整起见,这是我的ApplicationController.langRedirect(...)
实现:
def langRedirect(lang: String, target: String = "") = silhouette.UserAwareAction.async { implicit request =>
Future.successful(Redirect("/" + target).withLang(Lang(lang)))
}