Technology Blog

Partners

WhichIsBest

Ads

ads
WhichIsBest

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

20 comments:

  1. The Voice Winner 2018
    The Voice Usa
    The Voice Season 15
    The Voice 2018 Winner

    I like this article.I was searching over search engines and found your blog and its really helps thank you so much Happy New Year 2019 Wish

    ReplyDelete
  2. It's Really A Great Post. Looking For Some More Stuff.



    shriram break free

    ReplyDelete
  3. Thanks for the nice information and also it's very inspirational and Thanks for the detailed explanation. Really useful. Keep sharing more. Regards. Click Here for Commerce College in Hyderabad

    ReplyDelete
  4. Wow...What an excellent informative blog, really helpful. Thank you. Best Oracle DBA Course Training| orskl

    ReplyDelete
  5. Really very great information to be provided and the All points discussed were worth reading and i’ll surely work with them all one by one.
    Best C and C++ Programming Training Academy in Kanchipuram

    ReplyDelete
  6. Wonderful post. Thank you for updating such an informative content.


    Best Python Training Academy in Kanchipuram

    ReplyDelete
  7. Your Blog is nice and informative..Thanks for sharing this valuable information with us..I am visiting this website regularly, this web site sharing nice thoughts

    Best MATLAB Training Academy in Kanchipuram

    ReplyDelete
  8. Thanks for this grateful information. all this information is very important to all the users and can be used good at all this process.


    Best Web Designing Training Academy in Kanchipuram

    ReplyDelete
  9. I really enjoyed your blog Thanks for sharing such an informative post.Looking For Some More Stuff.

    shuttering works

    ReplyDelete
  10. I really enjoyed your blog Thanks for sharing such an informative post.Looking For Some More Stuff.

    best seo company in bangalore SSS digital Marketing

    ReplyDelete
  11. Really Interesting Article . Nice information will look forwardr next article update Keep posting the articles :)
    If you are looking for any data science Related information please visit our website Data Science Course In Bangalore page!

    ReplyDelete
  12. نجار ابواب بالرياض نجار ابواب بالرياض
    تركيب ستائر بالرياض افضل شركة تركيب ستائر بالرياض
    تنظيف مكيفات بالرياض شركة غسيل مكيفات بالرياض
    شركة تنظيف افران الغاز بالرياض تنظيف افران بالرياض

    ReplyDelete

WhichIsBest
WhichIsBest