Chapter 4. National Language Support (NLS) 125
4.7 Sample scenario: translating whole resources
Another way to accomplish internationalization is by translating and maintaining
separate JSPs within a predictable directory structure. The Portal will take
responsibility for locating the correct file at runtime, depending on the preferred
language selected by the user.
Figure 4-39 Sample scenario
1. Open the Web Content/messagereceiver/jsp/html/MessageReceiverView.jsp
page to delete fmt tags and return to static information. Your code should look
as shown in Example 4-20.
Example 4-20 MessageReceiverView.jsp
<%@ page contentType="text/html" import="java.util.*, messagereceiver.*"%>
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<portletAPI:init/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
Action
Performed
View
Mode
Edit
Mode
doView
Portal
Browser
Action
Red
Action
Blue
Bean
JSP
View
Mode
Receive
Message
Request
Object
MessageReceiver.java
ActionEventPortlet.java
set
get
JSP
(en)
doView
html
English
Spanish
Portuguese
JSP
(es)
JSP
(pt)
126 IBM WebSphere Everyplace Access V5, Volume II: Application Development
This is a sample <B>view mode</B> page. You have to edit this page to customize
it for your own use.<BR>
The source file for this page is "/Web
Content/messagereceiver/jsp/html/MessageReceiverView.jsp".
<br>
<% if (request.getAttribute("MyMessage") == null) { %>
<B>Ready to receive message ... </B>
<% } else { %>
<B>Received a message:</B>
<B><%= request.getAttribute("MyMessage") %></B>
<% } %>
</DIV>
2. Select your Web Content/messagereceiver/jsp/html folder, right-click it and
select New -> Folder. Type en for the Folder name field and click Finish.
3. Right-click
Web Content/messagereceiver/jsp/html/MessageReceiverView.jsp and
select Copy.
Figure 4-40 Copy a JSP page
4. Now select the Web Content/messagereceiver/jsp/html/en folder,
right-click it and select Paste.
Chapter 4. National Language Support (NLS) 127
Figure 4-41 Paste a JSP page
5. Open the page Web
Content/messagereceiver/jsp/html/en/MessageReceiverView.jsp to update
the text indicating the location of the source file page. This is not required but
it is recommended for clarity.
128 IBM WebSphere Everyplace Access V5, Volume II: Application Development
Example 4-21 MessageReceiverView.jsp (English)
<%@ page contentType="text/html" import="java.util.*, messagereceiver.*"%>
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<portletAPI:init/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
This is a sample <B>view mode</B> page. You have to edit this page to customize
it for your own use.<BR>
The source file for this page is "/Web
Content/messagereceiver/jsp/html/en/MessageReceiverView.jsp".
<br>
<% if (request.getAttribute("MyMessage") == null) { %>
<B>Ready to receive message ...</B>
<% } else { %>
<B>Received a message:</B>
<B><%= request.getAttribute("MyMessage") %></B>
<% } %>
</DIV>
6. Optionally, repeat the steps to create the folders and JSPs for other
languages such as Spanish (es) and Brazilian Portuguese (pt_BR). Your
directory structure should be as illustrated in Figure 4-42 on page 129.
Chapter 4. National Language Support (NLS) 129
Figure 4-42 Directory structure
7. Modify the JSP pages to display a message in the proper language. Also
change the directory of the source file pages. For example, create a folder
with a JSP for Spanish (es).
Example 4-22 MessageReceiverView.jsp (Spanish)
<%@ page contentType="text/html" import="java.util.*, messagereceiver.*"%>
<%@ taglib uri="/WEB-INF/tld/portlet.tld" prefix="portletAPI" %>
<portletAPI:init/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
This is a sample <B>view mode</B> page. You have to edit this page to customize
it for your own use.<BR>
The source file for this page is "/Web
Content/messagereceiver/jsp/html/es/MessageReceiverView.jsp".
<br>
<% if (request.getAttribute("MyMessage") == null) { %>
<B>Listo para recibir mensajes ...</B>
<% } else { %>
<B>Mensaje recibido:</B>

Get IBM WebSphere Everyplace Access V5 Handbook for Developers and Administrators Volume II: Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.