Tuesday, July 3, 2012

Multilanguage support & Internationalization (i18n) in Java WebApplication

1. Create a Simple dynamic web project in eclipse and name it as "Test".

2. create a package "com.example.test and place the property file inside the package




3. create the JSP page with name “index.jsp” and place the code below in that page.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="tt.jsp" method="post">
English:
<input type="radio" checked="checked"
name="lang" value="en">
<br>
French:
<input type="radio"
name="lang" value="fr">
<input type="submit" name ="Submit" value="Submit"></input>
</form>
</body>
</html>
4 create the JSP page with name “tt.jsp” and place the below code inside that page.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*"%>
<%@ page import="com.example.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String l1=null;
l1=request.getParameter("lang");
Locale lc;
ResourceBundle rb;
if(l1!=null){
lc = new Locale(l1);
rb = ResourceBundle.getBundle("com.example.test.resources", lc);
}
else{
lc = new Locale("en");
rb = ResourceBundle.getBundle("com.example.test.resources", lc);
}
%>
<%=rb.getString("helloworld")%>
</body>
</html>
5. To implement internationalization (i18n), create a property file for each language and place all those property file in one package as shown in the image above.

5.1    create the property file in the name of “resources_en.properties”

5.2  Place the below code inside the “resources_en.properties”
helloworld=Hello world

5.3      create the property file in the name of “resources_fr.properties”

5.4  Place the below code inside the “resources_fr.properties”
helloworld=Bonjour tout le monde

6. Now just run the index.jsp  file, the code will works.

Thank you for read this blog

10 comments:

  1. Thank you, I had been looking for some online reference to be used in my Java training and your work really helped me.
    Java Course in Chennai | Java Course in Chennai | Java Course in Chennai

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

      Delete
    2. Java Training Institutes Java Training Institutes Java EE Training in Chennai Java EE Training in Chennai Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

      Delete
  2. Translating apps that use .properties files for localization can be handled smoothly with the translation platform https://poeditor.com which works great when localizing software in a team.

    ReplyDelete
  3. it's furthermore extremely important to verify that document is downloaded effectively with no mistakes or if various other document gets saved.
    In many of the instances we all know which document gets saved after hitting obtain switch OR hyperlink. Today whenever we understand the file-name, we are able to confirm utilizing java for that ADocument Prevails' in a saved file area which we stipulate

    . For more info on this try this

    ReplyDelete
  4. Factor isn't clickable at point SeleniumWebdriverException
    This dilemma comes only once working together with opera drivers whilst the firefox surfers uses point site. If the aspect location isn't repaired and we are trying to do several steps on that one component can result a mistake as Iselenium.common.exceptions.WebDriverException - Component is not clickable at point (xx, xx). Different ingredient might get the clickA

    . For more info on this click here

    ReplyDelete
  5. Individual can also obtain the wording of the values inside the dropdown. Also can obtain the alternative that are picked from the individual. To make use of these selections, the Choose Marking needs to have "numerous" credit

    JQuery And KendoUI Date Picker Calendar illustration
    In this course, we will see how exactly to use Day Picker by acquiring distinct calendars. We shall consider several various calendars and see how to work with these

    . For more info on this visit here

    ReplyDelete
  6. All these have one of a kind components and capacities which chip away at their stage and structure. Java

    ReplyDelete
  7. I have completely read your post and the content is crisp and clear.Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated. Java Training in Chennai

    ReplyDelete