下面介绍两个解决办法:
1. 装一个插件 Poperties Editor 就可以解决了!
Poperties Editor介绍:一个在编辑完成后可以将资源文件中的中文编码格式转换为unicode编码的插件,在开发国际化应用程序的时候非常有用http://propedit.sourceforge.jp/eclipse/updates/
安装方法:在线安装Poperties Editor
启动eclipse,点菜单Help -> SoftWare Updates -> find and install->选中Search for new features to install ->next->点击 New Remote site->给这个更新站点取个名字 如:luanma,url ,填写http://propedit.sourceforge.jp/eclipse/updates即可。->点击ok->选中刚才新加的站点名称,点击finish->他会自动找出与你所用的eclipse版本相适应的插件全部选中->后面只要选择install all即可
->最后会提示你重起你的eclipse 所有的properties文件名的前面都有一个绿色的p字.
注意:当你安装完之后,那个properties文件里有中文,你编译之后它自动就会转化了。
2. 在jdk的bin文件夹里有个专门转unicode的应用程序 native2ascii.exe
具体操作如下:
1) 把你要转换的文字写到一个文件里,如c:/test.txt
例如:内容如下:
hello.error.name = 请输入姓名。
hello.error.hobby = 请至少选择一个爱好。
hello.error.age = 请输入年龄,年龄必须大于{0}。2) 在cmd方式中转到bin目录,如C:/j2sdk1.4.2_04/bin
3) 输入命令 native2ascii c:/test.txt > c:/out.txt
转出来的内容就是这样的:
hello.error.name = \u8bf7\u8f93\u5165\u59d3\u540d\u3002
hello.error.hobby = \u8bf7\u81f3\u5c11\u9009\u62e9\u4e00\u4e2a\u7231\u597d\u3002
hello.error.age = \u8bf7\u8f93\u5165\u5e74\u9f84\uff0c\u5e74\u9f84\u5fc5\u987b\u5927\u4e8e{0}\u3002将内容直接粘到 ApplicationResources.properties 文件的相应位置就可以了。
4) 将out.txt里对应的编码替代原文件的编码即可
当然也可以这样
native2ascii -encoding gb2312 ApplicationResources.properties ApplicationResources_zh.properties