Java i18n to JavaScript Object action


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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. %>

URL: http://kaedatorum.net/blog

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.