6. Previewing Internationalized Pages

During developing an internationalized application, sometimes it is necessary to view the JSP pages in the different languages to fix the localization and web design issues related to internationalization.

Workshop's JSF support includes design time support for localization resource bundles.

6.1. Configure the application for French

  1. Open the JSF configuration file workshop-jsf-tutorial/web/WEB-INF/config/faces-config.xml.
  2. Locate the <application> element specifying the resource bundle and default locale for the application.
  3. In the <locale-config> element add a <supported-locale> element for the French locale as shown below in bold text.
  4. <application>
      <message-bundle>resources.application</message-bundle>
      <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>fr_FR</supported-locale>
      </locale-config>
    </application>
  5. Save the faces-config.xml file.
  6. You need to create the properties file with key-value pairs for French language support. You can import the file application_fr_FR.properties from the folder workshop-jsf-tutorial/web/Resources to the resources package.

6.2. Localize the view at design time

  1. Open register.jsp and click the Design tab.
  2. In the Workshop main menu bar select Text > Resource Locale. The Resource Locale dialog is displayed, allowing you to select configured locales for the web application.
  3. Select the French (France) locale and click OK. Notice that the text in register.jsp is now in French
  4. Reset the locale to English.

6.3. Localize the view at design time [Optional]

The locale-config element in faces-config.xml lists the default locale and the other supported locales. The locale-config element enables the system to find the correct locale based on the browser's language settings. In register.jsp page we will manually set the French locale to override these settings.

  1. In register.jsp, add following lines of code after the tag libraries definitions and before the <f:loadBundle> tag.
  2. <%
      javax.faces.context.FacesContext ctx =javax.faces.context.FacesContext.getCurrentInstance( );
      ctx.getViewRoot( ).setLocale(new java.util.Locale("fr", "FR"));
    %>
  3. Save the register.jsp page and run the application on the server.
  4. Refresh the web brower. It displays application component labels and messages in French.

  5. Comment (/* … */) the above code which sets the French locale manually and save the register.jsp page.
  6. Refresh the register.jsf page in Web browser and verify that it displays the application in English language.
  7. Stop the server.

Click one of the following arrows to navigate through the tutorial:


Still need help? Post a question on the Workshop newsgroup.