• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

how are people Internationalizating thier jsps


I am in the process of allowing my web app two langs. English and spanish.

I found a pretty good article on some ideas on how to do it

But i am concerned with loading this application wide properties file evertime the jsp is loaded
        Locale currentLocale;
        ResourceBundle messages;

        currentLocale = new Locale(language, country);

        messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);

SO i am wondering how other people are accomplishing this task?

  • 2
2 Solutions
better check that tutorial http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html See chapter 22 "Internationalizing and Localizing Web Applications"
Yes, ur approach is correct

Btw, ResourceBundle will not load each time of ur JSP hit

ResourceBundle  will load only once (at first hit) and so it will not cause any performance issue

No other best way is there to implement multilingual (many languages)
>>But i am concerned with loading this application wide properties file evertime the jsp is loaded

I think u have wrong opnion about ResourceBundle  bcaz of ur property file name

Actually, if u use Properties class, then it will loan ur file each time. ResourceBundle  will work differently

check the link for more information
As previously stated, resource bundles are the way to go. They are commonly used in things like Struts applications where they are an essential part. If you want easy internalization, I would take a good look at the fmt library of JSTL (JSTL can be found here http://jakarta.apache.org/taglibs/index.html).

This library allows many things but 2 of the most important are localization and iternationalization (often reffered to as l10n and i18n). This gives you multiple language support on your website as well as the correct formatting for things such as currency, time and date.

The fmt library is based around the use of Resource Bundles but all the hardwork is taken away. The library is read once at start-up and then stored in memory. This makes it very fast and very efficient. I'm currently using it for a site that supports both English (_en), French (_fr) and Chinese (_zh) languages and it's been brilliant.

Here's a simple example.

<%@ page language="java" contentType="text/html" %>
<%@ taglib uri='http://java.sun.com/jstl/fmt' prefix='fmt'%>
<%-- The following line is not required if you've set it up in web.xml --%>
<fmt:setBundle basename='i18n'/>
<title><fmt:message key='welcome'/></title>
<fmt:message key='hello'/>

where i18n_en.properties is:

and i18n_fr.properties is:

And now that webapp supports french and english, using the locale specified in the request sent by the browser.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now