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)"
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:
If you are trying to use server data or variables in your JS code, you could use this approach. In some situations, I need my JS to have a list of server items, so in my whatever.scala.html, I create a script tag and initialize a JS variable from the server like below.
<script type="text/javascript">
// get employee data from our server model - it needs to be converted to JSON for JS
var employeeJsonString = @{Html(new Gson().toJson(model.getEmployeesAsJson()))};
var employees = JSON.parse(exmployeeJsonString);
// then you may use employees in JS code...
</script>
jsMessages is a good solution.
If you want a more generic solution for any kind of code, not just messages, you can try out this: JavascriptRouting
It enables you to pass javascript variables to any call to an endpoint in your application. But true, you would have to set up a Play route for your Messages.