// the routes file
GET /i18n controllers.JavaScriptController.i18n()
// the controller
public class JavaScriptController extends Controller {
public static Result i18n(){
Lang l = request().acceptLanguages().get(0);
String properties = "";
// you can also use commons-io
try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("messages." + l.code())){
properties = new java.util.Scanner(in).useDelimiter("\\A").next();
} catch (NoSuchElementException | IOException e) {
Logger.error("Failed to read messages file");
}
return ok(properties).as("text/plain");
}
}