Announcement Announcement Module
Collapse
No announcement yet.
Is it possible to set Locale based on URL pattern? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to set Locale based on URL pattern?

    Hi all,

    I'm somewhat new to this stuff so be kind

    I would like to know if it is possible to have more than one URL map to a servlet/jsp and have the URL be used to set the Locale.

    For example

    www.foobar.com/foo-bar/MyFunkyServlet

    www.foobar.com/bar-foo/MyFunkyServlet

    So, the path /foo-bar/ should make the Locale be set to en_CA for example, while /bar-foo/ means the Locale is set to fr_CA. Ultimately the same Servlet/JSP is used for both, only a different resource bundle is loaded.

    Could someone let me know if this is possible, and possibly supply a short example (even if only in snippets) of how I might go about doing this?

    Thanks in advance for any replies!

    Cheers,
    Keith.

  • #2
    Well, using URL will be really hard, 'cos your controller maps requests using URL mappings and if you change them you might get into trouble.

    But, if you want to try something different, the first place to look is the LocaleResolver interface, it's the interface you will have to implement to change the way that a Locale is choosen: http://static.springframework.org/sp...eResolver.html

    Take a look at the avaliable implementations, don't try to write a new one if one of the avaliable classes suit your needs (one of them will probably do, but none use URL to resolve it).

    Comment

    Working...
    X