SiteMesh is a web page layout and decoration framework, which can be used to select the layout and style of the web application’s user interface when certain criterias are met. I will not go into any details, because Will Iverson has written an article, which gives the reader a good introduction to Sitemesh framework. Even though I have been a happy user of Sitemesh framework in several projects, I have noticed that it does not offer particularly good support for internationalization or localization. It provides two decorator mappers, which can be used in this purpose:
- LanguageDecoratorMapper maps the values of the ACCEPT-LANGUAGE HTTP header to a preferred decorator.
- SessionDecoratorMapper looks at a session attribute to find the name of the used decorator.
However, these implementations are not an elegant solution to the problem. The usage of LanguageDecoratorMapper will not necessarily lead into the wanted result, because the language set by web browser is not always the language preferred by the user. The other option for selecting the used decorator by using the user’s locale information is SessionDecoratorMapper. It is indeed possible to use this decorator mapper and always select the decorator preferred by the user. However, it requires that an extra code is written to set the name of the decorator every time when the locale is changed. My requirements for an elegant solution are following:
- It can obtain the locale information from user’s session.
- The name of the session attribute, which is used to store the locale information, must be configurable.
- The name of the used decorator is combined by using the name of the default decorator and the obtained locale information.
Because Sitemesh did not offer a decorator mapper, which would fulfill these requirements, I decided to write my own implementation. Also, because I have always been a big fan of open source, I decided to release it under Apache 2.0 License. If you are interested, you should check out the sitemesh-sessionlocale-decoratormapper project from Google Code. Any feedback is greatly appreciated.