我有一个简单的Play Framework 2.4.6项目,其国际化配置为Play描述文档。 我的文件是这样的: 1)控制器:
package controllers
import play.api._
import play.api.mvc._
import play.api.i18n.{I18nSupport,MessagesApi,Messages,Lang}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import javax.inject.Inject
class Application @Inject()(val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index = Action { implicit request =>
Ok(views.html.index("Your new application is ready."))
}
}
2)消息资源文件:
application.name = Orthoclinic
welcome = Welcome to play!
3)主要模板:
@(title: String)(content: Html)(implicit messages: Messages)
<!DOCTYPE html>
<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("/assets/stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("/assets/images/favicon.png")">
<script src="@routes.Assets.versioned("/assets/javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@Messages("application.name")
@content
</body>
</html>
4)索引模板:
@(message: String)
@main("Welcome to Play") {
@play20.welcome(message)
}
5)路由文件:
# Home page
GET / controllers.Application.index
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
6)应用程序配置文件:
play.crypto.secret = "k1mIneaPlay_pRoJ"
play.i18n.langs = [ "en", "en-us", "pt-br", "es" ]
Calling ./activator reload compile run my result is that:
[error] /home/josenildo/scala-ide/workspace/orthoclinic-app/app/views/main.scala.html:13: could not find implicit value for para
meter messages: play.api.i18n.Messages
[error] @Messages("application.name")
我已按照Play文档here上的i18n最新版本的文档进行操作。 该实施有什么问题?
答案 0 :(得分:0)
您只需要在messages
模板中添加隐式index.scala.html
参数:
@(message: String)(implicit messages: Messages)
@main("Welcome to Play") {
@play20.welcome(message)
}
每当您通过Messages
使用i18n时,隐式@Messages("my.key")
实例都需要在范围内,messages
具有将由编译器提供的相应隐式import play.api.i18n.Messages.Implicits._
参数(请参阅签名) here)。
,您可能希望摆脱I18NSupport
,因为如果您的控制器扩展relist
,则不应该要求它,并且确实可能导致有关模糊的错误隐含的价值观。