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

  • Locale and message.properties issue

    I have a simple Spring MVC webapp supporting both norwegian and english users. Thus I have two message files (message_en.properties and message.properties) 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
    http://someserver/list.htm?locale=no

    How can I load the proper message.properties 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?

    Comment


    • #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:
      Code:
      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 application.properties file.

      Comment


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

        Comment


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

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

          Comment

          Working...
          X