5

如何在同一页面中将 Messages("home.title") 与 IT 和 EN 一起使用?在依赖注入之前我做了:

Messages("home.title")(Lang("IT")) 
Messages("home.title")(Lang("EN"))

但现在它不起作用。

4

1 回答 1

0

如果您的控制器看起来像这样

class MyController extends Controller { def doSomething = Action {...} }

而不是这样

class MyController (val messagesApi: MessagesApi) extends Controller with I18nSupport { def doSomething = Action {...} }

那么您可以在模板中使用以下方法:

@import play.i18n._
<html>
    ...
    <h1>@Messages.get(Lang.forCode("IT"), "home.title")</h1>
    ...
    <h1>@Messages.get(Lang.forCode("EN"), "home.title")</h1>
    ...
</html>
于 2015-06-18T17:24:13.853 回答