javaSE国际化

国际化  用properties属性文件 实现

属性文件properties是键值对的方式存在

首先用 jdk的 cmd命令 native2ascii res.properties b 转化为unicode编码

加载 使用

import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.JFrame;

public class TestI18N {
 private static ResourceBundle bundle;
 private static Locale currentLocale;
 static {
//  currentLocale = Locale.getDefault();  //中文显示
  currentLocale = Locale.US;           //英文显示
  bundle = ResourceBundle.getBundle("Res", currentLocale);
 }
 private static String getString(String key) {
  String value = null;
  try {
   value = bundle.getString(key);
  } catch (Exception e) {
   value = key;
  }
  return value;
 }
 public static void main(String args[]) {
  JFrame jf = new JFrame(getString("title"));
  jf.setSize(350, 200);
  jf.setLocation(400, 300);
  jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jf.setVisible(true);
 }
}

猜你喜欢

转载自diyyangying-163-com.iteye.com/blog/1353770
今日推荐