Internationalizing in Struts 2.0 (i18n) your application

Source: Internet
Author: User
Tags i18n new features

Internationalization is an integral part of a business system, so no matter what web framework you are learning, it is a skill that must be mastered.

In fact, Struts 1.x has done quite well in this section. It greatly simplifies the work that our programmers need to do to internationalize, for example, if you want to export an internationalized message, simply add file-name_xx_ to the code package Xx.properties (where File-name is the file name of the default resource file), and then indicate its path in struts-config.xml, and then output with <bean:message> logo on the page.

However, the so-called "no best, only better". Struts 2.0 does not stop in this part, but instead makes it more flexible and powerful on the basis of the original simplicity of ease of use.

International Hello World

Now let's look at an example--helloworld. This example shows how to output the corresponding HelloWorld according to the user's browser settings.

Create a project configuration development and running environment in eclipse (if you have questions about this step, refer to my earlier article, "Prepare for Struts 2.0").

In the SRC folder, add the Struts.properties file, which reads as follows:

Struts.custom.i18n.resources=globalmessages

Struts 2.0 has two profiles, Struts.xml and struts.properties are placed under web-inf/classes/.

Struts.xml for application-related configuration

Struts.properties configuration for the runtime (Runtime) of Struts 2.0

In the SRC folder, add the Globalmessages_en_us.properties file, which reads as follows:

Helloworld=hello world!

In the SRC folder, add the Globalmessages_zh_cn.properties file, which reads as follows:

helloworld= Hello, world!

Here I would like to share with you a good writing properties file of the Eclipse plug-in (plugin), with it we are editing some Simplified Chinese, Traditional Chinese and other Unicode text, you do not have to use the NATIVE2ASCII encoding. You can install this plugin through the software upgrade (Software Update) in eclipse as follows:

1. Expand the Eclipse Help menu, move the mouse over the software update subkey, and click Find and Install in the submenu that appears;

2, in the Install/update dialog box select search for new features to install, click Next;

3, in the Install dialog box click New Remote Site;

4, in the New Update Site dialog box name fill in "Propedit" or any other non-empty string, in the URL to fill in the http://propedit.sourceforge.jp/eclipse/updates/;

5, in the site to include the To search list, in addition to the previous step added to the site outside the other options to remove, click Finsih;

6, in the Pop-up Updates dialog box in the Select the features to install list all the end of the "3.1.x" option to remove (for Eclipse 3.2 version of Friends);

7, click Finish to close the dialog box;

8, after downloading, agreed to install, and then prompted to restart Eclipse, in the tool bar to see the shape of vi button to indicate the success of the installation, Plug-ins available. At this point, the file name of all properties files in Eclpise is labeled with the green P icon.

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.