Internationalization

The 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 named WebMessages_*.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 this way:

appclient -client DukesBankAppClient.jar es 

The administration client class BankAdmin creates a ResourceBundle that has a locale created from the command-line arguments:

//Constructor
public BankAdmin(Locale currentLocale) {
  //Internationalization setup
  messages = ResourceBundle.getBundle("AdminMessages",
    currentLocale); 

The web client Dispatcher component 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);
  } 

The web client's JavaBeans components access localized messages using messages.getString("key");.

The web client's JSP pages use the JSTL fmt:message tags to retrieve localized messages. You set the localization context of the JSTL fmt tag library as a context parameter when you package the web client with deploytool.

For example, here is how accountHist.jsp generates the headings for the transactions table:

<td><center><b><fmt:message 
  key="TxDate"/></b></center></td>
<td><center><b><fmt:message
  key="TxDescription"/></center></b></td>
<td><center><b><fmt:message 
  key="TxAmount"/></b></center></td>
<td><center><b><fmt:message
  key="TxRunningBalance"/></b></center></td>