I followed this link https://github.com/julienrf/play-jsmessages/commit/3f67083e296edc039af6ed7fc0fe698a282d01b5 to implement i18N in javascript.
Application.java
===================
package controllers;
import java.util.HashMap;
import java.util.Map;
import play.i18n.Messages;
import play.i18n.Lang;
import play.*;
import play.mvc.*;
import jsmessages.JsMessages;
import views.html.*;
import models.Session;
public class Application extends Controller {
private static Session session;
final static JsMessages messages = new JsMessages(play.Play.application());
/**
* Loads the application
* @return
*/
public static Result index() {
return load();
}
public static Result jsMessages() {
System.out.println("in jsMessages");
return ok(messages.generate("window.Messages")).as("application/javascript");
}
/**
* Initial load function, clears all stored session data
* @return Redirect to homepage.html
*/
public static Result load() {
System.out.println("in load1");
session = new Session();
changeLang("fr");
jsMessages();
return ok(mainpage.render(messages));
}
public static Result reset() {
session = new Session();
return ok();
}
public static Session getSession() {
if(session == null) {
session = new Session();
}
return session;
}
}
HTML which is rendered properly if i don't include i18n code for javascripts
mainpage.scala.html
==========================
@(messages: jsmessages.JsMessages)
<html>
<head>
@messages.html("window.Messages")
</head>
//some code goes here
</html>
javascript loaded on rendering homepage.scala.html
Main.js
======
// some code goes here
alert(Messages('first'));
//some code goes here
If I am not including i18n code in Application.java , mainpage.scala.html and main.js , my application is working fine but after including i18n code , page is not getting loaded.
As per my understanding , problem is with rendering ,as two results are being returned from load() and jsMessages().Kindly suggest me how to render both javascript and html or any other way so that this issue can be resolved.