# The application languages
# ~~~~~
play.i18n.langs = [ "en", "pl", "fr" ]
import play.api.mvc._
class Application extends Controller {
def index = Action { request =>
val s: String = "Languages: " + request.acceptLanguages.map(_.code).mkString(", ")
val striner: String = play.i18n.Messages.get("title") + ">>>" + s
Ok(views.html.index("[[" + striner + "]]"))
}
}
test = en
title = title en
page.lang = en
test = "pl"
title = title pl
page.lang = pl
@(message: String)
@main("Welcome to Play") {
@play.i18n.Messages.get("test")
<br />
@message
}
@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="@play.i18n.Messages.get("page.lang")">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
If you have aRequestHeaderin the implicit scope, it will use the preferred language extracted from theAccept-Languageheader and matching one of theMessagesApisupported languages. You should add aMessagesimplicit parameter to your template like this:@()(implicit messages: Messages).
class Application @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index = Action { implicit request =>
Ok(views.html.index())
}
}@()(implicit messages: Messages)
@Messages("your.key")package controllers
import com.google.inject.Inject
import play.api.i18n.{MessagesApi, I18nSupport}
import play.api.mvc._
class Application @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index = Action { request =>
val s: String = "Languages: " + request.acceptLanguages.map(_.code).mkString(", ")
val striner: String = messagesApi("title") + ">>>" + s
Ok(views.html.index("[[" + striner + "]]"))
}
}
@(message: String)(implicit messages: Messages)
@main("Welcome to Play") {
@Messages("test")
<br />
@message
}
@(title: String)(content: Html)(implicit messages: Messages)
<!DOCTYPE html>
<html lang="@Messages("page.lang")">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/tjNZehtyofI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/8897b8f5-872a-41fe-b3c8-b11421b24fb3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/7c385140-9e2d-442e-8d03-dd04a50c5184%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/75c80ce6-e7e0-4f94-a8dd-3add972be0ee%40googlegroups.com.
class Application @Inject() (val messagesApi: MessagesApi) extends Controller with I18nSupport {
def index = Action { implicit request =>
println(request2Messages.lang)
Ok
}
}
Lang(en,)
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/8bb011c5-53fc-4b24-a98d-5a7b2fd7485f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/cccd8673-4989-4f38-8415-da634f5497f9%40googlegroups.com.