Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // the routes file
  2. GET /i18n controllers.JavaScriptController.i18n()
  3.  
  4. // the controller
  5. public class JavaScriptController extends Controller {
  6.     public static Result i18n(){
  7.         Lang l = request().acceptLanguages().get(0);
  8.         String properties = "";
  9.         // you can also use commons-io
  10.         try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("messages." + l.code())){
  11.             properties = new java.util.Scanner(in).useDelimiter("\\A").next();
  12.         } catch (NoSuchElementException | IOException e) {
  13.             Logger.error("Failed to read messages file");
  14.         }
  15.         return ok(properties).as("text/plain");
  16.     }
  17. }