Click to See Complete Forum and Search --> : unable to locate locale message bundle properties file


sirpelidor
08-26-2008, 05:05 PM
Hi, I am having trouble to have java ResourceBundle to read a localed bundle properties file.

Platform is winxp, jvm1.5,
File structure is:
C:\myProg <-root
C:\myProg\test <-package
C:\myProg\test\Run.java
C:\myProg\test\MessageBundle.properties <- default properties
C:\myProg\test\MessageBundle_zh_HK.properties <- localed properties (written in notepad and save as Unicode, window notepad contains BOM)

inside MessageBundle.properties:
test = Hello

inside Message_zh_HK.properties:
test = 喂 //hello in big5 encoding

run.java:
package test;
import java.util.*;
public class Run{
public static void main(String[] args){
Locale locale = new Locale("zh","HK");
ResourceBundle resource =
ResourceBundle.getbundle("test.MessageBundle", locale);
System.out.println(resource.getString("test"));
}//main
}//class

when run this program, it'll kept diplay "hello" instead of the encoded character...

then when i try run the native2ascii tool against MessageBundle_zh_HK.properties

I'm getting monster characters, any thoughts on that?

Thank you.

chazzy
08-26-2008, 08:47 PM
i have a possibly stupid question. are you using an IDE or command line? are the properties files being copied into the classpath during compilation?

sirpelidor
08-26-2008, 09:45 PM
hi chazzy,

i don't think ur question is stupid at all. in fact u raised a very good point which I've missed to inform...

-I created a project using eclipse (name: myProg)
-At the project level, I changed the encoding property to UTF-8
-After created Run.java and MessageBundle.properties, I go ahead and create -MessageBundle_zh_HK.properties in eclipse. However, eclipse won't let me save because it complained my text file contains non ASCII character (even the project is setup as UTF-8).
-Then I create MessageBundle_zh_HK.properties using notepad
-when execute run.java, it only can read MessageBundle.properties, MessageBundle_zh_HK.properties basically was skipped even when Locale was set to zh, HK.
-after google for a while, I learned javac can't read Unicode with BOM (which generated by notepad) and I need tool such as native2ascii to convert the native character into unicode
-after done so, (native2ascii -encoding UTF-8 MessageBundle_zh_HK.properties test.properties, replace current MessageBundle_zh_HK.properties), java is able to read the localed text file, but system.out.println display weird character instead of what shows in text file.

as u can see, i was able to get ResourceBundle object to read the locale, it just won't display on system.out.println correctly.

Please have me further clarify if I made myself unclear.

Thank you :)

chazzy
08-26-2008, 09:58 PM
oh, ok. do you have the necessary language installed on your OS?

sirpelidor
08-26-2008, 10:01 PM
yup, i'm using winxp with all the languages I needed.

In fact, I wrote the same hello world in c# and I was able to get the Big5 character to print in dos console. Just to demonstrate that OS support UTF-8 in console mode.

chazzy
08-26-2008, 10:47 PM
ok, if this isn't it i have no clue.

you're running java 6 multi language correct?

another thing I just saw is from here: http://osdir.com/ml/java.ide.netbeans.user/2001-01/msg00663.html

while it sounds like you did the first part, the second part "does java/netbeans have access to the fonts" kind of sticks out to me.

sirpelidor
08-27-2008, 02:04 PM
hi, I got the problem solved....

The reason I was unable to display double byte character was because:
1) i used native2ascii with wrong encoding
2) Locale locale = new Locale("zh", "HK") was not picking up the encoding I used with native2ascii

somehow native2ascii -encoding Big5 input.txt output.txt was not doing what I expected to do, nor -encoding UTF-8 or -encoding Unicode

However, I was able to get around it using JInto (http://www.guh-software.de/jinto_en.html), resource editor plug-in for eclipise. It is quite a handy tool when working with i18l resources.