Use Cyrillic .properties file in eclipse project

I am developing a small project, and I would like to use internationalization. The problem is that when I try to use a .properties file with Cyrillic characters inside, the text is displayed as garbage. When I program hard the lines, they are displayed just fine.

Here is my code:

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

And in my .properties file:

quit = Exit

And I get trash. When i try

 btnQuit = new JButton("); 

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

Any ideas?

+4
source share
2 answers

AnyEdit is an eclipse plugin that allows you to easily convert your property files from and to Unicode notation. (avoiding using command line tools like native2ascii)

If you used the Properties class (without a set of resources), since Java 1.6 you have the option to load a user-encoded file using Reader (and not InputStream )

I would suggest that you can also use new PropertyResourceBundle(reader) , rather than ResourceBundle.getBundle(..) , where Reader :

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

Properties is encoded by ISO-8859-1 by default. You must use native2ascii to convert your UTF-8 properties to a valid ISO-8859-1 property file containing Unicode escape sequences for all characters other than ISO-8859-1.

+4
source

All Articles