Localization of Java programs

Source: Internet
Author: User

Task: there is a simple SWT window, such:

 

Perform localization.

The development tool used is eclipse 3.7.

1. Select the one corresponding to the preceding window. java file (mainframe in this example. java), right-click, and select Source-externalize strings in sequence. In the displayed dialog box, keep the default state, select next, and then click Finish. Two files are generated: messages. java and messages. properties.

The content in messages. properties is as follows:

View Source

 

Print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 MainFrame_1=Student Information
3 MainFrame_2=Name
4 MainFrame_3=Sex
5 MainFrame_4=Number
6 MainFrame_5=Class
7 MainFrame_6=Male
8 MainFrame_7=Female

2. Copy the messages. properties file to the bin folder in JDK on your computer. For example, I put it in the D: \ Program Files \ Java \ jdk1.6.0 _ 25 \ bin directory.

3. Open the messages. properties file in the bin directory in notepad and replace the English words after "=" with the desired Chinese characters. After replacement, the content is as follows:

View Source

 

Print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 Mainframe_1 = Student Information
3 Mainframe_2 = Name
4 Mainframe_3 = gender
5 Mainframe_4 = student ID
6 Mainframe_5 = Class
7 Mainframe_6 = male
8 Mainframe_7 = female

(Note:/javax/swing/plaf/basic/icons/javacup16.png indicates a path, regardless of which)

4. Next is a key step. Select Start-run, Enter cmd, and open the command window. The command to be entered is as follows:

Press enter to generate a newmessages. properties file with the following content:

View Source

 

Print?

1 MainFrame_0=/javax/swing/plaf/basic/icons/JavaCup16.png
2 MainFrame_1=\u5b66\u751f\u4fe1\u606f
3 MainFrame_2=\u59d3\u540d
4 MainFrame_3=\u6027\u522b
5 MainFrame_4=\u5b66\u53f7
6 MainFrame_5=\u73ed\u7ea7
7 MainFrame_6=\u7537
8 MainFrame_7=\u5973

5. Replace the messages. properties file in the Eclipse project with the above content and save it. Run the program. The effect is as follows:

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.