Announcement Announcement Module
No announcement yet.
Locale and issue Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Locale and issue

    I have a simple Spring MVC webapp supporting both norwegian and english users. Thus I have two message files ( and in the WEB-INF/classes directory. The "clients" of my app are including the my app by using iframe tag. The plan is to manage language by passing a request parameter named "locale" like this:

    http://someserver/list.htm?locale=en or

    How can I load the proper file, by testing on the locale request parameter? I have tried to set the locale in my spring controller, but I guess I do something wrong.

    Any thoughts?

  • #2
    Are you using the JSTL format taglib? Doesn't the locale come from the user's browser locale settings?


    • #3
      Yes, I use the JSTL fmt tag.
      <fmt:message key="list.title" />

      I would like to set the locale based on a request parameter (comes from an hardcoded iframe url), and not from the user's browser.

      I did a quick test, and put this code in my controller:
      ReloadableResourceBundleMessageSource msgSrc = 
          new ReloadableResourceBundleMessageSource();
      String s = msgSrc.getMessage("list.title", null, new Locale("en"));
      logger.debug("english: " + s);
      s = msgSrc.getMessage("list.title", null, new Locale("no"));
      logger.debug("norwegian: " + s);
      and this hardcoding approach works.

      My problem is; How do I set locale on a request so the jstl fmt tag display text from the correct file.


      • #4
        Ah - so you want to override the browser settings.

        Well, it's pretty nasty, but IIRC there's a format tag to set the locale explicifly. You could have a bunch of these in a c:choose block...


        • #5
          Hmm, when I read the jstl doc it was pretty obvious...

          <fmt:setLocale value="${param.locale}" scope="request" />
          Thanks Simon!