|
Home TOC Index |
|
Search
Feedback |
Internationalization
The J2EE application client and Web client distributed with the Duke's Bank application are internationalized. All strings that appear in the user interfaces are retrieved from resource bundles. The administration client uses resource bundles named
AdminMessages_*.properties. The Web client uses resource bundles namedWebMessages_*.properties. Both clients are distributed with English and Spanish resource bundles.The application client retrieves locale information from the command line. For example, to use the Spanish resource bundle, invoke the application like this:
runclient -client BankApp.ear -name BankAdmin esThe administration client class
BankAdmincreates aResourceBundlewith a locale created from the command-line arguments://Constructor public BankAdmin(Locale currentLocale) { //Internationalization setup messages = ResourceBundle.getBundle("AdminMessages", currentLocale);The Web client
Dispatchercomponent retrieves the locale (set by a browser language preference) from the request, opens the resource bundle, and then saves the bundle as a session attribute:ResourceBundle messages = (ResourceBundle)session. getAttribute("messages"); if (messages == null) { Locale locale=request.getLocale(); messages = ResourceBundle.getBundle("WebMessages", locale); session.setAttribute("messages", messages); }In the Web client, each JSP page first retrieves the resource bundle from the session:
<% ResourceBundle messages = (ResourceBundle)session.getAttribute("messages"); %>and then looks up any string that it needs in the bundle. For example, here is how
accountHist.jspgenerates the headings for the transactions table:<td><b><%=messages.getString("TxDate")%></b></td> <td><b><%=messages.getString("TxDescription")%></b></td> <td><b><%=messages.getString("TxAmount")%></b></td> <td><b><%=messages.getString("TxRunningBalance")%></b></td>
|
Home TOC Index |
|
Search
Feedback |