In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use Eclipse to edit Chinese resource files", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Eclipse to edit Chinese resource files" this article.
If you often use Struts and have done international operations, you should not be unfamiliar with the processing of Chinese resource files. For example, the following two documents, one in English and the other in Chinese. For English, business as usual; for Chinese, generally need to use JDK's native2ascii tool 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 Hello instances
Hello.title=*** Struts applications
Hello.prompt.user=, please enter a user name
Hello, hello.page.hello=.
Hello.page.wellocome=. Welcome to Javamxj's Blog.
My current version of Eclipse is 3.1M6. If you use Eclipse to edit the application_zh_CN.properties file, after saving, close the file, and then open it again, you will find that all the Chinese characters in this file have become.
Why did this happen? Under the Chinese operating system, the default setting for encoding Java type files in Eclipse is GBK, but the default setting for encoding Properties resource files is ISO-8859-1. So there is no problem editing the Chinese in the Java file, but there is a problem editing the Chinese in the Properties resource file.
Under the 3.1M6 version, we can directly modify the default encoding of the Properties resource file (the Eclipse3.0 version does not seem to support it). Under the Eclipse main interface, open Window-> Perferences-> General-> Editors-> Context Types
After you change it to GBK, open the application_zh_CN.properties file again, edit it and save it. When you open it again, the Chinese characters in the file can be displayed normally.
This is not enough, and you have to use native2ascii (native2ascii- native code-to-ASCII converter) to convert it.
Converts a file that contains locally encoded characters (neither Latin1 nor Unicode characters) to a file with ascii encoded characters.
Format of native2ascii command: native2ascii [- reverse] [- encoding] [inputfile [outputfile]]
Description:
Java compilers and other Java tools can only work with files that contain Latin-1 and / or Unicode encoded (\ udddd tokens) characters. Native2ascii converts files that contain other character encodings into files that contain Latin-1 and / or Unicode encoded characters.
If outputfile is omitted, standard output device output is used. In addition, if inputfile is also omitted, the standard input device input is used.
Options:
-reverse
Do the opposite: convert a file containing Latin-1 and / or Unicode encoded characters into a file containing locally encoded characters:-encoding encoding_name.
Specifies the encoding name used by the conversion process. The default encoding is obtained from the system property file.encoding. The encoding_name string must be a string that meets the requirements.
If the path to the application_zh_CN.properties file is: d:\ myfiles\ myproject\, the way to convert the file is as follows: "start"-"run" (or press Win + R directly), type cmd, press enter or click OK to open the command window. Enter cd myproject and press enter; enter cd myfiles, press enter; enter cd myproject, press enter Now that you have gone to the path of the file through the cd command, you can use the command to operate it directly, enter: native2ascii-encoding application_zh_CN.properties temp.properties, press enter, here you will output a temporary file temp.properties according to application_zh_CN.properties, and then replace the file contents in application_zh_CN.properties with the contents 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 fine for one or two resource files, which is a bit too troublesome if there are multiple resource files. You can create a batch file (.bat), or you can create an Ant file that contains native2ascii tasks, or you can batch.
The above is all the contents of the article "how to use Eclipse to edit Chinese resource files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.