playframeworkplayframework-2.5

How to use JavaScript variable as a param on @Messages


Is it possible to use a JS variable inside @Messages as a parameter? When I use this, I get the following error:

not found: value name

var name = "some name";
var title = "@Messages("message", name)"

Solution

  • It's not possible, @Messages compiled on the server and javascript on the client. It will compile before javascript even if you will pre-compile it with some server side js engine.

    Here is special module to compute messages on client side, but I am not sure it is still relevant for Play 2.5:

    https://github.com/julienrf/play-jsmessages