8.7 Sample scenario: translating whole resources

 < Day Day Up > 

Another way to accomplish internationalization is by translating and maintaining separate JSPs within a predictable directory structure. The Portal will take responsability for locating the correct file at runtime, depending on the preferred language selected by the user .

Figure 8-35. Sample scenario

graphics/08fig35.gif

  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 8-19.

    Example 8-19. 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> 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 8-36. Copy a JSP page

    graphics/08fig36.jpg

  4. Now select the Web Content/messagereceiver/jsp/html/en folder, right-click it and select Paste .

    Figure 8-37. Paste a JSP page

    graphics/08fig37.jpg

  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.

    Example 8-20. 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 8-38 on page 288.

    Figure 8-38. Directory structure

    graphics/08fig38.jpg

  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 8-21. 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>    <B><%= request.getAttribute("MyMessage") %></B> <% } %> </DIV> 
    Example 8-22. MessageReceiverView.jsp (Br Portuguese)
     <%@ 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/pt_BR/MessageReceiverView.jsp". <br> <% if (request.getAttribute("MyMessage") == null) { %>    <B>Pronto para receber mensagem ...</B> <% } else { %>    <B>Mensagem recebida:</B>    <B><%= request.getAttribute("MyMessage") %></B> <% } %> </DIV> 
  8. Run the scenario (click Run on Server ) and verify your results in multiple languages.

  9. Change the locale in the user profile as before and try other supported languages.

 < Day Day Up > 


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net