Posted By

alvaroisorna on 12/05/07


Tagged

javascript String i18n localize


Versions (?)

Java i18n to JavaScript Object action


 / Published in: Java
 

URL: http://kaedatorum.net/blog

  1. <%@ page import="java.util.*, my.utils" %>
  2. <%response.setContentType("text/javascript");%>
  3. if (!window.i18n){window.i18n = {};}
  4. <%
  5. Locale currentLocale = UtilJSP.getCurrentLocale(request);
  6. ResourceBundle labels = ResourceBundle.getBundle(my.utils.getI18nResources(), currentLocale);
  7. Enumeration bundleKeys = labels.getKeys();
  8.  
  9. while (bundleKeys.hasMoreElements()){
  10. String key = (String)bundleKeys.nextElement();
  11. String value = labels.getString(key);
  12.  
  13. if (request.getParameter("filter") != null && key.startsWith(request.getParameter("filter"))){
  14. out.println("window.i18n[\"" + key + "\"] = \"" + value.replaceAll("\"", "\\\\\"").replaceAll("\\n", "\\\\n") + "\";");
  15. }
  16. }
  17. %>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: alvaroisorna on December 5, 2007

This is the code of the JSP.

You need to login to post a comment.