I have a project with Play Framework 2.3.8 and I'm migrating in Play Framework 2.4 but I have a problem with I18n.
Now I have in a view code like this:
@Messages("components.navbar.text")(locale.MyLang)
where locale is:
object locale {
var MyLang =Lang("it")
def changeLang(newLang:String): Unit ={
MyLang=Lang(newLang)
}
}
I would mantainer this structure without using implicit lang, is possible ?
I have some situation where I use in the same page different language and in this case is difficult and boring with the implicit lang.
If I understand your question correctly, which is that you want to override the user's chosen language for certain blocks of the page, I would do this (for Play 2.4) using an implicit
Messages
object:That is, use
defining
to create a new (implicit) messages for certain nested blocks of HTML.If you really wanted to go to town (and I wouldn't necessarily recommend this) you could add an
italian
method toMessages
via an implicit class:(in
my.package.utils.i18n.MessagesExtensions.scala
):To have that work in a view you need to add the class to your
templateImport
in yourbuild.sbt
:Then in your templates you can just to this:
But that might be overkill, unless it really saves you a lot of boilerplate language switching.