Design idea of developing internationalized program with struts framework

Source: Internet
Author: User
Tags character set locale resource

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.