For consumers, a Web program that supports internationalization has several forms
1. Automatically set the displayed language according to the user's browser (no user intervention required)
2. Provide user choice, the user decides according to own need to use which language displays
3. Combine the first two. The system automatically chooses a language, but simultaneously provides the user with the choice of
Using struts to develop internationalization programs is a very handy thing to see how the first two can be implemented
1. This is the simplest way, you do not need to modify any of the programs, just need to translate the resource files in accordance with the language and the internationalization of the requirements of the program named the same directory can be placed. For example Applicationresource_en_us.properties Applicationresource_zh_tw.properties. This approach, although automatically set the user to display the language, but sometimes because of the browser itself, or users want to see other languages when there is no way.
2. This is the more common way, the user chooses the language they want to display. The general situation is in the homepage or login page to add the language option, the user selected one of the login that is the user's choice of language to display, but the user login must be the user's choice of language to save and let the program is
Locale locale = new Locale(request.getParameter("locale"));
//TODO:判断locale的有效性,无效的话不存入到sesssion中
req.getSession().setAttribute(Globals.LOCALE_KEY,locale);
OK, this tag library can now according to you save in the session of the locale object to decide which language to load, by looking at the source of the tag library we can know at a glance that the tag library in the load resource before the session or the Locale object, If NULL, the value of Request.getlocale () is used to load the resource of the corresponding language, so this practice actually implements the third form mentioned above. The next step is to translate the resource files, as the first steps say.
The struts framework is thoughtful for us when it comes to implementing internationalized applications, so all you have to do is translate.
Finally remember two points:
1. The character set of the page must be UTF-8
2. All other information on the page should be defined in the resource file