先建立語系檔檔名

繁體中文 lang_zh_TW.properties

英文 lang_en_US.properties

 String viewt[] = new String[50];

ResourceBundle resource = ResourceBundle.getBundle("lang");
viewt[0] = resource.getString("t0");

參考

http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/I18NMessage.htm

 

系統會依照   Locale locale = new Locale();  決定要抓的語系檔

 

如果是中文的語系檔要經過轉換

native2ascii -encoding Big5 messages_zh_TW.txt messages_zh_TW.properties

 

倒是今天這樣做的時候

當我把class包成jar的時候

C:\jdk\bin\jar cfm testc.jar manifest.mf *.class 

檔案結構 

   testc.jar 
   lang_zh_TW.properties
   lang_en_US.properties

結果執行testc.jar 卻發生下列訊息

exception in thread "main" java.util.MissingResourceException: Can't find bundle
for base name messages, locale en_US

可以看得出來找不到en_US這個語系檔,可是我是放在同一個目錄怎會找不到,查的好多資料

後來我想到一個作法!!!該不會要全部包進去 jar裡面吧

於是再重下一次jar封裝

C:\jdk\bin\jar cfm testc.jar manifest.mf *.clas .properties

這次就可以正常執行的...

arrow
arrow
    全站熱搜

    ROACH 發表在 痞客邦 留言(0) 人氣()