java國際化

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;


public class I18n {

 
 public static void main(String[] args) {
  Locale l=Locale.getDefault();   //默認的local
  Locale us=new Locale("en","US");//一個  Locale 由語言和國家組成
  //System.out.println(l.getCountry());
  //System.out.println(l.getLanguage());
  ResourceBundle rb=ResourceBundle.getBundle("MessagesBundle", us);   //根據配置信息 獲取國際化文件
  //System.out.println(rb.getString("k1"));
  //System.out.println(rb.getString("k2"));
  MessageFormat mf = new MessageFormat(rb.getString("k1"));
  System.out.println(mf.format(new Object[]{"Tom"}));
  MessageFormat m = new MessageFormat(rb.getString("k2"));
  System.out.println(m.format(new Object[]{"john"}));
 }

 

}

 

MessagesBundle.properties  :k1=hello,{0}
                                                 k2=good bye

 

MessagesBundle_en_US.properties:k1=hello,{0}
                                                           k2=good bye,{0}

 

MessagesBundle_zh_CN.properties:k1=/u4f60/u597d,{0}
                                                           k2=/u518d/u89c1

 

 

o.properties:k1=你好,{0}
                       k2=再見,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章