We Recommend

Java How to Program Java How to Program
Takes a new tools-based approach to Web application development that uses Netbeans 5.5 and Java Studio Creator 2 to create and consume Web Services. Features new AJAX-enabled, Web applications built with JavaServer Faces (JSF), Java Studio Creator 2 and the Java Blueprints AJAX Components. Includes new topics throughout, such as JDBC 4, SwingWorker for multithreaded GUIs, GroupLayout, Java Desktop Integration Components (JDIC), and much more.


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.