Is there a way to display data from properties file to HTML with thymeleaf? Say I have global_en.properties:
userId = Username EN
And I have in my HTML something like:
<label> <span th:text="#{userId}"></span> </label>
Here, it displays Username EN properly. However, how would I do it if I have another global_jp.properties with:
userId = Username JP
It has the same key value with global_en.properties. Basically, what I want to do is display Username EN when the user selects English and Username JP when the user selects Japanese as language.
Edit: Ok, so I have this in my servlet.xml: The locale interceptor is declared under mvc:interceptors
<mvc:interceptors>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0" />
<property name="useExpiresHeader" value="false" />
<property name="useCacheControlHeader" value="true" />
<property name="useCacheControlNoStore" value="true" />
</bean>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/css/**" />
<mvc:exclude-mapping path="/img/**" />
<mvc:exclude-mapping path="/js/**" />
<mvc:exclude-mapping path="/lib/**" />
<mvc:exclude-mapping path="/" />
<mvc:exclude-mapping path="/index.do" />
<mvc:exclude-mapping path="/C0001.do" />
<mvc:exclude-mapping path="/pages/C0001.do" />
<mvc:exclude-mapping path="/C0001Login.do" />
<bean class="jp.co.vmt.qt.common.interceptor.LoginIntercept" />
</mvc:interceptor>
The local resolver
<!-- Internationalization -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en_UK" />
</bean>
The location of the properties files
<!-- messages.properties location -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>WEB-INF/conf/messages</value>
<value>WEB-INF/conf/global</value>
</list>
</property>
</bean>
To my understanding, those things are everything I need to get localization working, correct? I added in my URL "../action?lang=jp" but it's still displaying English versions. I'm not sure now where it's going wrong.