Play Framework 2.4.0 with I18n: two languages ​​on one page

How can I use messages ("home.title") with IT and EN on the same page? Before dependency injection, I did:

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

but now it will not work.

+5
source share
1 answer

If your controller looks like this

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

and don't like

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

you can use the following approach inside your template:

 @import play.i18n._ <html> ... <h1>@Messages.get(Lang.forCode("IT"), "home.title")</h1> ... <h1>@Messages.get(Lang.forCode("EN"), "home.title")</h1> ... </html> 
0
source

All Articles