Results 1 to 5 of 5

Thread: Locale and message.properties issue

  1. #1
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    14

    Default 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. #2
    Join Date
    May 2005
    Location
    London
    Posts
    9

    Default

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

  3. #3
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    14

    Default

    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.

  4. #4
    Join Date
    May 2005
    Location
    London
    Posts
    9

    Default

    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. #5
    Join Date
    Oct 2005
    Location
    Norway
    Posts
    14

    Default

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

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

Posting Permissions

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