NDSQ
NDSQ

Reputation: 1

Playframework [Scala]: Problems with i18n after migrating from 2.5 to 2.6

I am working on migrating my project from play 2.5 to 2.6. Everything seems ok, however, there is a problem with i18n in within my views, rendered by scala controllers(and there is no such problem with java controllers).

To provide i18n, play.api.i18n.Messages.apply method is used in both cases, but with Scala controller(derived from AbstractController or InjectedController) there are only marks from Messages.lang file, not values.

How can I resolve this?

Upvotes: 0

Views: 60

Answers (1)

o-0
o-0

Reputation: 1799

In your controller class:

  1. Inject controller components and the actor system
  2. Use the implicit value of assets finder.
  3. Extending it with AbstractController and I18nSupport:

    class myController @Inject()
     (controllerComponents: ControllerComponents,actorSystem: ActorSystem)
     (implicit assetsFinder: AssetsFinder) 
     extends AbstractController(cc) with I18nSupport{ 
     ??? //Body of your controller class. 
    } 
    

In your views:

Within your views file use three implicit values of RequestHeader, Messages, and AssetsFinder:

@(whatever: Any)(implicit req: RequestHeader, messages: Messages, assetsFinder: AssetsFinder)

Upvotes: 1

Related Questions