在eclipse项目中使用cyrillic .properties文件 [英] Use cyrillic .properties file in eclipse project

查看:110
本文介绍了在eclipse项目中使用cyrillic .properties文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个小型项目,我想使用国际化。问题是当我尝试在里面使用西里尔文符号的.properties文件时,文本显示为垃圾。当我硬编码字符串它显示很好。

I'm developing a small project and I'd like to use internationalization for it. The problem is that when I try to use .properties file with cyrillic symbols inside, the text is displayed as rubbish. When I hard-code the strings it's displayed just fine.

这是我的代码:

ResourceBundle labels = ResourceBundle.getBundle("Labels");
btnQuit = new JButton(labels.getString("quit"));

在我的.properties文件中:

And in my .properties file:

quit =Изход

quit = Изход

我得到垃圾。当我尝试

btnQuit = new JButton("Изход);

正确显示,据我所知,UTF-8是用于文件的编码。

It is displayed correctly. As far as I am aware, UTF-8 is the encoding used for the files.

任何想法?

推荐答案

AnyEdit 是一个eclipse插件,可以让您轻松地将您的属性文件从和unicode符号转换(避免使用诸如native2ascii之类的命令行工具)

AnyEdit is an eclipse-plugin that allows you to easily convert your your properties files from and to unicode notation. (avoiding the use of command-line tools like native2ascii)

如果您使用的是 属性 类(不含资源束),由于Java 1.6可以选择加载具有自定义编码的文件,使用(而不是一个 InputStream

If you were using the Properties class alone (without resource bundle), since Java 1.6 you have the option to load the file with a custom encoding, using a Reader (rather than an InputStream)

我猜你也可以使用 new PropertyResourceBundle(reader) ,而不是 ResourceBundle.getBundle(。 。),其中阅读器是:

I'd guess you can also use new PropertyResourceBundle(reader), rather than ResourceBundle.getBundle(..), where reader is:

Reader reader = new BufferedReader(new InputStreamReader(
     getClass().getResourceAsStream("messages.properties"), "utf-8")));

这篇关于在eclipse项目中使用cyrillic .properties文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆