views:

826

answers:

2

I'm using freemarker, SiteMesh and Spring framework. For the pages I use ${requestContext.getMessage()} to get the message from message.properties. But for the decorators this doesn't work. How should I do to get the internationalization working for sitemesh?

+2  A: 

You have to use the fmt taglib.

First, add the taglib for sitemesh and fmt on the fisrt line of the decorator.

<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator"%&gt;
<%@ taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page"%&gt;
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%&gt;
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%&gt;
<fmt:setBundle basename="messages" />

In my example, the i18n file is messages.properties. Then you need to use the fmt tag to use the mesages.

<fmt:message key="key_of_message" />
mathd
A: 

If you prefer templates and the freemarker servlet instead you can enter the following in your templates:

<#assign fmt=JspTaglibs["http://java.sun.com/jstl/fmt"]&gt;
<@fmt.message key="webapp.name" />

and in your web.xml:

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>messages</param-value>
</context-param>