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

how are people Internationalizating thier jsps

Hello

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
http://java.sun.com/docs/books/tutorial/i18n/intro/after.html

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

        currentLocale = new Locale(language, country);

        messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
        System.out.println(messages.getString("greetings"));


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

Thanks
0
paries
Asked:
paries
  • 2
2 Solutions
 
ramazanyichCommented:
better check that tutorial http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html See chapter 22 "Internationalizing and Localizing Web Applications"
0
 
neonlinesCommented:
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)
0
 
neonlinesCommented:
>>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
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ResourceBundle.html
0
 
bloodredsunCommented:
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'/>
<html>
</head>
<title><fmt:message key='welcome'/></title>
</head>
<body>
<fmt:message key='hello'/>
</body>
</html>

where i18n_en.properties is:
welcome=Welcome
hello=Hello

and i18n_fr.properties is:
welcome=Bienvenue
hello=Bonjour

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

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