public class LanguagePro {
private static String language;
/**
* 实例化时给language赋值
*/
public LanguagePro(){
try {
FileInputStream fis = new FileInputStream(path);
pros.load(fis);
language = pros.getProperty("language");
//不能用中文,在没有英文语言包的系统上"中文"会成为乱码
if (language.equals("Chinese"))
{
language = "Chinese";
}else {
language = "English";
}
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage(),e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error(e.getMessage(),e);
}
//return str;
}
/**
*
* @param key 枚举属性_EN或_CN前面的值
* @return 对应的值
*/
public String getString(String key){
String str = null;
if(language.equals("English")){
str = Languages.valueOf(key + "_EN").getDesc();
}else{
str = Languages.valueOf(key + "_ZH").getDesc();
}
return str;
}
private static Properties pros = new Properties();
private static String path = System.getProperty("user.dir")
+ "\\conf\\conf.properties";
}
public enum Languages {
//属性
PROMPT_ZH("提示"),
PROMPT_EN("Info");
private String desc; // 枚举说明
/**
* 私有的构造方法
*/
private Languages(String desc) {
this.desc = desc;
}
/**
* 获取枚举值的说明
*
* @return String
*/
public String getDesc() {
return desc;
}
}
public class LanguageAll {
//将LanguagePro对象变为一个静态属性
public static LanguagePro lp = new LanguagePro();
}//不用老是其new
//调用,枚举的_EN或_ZH前面的
LanguageAll.lp.getString("PROMPT");