Written by ninadgawad on March 2nd, 2008
Implementing Websites For Internationalization
Java EE, Tutorials
6 responses
Most business in today’s open market are demanding their websites & web application to have multilingual support. This is in order to attract non-English speaking audiences to increase their customer base and make people comfortable using the application in their native language. But for this, it would require an existing business application to be customized to support native locale. The process of producing an application that can be localized for a particular country without any changes to the program code is called Internationalization.

Following are the list of things one needs to take care while making an application to implement Internationalization.
1. Producing Content in Unicode
You need to make sure that all files which contain the multilingual content are in Unicode format. By default most text editors will store your file in ASCII which does not support other language characters. So after saving any content in ASCII format and loading it, your browser might not be able to display correct text in native language. Here you need to convert the file from ASCII to UTF format.
For example, the steps required for doing this if you are using Notepad are,
- Open your JavaScript or properties, etc. file in notepad
- Go to > File > Save As > Encoding
- Change Encoding from ASCII to UTF-8
2. Files needed to be converted to UTF
.properties
All your properties file should have a suffix based on the language in which the content is stored in this file. For example,
- For English, content_en.properties for French content_fr.properties and so on.
- Most java frameworks like Struts, Spring have inbuilt support to detect JVM locale and select the corresponding properties file based on the extension of the file & JVM/Browser setting. You don’t need to add any code to detect the setting and set the properties file
.java
Make sure that your JVM has set the parameter -Dfile.encoding=UTF-8
.js
Set charset attribute of the SCRIPT tag to “UTF-8″. For example,
<script type=”text/javascript” src=”./urscript.js” charset=”UTF-8″></script>
.xml
Use the steps as in the first example to make sure the content within the XML files in is UTF-8 format.
.html/.htm
Add this line to head of all html pages.
<meta name=”http-equiv” content=”Content-type: text/html; charset=UTF-8“/>
.jsp
Set Content-type explicitly through your server side scripts. To do this, add this line to all your jsp pages,
<%@page contentType=”text/html; charset=UTF-8” pageEncoding=”UTF-8″%>
3. Configuring the Web Server
Your Web Server has to be configured to set the Content-type of headers to UTF-8 since by default the web server will replace the Content-type-header to ISO-8859 encoding. For example:
- In Apache Web Server, edit httpd.conf to set AddDefaultCharset=Off.
- In Tomcat Server set connector settings within the server.xml file to URIEncoding=”UTF-8″
4. Handling Request & Response Objects
Make sure that before reading request parameters & writing to response objects set character encoding type to UTF-8. This can be handled using filters where all the contents coming in and going out can be set to UTF-8 encoding. For example,
- request.setCharacterEncoding(“UTF-8″);
- response.setContentType(“text/html”);
- response.setCharacterEncoding(“UTF-8″);
5. Creating Database with Unicode encoding
While using a database make sure that the database created has encoding set to UNICODE. Most of the database servers like Oracle, Postgress, MySQL and MSSQL have this support. In order to create databases with unicode encoding use the following query,
CREATE DATABASE MyWebApps DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Once all the above steps are implemented your web application will work smoothly for all UTF-8 supported languages. In some cases, you will have to take care of NumberFormat, DecimalFormat and DateFormat. There are some FAQ’s on internationalization provided by Sun to get you started. But feel free to put in your doubts related to internationalization via comments. I will be glad to help you out.
(Ninad Gawad is a Java EE Developer who blogs at Technology Discussion)

6 Responses
Monday, March 3, 2008
[...] Following are the list of things one needs to take care while making an application to implement Internationalization. [click here to read complete article] [...]
Tuesday, March 4, 2008
Honestly I didn’t know that “internationalization” was even a word.
The Masked Millionaire
http://www.TheMaskedMillionaire.com
Friday, March 14, 2008
[...] Implementing Websites For Internationalization | Techtracer Un bon mémo pour ne rien oublier lorsqu’il s’agit d’internationaliser une application! (tags: internationalization, website,utf8,iso,encoding,encodage) [...]
Sunday, July 6, 2008
Hi, I am quite familiar on implemention Internationalization in a Struts application. But I would like to know how Internationalization can be implemented in a web application that uses conventional MVC architecture, that is the normal JSP’s, page Mappings etc. Please help me out.
Thanks
Dinesh T R
Tuesday, July 8, 2008
hi dinesh,
there are quite a different ways in which this can be implemented using the Locale.
try these links:
1) http://www.ibm.com/developerworks/java/library/j-jspapp/
2) http://www.javaworld.com/jw-03-2000/jw-03-ssj-jsp.html?page=1
Wednesday, March 11, 2009
thanks a lot!!