Archive for October, 2006

Multi-Language Support with Filters

October 22, 2006

The multi-language support has now been moved from the PANDORA-core to a filter (PolyglotFilter) so it may be used or not, depending of the needs.

The filter works in 2 ways:

On the way in (Request) it finds the desired language from either extracting it from the URL or by matching the accepted Locales (as sent from the browser) and the supported languages (as specified in the filter-entry in web.xml).

The filter adds a ResponseWrapper that extends the functionality of the Response#encodeURL() method. Here we encode the locale to use into the URL, so it will look something like that:

http://host.com/app/controller/action.now;locale=en?some=params

The next time the filter gets the locale from that code in the URL.

This explicit method has 2 advantages over storing the language in a session variable:

  1. Any URL can be bookmarked and keeps the desired language
  2. We have no problems with session timeouts

There is one drawback though — we have to encode all URLs in our application. But there is a nice macro in the pandora_global_library.vm: #href() so encoding is as easy as that:

<a #href(“../controller/action.now”)>

Advertisements