• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Internationalization of messages

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am newbie to spring. I want to do Internationalization of messages. currently, all the english messages are hard coded in applicationContext.xml file. Now, I want to add another language to this project. Do I need to create two separate applicationContext.xml file so that when a language indicator is passed from request, the appropriate file gets loaded? or how can I approach this? can someone help me? Thanks..
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone please help me here?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's how you would do it - by using a MessageSource. It also might help to read up on ResourceBundle in the Java API, as MessageSource uses the underlying Java I18N APIs.
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is I just need to change wahtever existing now..cant change entire functionality.Since, messages already hard coded in app context file, is there any way to select this app context based on request? or do I must move all messages to different file which I can select based on request?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Extracting the strings from the existing applicationContext.xml, putting them into a properties file, and loading them through a MessageSource is going to be infinitely easier and quicker than figuring out how to select a different application context based on the language of the request. It's basically "mov(ing) all messages to different file which I can select based on request."
 
namita sasa
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying Nathan. But, I want to know if this is possible or not since thats the only option they want.

I am trying to do something like below:Want to create two hash maps in app context. From these hashmaps, I am planning to retrieve values in my actions.ie. from context, get the hashmaps and then based on request parameter, decide which one to use.
<bean id="exporter" class="org.springframework.web.context.support.Ser vletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="appContenMapEn" value-ref="enMAP" />
<entry key="appContenMapSp" value-ref="spMAP" />
</map></property></bean>

<bean id="enMAP" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="defaultCss" value="/dmm/styles/default.css" />
</map>
</constructor-arg>
</bean>
<bean id="spMAP" class="java.util.HashMap">
<constructor-arg>
<map>
<entry key="defaultCss" value="/dmm/styles/default.css" />
</map>
</constructor-arg>
</bean>

Is it possible to do something like this? Thanks for help,Namita
 
This tiny ad will self destruct in five seconds.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic