Announcement Announcement Module
Collapse
No announcement yet.
#springMessage in velocity Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #springMessage in velocity

    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.Resourc eBundleMessageSource">
    <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

  • #2
    I have the same problem

    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:

    Code:
     <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <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.VelocityViewResolver">
      		<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.VelocityConfigurer">
    
    		<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.ResourceBundleViewResolver">
    		<property name="basename"><value>/WEB-INF/viewResolver</value></property>
    	</bean>
    
    	<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
    
    	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
    and the viewResolver.properties file:
    Code:
    modelView.class=org.springframework.web.servlet.view.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.

    Comment


    • #3
      Solved: the messages files should be called:
      messages_en_US.properties
      and messages_iw_IL.properties for the Israeli locale

      the

      Code:
      <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
      		<property name="basename"><value>/WEB-INF/viewResolver</value></property>
      	</bean>
      and the viewResolver.properties files are not needed at least at this stage.

      Comment

      Working...
      X