Use eclipse to edit Chinese resource files

Source: Internet
Author: User

Use eclipse to edit Chinese resource files

 

If struts is often used and international operations are performed, the processing of Chinese resource files should not be unfamiliar. For example, the following two files are in English and Chinese. For English, everything is normal; for Chinese, the native2ascii tool of JDK is generally used for conversion.

Application_en.properties

# Resources for the hello Sample Application

Hello. Title = a first struts Program

Hello. Prompt. User = Please enter a username

Hello. Page. Hello = Hello

Hello. Page. wellocome = Wellcome to blog of javamxj

Application_zh_cn.properties

# Resource files used by the hello instance

Hello. Title = the first struts Application

Hello. Prompt. User = enter the user name

Hello. Page. Hello = Hello

Hello. Page. wellocome = welcome to the blog of javamxj.

The current eclipse version is 3.1m6. If you use eclipse to edit the application_zh_cn.properties file, save the file, close the file, and open it again, the Chinese characters in the file are changed ????.

Why is this happening? In a Chinese operating system, the default encoding for Java type files in eclipse is GBK, but the default encoding for properties resource files is ISO-8859-1. Therefore, editing the Chinese in the Java file will not cause problems, but editing the Chinese in the properties resource file will cause problems.

In version 3.1m6, we can directly modify the default encoding of the properties resource file (which does not seem to be supported by eclipse3.0 ). On the eclipse main interface, choose Window> perferences> General> editors> context types.

After changing to GBK, open the application_zh_cn.properties file again, edit and save the file, and then open the file, the Chinese characters can be properly displayed.
This is not enough. You must also use native2ascii (native2ascii-Local Code-to-ASCII Code Converter) to convert it.
Convert a file that contains both local and non-Unicode characters to an ASCII character.
Native2ascii Command Format: native2ascii [-reverse] [-encoding] [inputfile [outputfile]
Note:
The Java compiler and other Java tools can only process files containing Latin-1 and/or Unicode (\ udddd mark) characters. Native2ascii converts a file containing other character encoding into a file containing Latin-1 and/or Unicode encoding characters.
If outputfile is omitted, the standard output device is used. In addition, if inputfile is also omitted, standard input is used for device input.
Option:
-Reverse
Perform the opposite operation: convert a file containing Latin-1 and/or Unicode characters to a file containing local encoding characters:-encoding encoding_name.
Specifies the encoding name used in the conversion process. The default encoding is obtained from the system property file. encoding. The encoding_name string must be a compliant string.
If the path of the application_zh_cn.properties file is D: \ myfiles \ myproject \, the method for converting the file is as follows: "Start" -- "run" (or press win + R directly ), enter cmd, press ENTER or click OK to open the command line window. Enter D:, press enter, enter CD myfiles, and press Enter. Enter CD myproject, and press Enter. Now, the file path has been transferred to the directory using the CD command, next, you can directly use the command to operate it. Enter native2ascii-encoding application_zh_cn.properties temp. properties, press Enter. Here a temporary file temp is output according to application_zh_cn.properties. properties, replace the file content in application_zh_cn.properties with the content of this temporary file. The converted application_zh_cn.properties is as follows:
# Hello \ u5b9e \ u4f8b \ u4f7f \ u7528 \ u7684 \ u8d44 \ u6e90 \ u6587 \ u4ef6
Hello. Title = \ u7b2c \ u4e00 \ u4e2astruts \ u5e94 \ u7528
Hello. Prompt. User = \ u8bf7 \ u8f93 \ u5165 \ u7528 \ u6237 \ u540d
Hello. Page. Hello = \ u4f60 \ u597d
Hello. Page. wellocome = \ u6b22 \ u8fce \ u6765 \ u5230javamxj \ u7684blog
This operation is okay for one or two resource files. If multiple resource files are used, it is too troublesome. You can create a batch processing file (. BAT), or create an ant file to use its native2ascii tasks, or perform batch processing.

 

Related Article

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.