Wednesday, December 22, 2010

MultiLanguage enabled JSPs

Step-1 : Load the jstl and fmt tag libraries in your jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

Step-2 : Check the locale
<c:if test="${param.locale == 'de_DE'}">
   <fmt:setLocale value="de_DE" />
</c:if>

Step-3 : Based on the locale, load appropriate bundle. Here if the locale is de_DE then message_de_DE.properties will be loaded.
<fmt:bundle basename="message">

Step-4 : Externalize(localize) the text in jsp, to the appropriate properties file, below statement will load the text corresponding to "LblHeading" from message_de_DE.properties file.
<fmt:message key="LblHeading"/>