Back Forum Reply New

Getting Locale to work.

Hi,
I am working through the quot;Developing a Spring Framework MVC Application....quot; - everything looking good.
Decided to try out the Locale stuff and have set up a de_DE locale, my understanding is that this should be picked up automatically by setting my client browser accordingly but this does not seem to work, is there something I have to set in the servlet xml for this to work?
Thanks.


Originally Posted by solastaHi,
......
Decided to try out the Locale stuff and have set up a de_DE locale, my understanding is that this should be picked up automatically by setting my client browser accordingly but this does not seem to work, is there something I have to set in the servlet xml for this to work?
Thanks.

What do you mean setting the de_DE? Do you mean you have created a message properties file with that extension?

For example for the german locale i should think you should have a message properties file name like this messages_de.properties

I had trouble with this at first, until I discovered which client setting to change. On my Windows client, it didn't matter which language or region I configured at the OS level, it only mattered which language I chose in the browser itself, e.g. in IE 6, Tools -gt; Internet Options -gt; Languages, or in Firefox, Tools -gt; Options -gt; General -gt; Languages.

Once I got this straight, everything worked as documented. Just be sure you use request.getLocale() whenever you have to pass Spring the locale, and have the properties file for your language(s) on the classpath. For example, your default messages file might be called quot;my-text.propertiesquot;, and your German-language message file for use in Germany might be called quot;my-text_de_DE.propertiesquot; (from quot;Spring in Actionquot; p. 84).

Also you need to wire in a MessageSource, in this case a ResourceBundleMessageSource with a basename of quot;my-textquot;.

Hope this helps.

What do you mean setting the de_DE? Do you mean you have created a message properties file with that extension?

I have a messages.properties file for the default language and a messages_de_DE.properties for the German language.

Okay.
Now have a messages_de.properties and added the following to the springapp-servlet.xml file and it works a treat - magic.
   lt;bean id=quot;localeResolverquot;        class=quot;org..web.servlet.i18n.Accept  HeaderLocaleResolverquot;/gt;

Thanks for help.
¥
Back Forum Reply New