Ambiguous values in Lang and requestLang

2019-07-18 16:31发布

Using: PlayFramework 2.3 and SecureSocial (compatible version with 2.3)

Im receiving this error in the ViewTemplate:

[error] /Users/einevea/projects/einjar/einevault/econcepts/modules/eusers/app/services.eusers/MyViewTemplates.scala:29: ambiguous implicit values:
[error]  both method request2lang in trait Controller of type (implicit request: play.api.mvc.RequestHeader)play.api.i18n.Lang
[error]  and value lang of type play.api.i18n.Lang
[error]  match expected type play.api.i18n.Lang
[error]   override def getStartSignUpPage(form: Form[String])(implicit request: RequestHeader, lang: Lang): Html = views.html.eusers.custom.startSignUp(WUPage(Messages("securesocial.signup.title")),form)(request, lang, env)

Any help?

1条回答
太酷不给撩
2楼-- · 2019-07-18 17:03

The error message means that you have tried to call getStartSignUpPage and that takes an implicit play.api.i18n.Lang but there are two implicit Lang instances in your scope, so therefore the compiler does not know which one to choose.

The first one is the value lang which you have imported or defined (either as a value in the template or as an implicit parameter in the parameter lists of the template)

The second one is a built in one that comes from play Controller.request2Lang which knows how to extract Lang from the request to select the language that the browser said that it accepts (in the Accept-Language header).

You could work around this in a few ways: avoid having two Lang instances in scope, provide the parameters explicitly where you call getStartSignUpPage or make the implicit parameter list a regular parameter list.

查看更多
登录 后发表回答