Announcement Announcement Module
Collapse
No announcement yet.
Getting Locale to work. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Re: Getting Locale to work.

    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?

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment

            Working...
            X