Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Tutorials I18N Internationalization Code Example

Related Tutorials


 
 

Share on Google+Share on Google+

Internationalization Code Example

Advertisement
This Example shows you Internationalization son of language.

Internationalization Code Example

     

This Example shows you Internationalization  son of language. This application gives the way of format for different languages. here I have specified only three languages i.e.-English, Chinese, French.

In the application given below we will develop a form for users from different countries. So user can select the from language as per suitability and operate further process.

index.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>

<head>

<title>Select Language</title>

</head>

<body>

<h1>Please select language:</h1>

<c:url value="application.jsp" var="engURL">

<c:param name="locale" value="en_US" />

</c:url>

<a href="${engURL}"> <img src="english.gif" /> </a>

<br />

<br />

<c:url value="application.jsp" var="chineseURL">

<c:param name="locale" value="zh_HK" />

</c:url>

<a href="${chineseURL}"> <img src="chinese.gif" /> </a>

<br />

<br />

<c:url value="application.jsp" var="frenchURL">

<c:param name="locale" value="fr_FR" />

</c:url>

<a href="${frenchURL}"> <img src="french.gif" /> </a>

</body>

application.jsp :

<%@ page pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<html>

<c:set var="loc" value="en_US" />

<c:if test="${!(empty param.locale)}">

  <c:set var="loc" value="${param.locale}" />

</c:if>

<fmt:setLocale value="${loc}" />

<fmt:bundle basename="app">

<head>

<title><fmt:message key="newTitle" /></title>

</head>

<body>

<h1><fmt:message key="newTitle" /></h1>

<br />

<c:url value="procform.jsp" var="formActionURL" />

<form action="${formActionURL}" method="post">

<table>

<tr>

<td><fmt:message key="lastName" /></td>

<td><input type="hidden" name="locale" value="${loc}" /> <input

type="text" name="lastname" size="40" /></td>

</tr>

<tr>

<td><fmt:message key="firstName" /></td>

<td><input type="text" name="firstname" size="40" /></td>

</tr>

<tr>

<td><fmt:message key="postalCode" /></td>

<td><input type="text" name="postcode" size="40" /></td>

</tr>

<tr>

<td><fmt:message key="password" /></td>

<td><input type="password" name="pass" size="40" /></td>

</tr>

<tr>

<td colspan="2" align="center"><input type="submit"

value="<fmt:message

key='submitForm'/>" /></td>

</tr>

</table> </form>

</body>

</fmt:bundle>

</html>

procform.jsp :

<%@ page pageEncoding="UTF-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<fmt:requestEncoding value="UTF-8" />
<html>
<fmt:setLocale value="${param.locale}"  />
<head>
  <fmt:bundle basename="app">
  <title><fmt:message key="appInfo"/></title>
</head>
  <body>
   <h1><fmt:message key="appInfo"/></h1>
   <br>
   <table border="1">
     <tr>
        <td><fmt:message key="lastName"/></td>
        <td>${param.lastname}</td>
     </tr>
     <tr>
       <td><fmt:message key="firstName"/></td>
       <td>${param.firstname}</td>
     </tr>
     <tr>
      <td><fmt:message key="postalCode"/></td>
      <td>${param.postcode}</td>
     </tr>
     <tr>
       <td><fmt:message key="password"/></td>
                <td>${param.pass}</td>
            </tr>
        </table>
    </body>
</fmt:bundle>
</html> 

app.properties
#import<stdio.h>
#import"MyClass.m"
int main(){
MyClass *class = [[MyClass alloc]init];
printf("Sum is : %d",[class sum : 5 andb : 6 andc:10]);
[class release];
return ;
} 

app_fr.properties

newTitle=Formulaire de Demande
lastName=Pr\u00e9nom
firstName=Nom
postalCode=Code postal
password=Mot de pass\u00e9
submitForm=Valider
appInfo=L\u2019information de demadeur

app_zh.properties

newTitle=\u7533\u8acb\u8868\u683c
lastName=\u59d3
firstName=\u540d\u5b57
postalCode=\u90f5\u653f\u7de8\u865f
password=\u5bc6\u78bc
submitForm=\u63d0\u4ea4\u8868\u683c
appInfo=\u7533\u8acb\u4eba\u8cc7\u6599 

Output : This is first  page of the application



when user selects first (English) option, next page will be....

If user when user selects second (Chinese) option, next page will be....

Download Source Code

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 11, 2009

Related Tutorials

Discuss: Internationalization Code Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
kapil
June 22, 2011
where to place these properties file

please give a complete descriptive process of doing i18n in jstl
DMCA.com