PDA

View Full Version : #springMessage in velocity


nidhi
Sep 10th, 2007, 02:13 AM
Hi,

I am using #springMessage in velocity template for getting message values from message resource bundle.

in xxx-sevlet.xml i configured like this.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>

and i have messages.propoerties in classpath with 2 other language properties.

default language

title = TITLE
heading=HEADING
greeting=GREETING

norwegina langiuage

title = TITLE_NO
heading=HEADING_NO
greeting=GREETING_NO



bt the problem is its displaying for default language only. If i change the language settings in browser its not affecting the message keys. So i alwys gets message for 3springMessage("title") as TITLE independant of language.

In one thread i found the ben configuration should in be in application ocntext.xml.
i tried that way also.

Please help.


thanks in adavance
Nidhi

yazo
Sep 1st, 2008, 05:27 AM
Hi,
I'm trying to implement internationalization (spring + velocity templates). I've read numerous posts, but haven't found a solution yet.
it seems #springMessage macro uses the default locale.

I have two files for the messages that uses the same keys:
/WEB-INF/messages_en.properties
/WEB-INF/messages_he.properties

Here is my setup:



<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="interceptors">
<list>
<ref local="localeChangeInterceptor"/>
</list>
</property>
<property name="mappings">
<props>
.......
</props>
</property>
</bean>

<bean id="velocityViewResolver" class="org.springframework.web.servlet.view.velocity.Velo cityViewResolver">
<property name="cache" value="true"/>
<property name="prefix" value="/"/>
<property name="suffix" value=".vm"/>
<property name="order"><value>0</value></property>

<!--if you want to use the Spring Velocity macros, set this property to true -->
<property name="exposeSpringMacroHelpers" value="true"/>

<property name="contentType" value="text/html; charset=utf-8"/>
</bean>

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.Velo cityConfigurer">

<property name="resourceLoaderPath" value="/WEB-INF/velocity"/>

<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
<prop key="directive.foreach.counter.name">
loopCounter
</prop>
<prop key="directive.foreach.counter.initial.value">
0
</prop>
</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundl eViewResolver">
<property name="basename"><value>/WEB-INF/viewResolver</value></property>
</bean>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocale Resolver"/>

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeI nterceptor"/>


and the viewResolver.properties file:

modelView.class=org.springframework.web.servlet.vi ew.velocity.VelocityView
modelView.url=/WEB-INF/velocity/editPage.vm


I'm confused with the viewResolver and the velocityViewResolver

Can anyone give a working setup for this ?
Yair.

yazo
Sep 1st, 2008, 07:31 AM
Solved: the messages files should be called:
messages_en_US.properties
and messages_iw_IL.properties for the Israeli locale

the

<bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundl eViewResolver">
<property name="basename"><value>/WEB-INF/viewResolver</value></property>
</bean>

and the viewResolver.properties files are not needed at least at this stage.