Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Framework only reads from English (en) locale file
    primarykey
    data
    text
    <p>So I've been following a mix of the following tutorials ....</p> <p><a href="http://viralpatel.net/blogs/spring-3-mvc-internationalization-i18n-localization-tutorial-example/" rel="nofollow">http://viralpatel.net/blogs/spring-3-mvc-internationalization-i18n-localization-tutorial-example/</a></p> <p><a href="http://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/" rel="nofollow">http://www.mkyong.com/spring-mvc/spring-mvc-internationalization-example/</a></p> <p><strong>THE IDEA!</strong></p> <p>Make it so our webpage can display multiple languages by clicking on a specific language and having the webpage update accordingly</p> <p><strong>THE PLAN!</strong></p> <p>Using spring's LocaleChangeInterceptor, LocaleResolver, HandlerMapping, and MessageSource, and some messages_xx.properties files, we are dynamically calling messages from different languages depending on the specified "lang" parameter. We call the messages using For example, if "lang"=en, we will go to the messages_en.properties file and get the message for label.message. </p> <p><strong>THE SETUP TO PROBLEM!</strong></p> <p>We have set up all of the spring "stuff" (note I am an amateur at this stuff) in the applicationContext.xml file and web.xml file. We have also added the in one of our .jsp files. </p> <p><strong>THE PROBLEM!</strong></p> <p>When we run the application (using a TomCat server) it successfully displays the message in the messages_en.properties file (In this case "hello"), but, when we attempt to change the language, the same message appears.</p> <p><strong>REFERENCE CODE</strong></p> <p><strong><em>applicationContext.xml</em></strong></p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ctx="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "&gt; &lt;bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"&gt; &lt;property name="paramName" value="lang" /&gt; &lt;/bean&gt; &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt; &lt;property name="defaultLocale" value="en"/&gt; &lt;/bean&gt; &lt;bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"&gt; &lt;property name="interceptors"&gt; &lt;ref bean="localeChangeInterceptor" /&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt; &lt;property name="basename" value="classpath:messages" /&gt; &lt;property name="defaultEncoding" value="UTF-8"/&gt; &lt;/bean&gt; </code></pre> <p></p> <p><strong><em>Example: messages_en.properties</em></strong></p> <pre><code> label.message = Hello </code></pre> <p><strong><em>jsp snippets for displaying message / changing language</em></strong></p> <pre><code>&lt;%@ include file="/include.jsp"%&gt; &lt;%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %&gt; .............. &lt;a href="?lang=en"&gt;English&lt;/a&gt;|&lt;a href="?lang=ar"&gt;Arabic&lt;/a&gt; &lt;h3&gt; &lt;spring:message code="label.message" text="default text" /&gt; &lt;/h3&gt; .............. </code></pre> <p><strong>NOTES</strong></p> <ul> <li><p>I threw in a line <code>${pageContext.response.locale}</code> into the code and the output on the webpage was <strong>"en_US"</strong>. Even after changing the parameter (where in the url it would display <code>.....lang=ar</code> for example)</p></li> <li><p>It does find the <em>messages_en.properties</em> file and gets the message from that file and prints it to the webpage, but only accesses that file and only displays the corresponding message. </p></li> <li><p>We are using spring v3.0.3 (edit: based off of the library files but it says 2.5 in the xml files so I dont know), should we use a different version or library?</p></li> </ul> <p><strong>WHAT DO I THINK IT IS?</strong></p> <ul> <li>I have very very little experience but I have a <em>feeling</em> that the locale variable is not actually being changed, so how would I effectively change that?</li> </ul> <p>Thank you everyone! I really appreciate any and all help!</p> <p><strong>EDIT</strong></p> <ul> <li><p>I have since surrounded the "localeChangeInterceptor" with <code>&lt;mvc:interceptors&gt;</code>, no luck </p></li> <li><p>If you need any more files or code, please ask!</p></li> </ul>
    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. 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