我做了ActionRefiner在URL從參數讀取當前請求的語言參數:PlayFramework 2.4斯卡拉ActionRefiner從URL使用
class LangRequest[A](val lang: Lang, request: Request[A]) extends WrappedRequest[A](request)
def LangAction(lang: String) = new ActionRefiner[Request, LangRequest] {
def refine[A](input: Request[A]) = Future.successful {
val availLangs: List[String] = Play.current.configuration.getStringList("play.i18n.langs").get.toList
if (!availLangs.contains(lang))
Left {
input.acceptLanguages.head match {
case Lang(value, _) if availLangs.contains(value) => Redirect(controllers.routes.Application.index(value))
case _ => Redirect(controllers.routes.Application.index(availLangs.head))
}
}
else Right {
new LangRequest(Lang(lang), input)
}
}
}
,並嘗試使用它在行動這樣的:
def login(lng: String) = LangAction(lng) { implicit request: Request[AnyContent] =>
Ok("Ok")
}
而且我有
「play.api.mvc.ActionRefiner [play.api.mvc.Request,controllers.actionbuilders.LangRequest] 不參數「
編譯時出錯。我怎樣才能使用這個ActionRefiner?在PlayFramework文檔https://www.playframework.com/documentation/2.4.x/ScalaActionsComposition他們表現出ActionRefiner用法與過濾器,變壓器這樣的:
(UserAction andThen ItemAction(itemId) andThen PermissionCheckAction)
,這確實工作。但如何使用一個ActionRefiner?