Results 1 to 6 of 6

Thread: Getting Locale to work.

  1. #1
    Join Date
    Jun 2005
    Location
    Stirling, Scotland
    Posts
    6

    Default Getting Locale to work.

    Hi,
    I am working through the "Developing a Spring Framework MVC Application...." - 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.

  2. #2

    Default Re: Getting Locale to work.

    Quote Originally Posted by solasta
    Hi,
    ......
    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?

  3. #3

    Default You should have

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

  4. #4
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    667

    Default How did you set it up in your browser?

    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 -> Internet Options -> Languages, or in Firefox, Tools -> Options -> General -> 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 "my-text.properties", and your German-language message file for use in Germany might be called "my-text_de_DE.properties" (from "Spring in Action" p. 84).

    Also you need to wire in a MessageSource, in this case a ResourceBundleMessageSource with a basename of "my-text".

    Hope this helps.

  5. #5
    Join Date
    Jun 2005
    Location
    Stirling, Scotland
    Posts
    6

    Default Re: Getting Locale to work.

    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.

  6. #6
    Join Date
    Jun 2005
    Location
    Stirling, Scotland
    Posts
    6

    Default

    Okay.
    Now have a messages_de.properties and added the following to the springapp-servlet.xml file and it works a treat - magic.

    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.Accept HeaderLocaleResolver"/>

    Thanks for help.

Similar Threads

  1. Sharing locale between JSF and Spring
    By xenrik in forum Web
    Replies: 2
    Last Post: Aug 1st, 2008, 11:04 AM
  2. Replies: 4
    Last Post: May 12th, 2006, 02:50 AM
  3. Replies: 2
    Last Post: Sep 5th, 2005, 10:22 AM
  4. LOCALE de-mystified...
    By chcmtl in forum Web
    Replies: 0
    Last Post: Jun 6th, 2005, 04:16 PM
  5. Replies: 2
    Last Post: Nov 27th, 2004, 06:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •