Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for your answer. Here is a more generic solution.</p> <p>The idea is to provide a <strong>dynamic javascript</strong> file named "string.js", containing an associative array of messages registered in the java resource bundle, using current user language.</p> <p>1) Create a method in Spring <strong>Controller</strong> to load all resource keys from resource bundle, and return the view "spring.jsp"</p> <pre><code>@RequestMapping(value="strings.js") public ModelAndView strings(HttpServletRequest request) { // Retrieve the locale of the User Locale locale = RequestContextUtils.getLocale(request); // Use the path to your bundle ResourceBundle bundle = ResourceBundle.getBundle("WEB-INF.i18n.messages", locale); // Call the string.jsp view return new ModelAndView("strings.jsp", "keys", bundle.getKeys()); } </code></pre> <p>2) Implement the <strong>View</strong> "strings.jsp"</p> <pre><code>&lt;%@page contentType="text/javascript" pageEncoding="UTF-8" %&gt;&lt;%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;&lt;%@taglib prefix="spring" uri="http://www.springframework.org/tags" %&gt;var messages = new Array(); &lt;c:forEach var="key" items="${keys}"&gt;messages["&lt;spring:message text='${key}' javaScriptEscape='true'/&gt;"] = "&lt;spring:message code='${key}' javaScriptEscape='true' /&gt;"; &lt;/c:forEach&gt; </code></pre> <p>3) Import "spring.js" in your HTML source code. Messages array is available and loaded with the right language.</p> <p><strong>Possible issue</strong>: If user change his language, "spring.js" must be reloaded by the navigator, but it will be cached. Clearing the cache is needed when user change his language (or other trick to get the file reloaded).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload