Struts stores Locale-specific messages in properties files. The sample application uses the following two files:
Intuitively, you would place Arabic text in the properties file and expect the application to display its home page in Arabic when a user selects Arabic. However, just putting the Arabic text in the properties files would result in the Arabic text displaying as question marks (see Figure 3) because text in the Properties file is not loaded in Unicode format.
You have to convert all Arabic characters to Unicode and write them in Unicode hex format in the properties files. Doing this manually is tedious. It's better to use
native2ascii.exe, a utility located in the <JDK_HOME>\bin folder of the Java SDK. It converts the characters written in Arabic to Unicode.
native2ascii, write Arabic messages in a text file (call it 1.txt) and then run the following code:
native2ascii -encoding utf-8 c:\1.txt c:\2.txt
You can then copy the converted text from the output file (2.txt) to the Arabic properties file. (Find more information about
native2ascii at java.sun.com.)
After doing this, you will see the Arabic version as shown in Figure 4.
Nothing Lost in Translation
As simply as that, you can enable your Web applications to handle Eastern languages just by using the basic Struts support for i18n and some additional Java/JSP code. You also can easily enhance the functionality presented in the sample application. For example, some applications require users to be able to change the locale in any page, not just at login. You can enable the sample application to do this by adding an Action class that is both responsible for changing language and capable of being called anywhere in the application.