Developing internationalization program with struts

Source: Internet
Author: User
Tags character set locale resource
Program for users, a Web program that supports internationalization has several forms





1. Automatically set the displayed language (without user intervention) according to the user's browser


2. Provides 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





use struts to develop internationalization programs is a very convenient thing, we look at the first two ways to achieve





1. This is the simplest way, you do not need to modify any program, just need to translate the resource files in accordance with the language and the internationalization of the requirements of the program name the same directory can be placed. such as Applicationresource_en_us.properties applicationresource_zh_tw.properties. This way, although the user is automatically set 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 a more common way for the user to select 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 must be logged on after the user's choice of language to save and let the program is


Locale Locale = new Locale (Request.getparameter ("Locale"));


//todo: Judge the validity of locale, invalid words are not deposited into sesssion


req.getsession (). setattribute (Globals.locale_key,locale);





OK, now 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 mentioned in the first steps.




The
struts framework is thoughtful for us when it comes to implementing internationalized applications, so all you have to do is translate.





last remember two points:


1. The character set of the page must be UTF-8, for example:





2. All the prompts for the page should be defined in the resource file





These two are basic requirements, here is just a reminder:














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.