The Source for Java Technology Collaboration

Home » java.net Forums » JDK » Java SE

Thread: Corrupt unicode characters

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 1 - Last Post: Feb 28, 2008 1:20 AM by: podlesh
echilon

Posts: 5
Corrupt unicode characters
Posted: Feb 27, 2008 7:29 AM
 
  Click to reply to this thread Reply

I'm trying to internationalize my program, but I'm having some problems. The characters aren't being displayed correctly. This happens with all languages with unicode characters, not just Czech. I've tried typing the unicode characters directly into the .properties file:
WELCOMETEXT=Vítejte do EasyForm!\n\n Je to porvé co spouatíte EasyForm, proto potYebujete nastavit heslo pro aifrování a deaifrování. Toto heslo budete muset vkládat poka~dé.

I've also tried using the native2ascii program to produce this:
WELCOMETEXT=V\u00c3\u00adtejte do EasyForm!\n\n Je to porv\u00c3\u00a9 co spou\u00c5\u00a1t\u00c3\u00adte EasyForm, proto pot\u00c5\u2122ebujete nastavit heslo pro \u00c5\u00a1ifrov\u00c3\u00a1n\u00c3\u00ad a de\u00c5\u00a1ifrov\u00c3\u00a1n\u00c3\u00ad. Toto heslo budete muset vkl\u00c3\u00a1dat poka\u00c5\u00bed\u00c3\u00a9.

But whenever I run the program, I just get corrupt characters:
Vítejte do EasyForm!
 
 Je to porvé co spouÅ¡títe EasyForm, proto potÅ"ebujete nastavit heslo pro Å¡ifrování a deÅ¡ifrování. Toto heslo budete muset vkládat pokaždé.

This is the code I'm using to create get and set the language strings:
ResourceBundle lang = ResourceBundle.getBundle("lang", new Locale("en"));
JTextPane txtWelcomeText = new JTextPane();
            txtWelcomeText.setText(lang.getString("WELCOMETEXT"));
	    System.out.println(lang.getString("WELCOMETEXT"));
            txtWelcomeText.setBackground(null);
            txtWelcomeText.setEditable(false);
            txtWelcomeText.setBorder(null);
            welcomePage1.add(txtWelcomeText,c);

The dodgy text appears in both the console and on the JTextPane, and all of the menus and buttons in the application.

podlesh

Posts: 75
Re: Corrupt unicode characters
Posted: Feb 28, 2008 1:20 AM   in response to: echilon
 
  Click to reply to this thread Reply

1) .properties file can contain only ASCII characters, always use native2ascii to encode non-ascii ones

2) When using native2ascii, don't forget to specify input encoding. In your case, you supplied UTF-8 input file, but native2ascii read it using some latin variant (probably windows-1250 or iso-8859-2).

Use: native2ascii -encoding UTF8 input.utf8.file output.properties


Btw it is quite easy to see that the properties file is invalid: every \uXXXX should be one unicode character, but you have two of them in place of every char (\u00c3\u00ad instead í =\u00ED, \u00c5\u00a instead of š = \u0161)




 XML java.net RSS