zoukankan      html  css  js  c++  java
  • java后台获取国际化资源文件


     //current属性,由于此属性只做赋值操作,不做取值操作,因此没有get方法
     private Locale current;

     public void setCurrent(Locale cur) {
      this.current = cur;
     }
     
     public Map<String, Locale> getLocales() throws UnsupportedEncodingException {
            Map<String, Locale> locales =new HashMap<String, Locale>(3);
            try {
             
             /*这里是根据当前用户选择的语言类型,获取指定资源文件,这一步非常重要
             (备注:资源文件如果不是放在src根目录下,需要加上path)*/
             
                ResourceBundle bundle = ResourceBundle.getBundle("com/wistron/wh/swpc/homesecurity/message" , current);
               if(bundle!=null){
                //设置工程支持的语言类型,key里的值对应资源文件里的key的值
                   locales.put(bundle.getString("hs_select_zh_tw"), Locale.TAIWAN);
                   //locales.put(bundle.getString("hs_select_zh_cn"), Locale.CHINA);
                   locales.put(bundle.getString("hs_select_zh_english"), Locale.US);
               }
              
            }catch(Exception ex){
             System.err.println("[Property]:Can't Load message_.properties");
             ex.printStackTrace();
            }
               
            return locales;
        }

  • 相关阅读:
    nginx:安装成windows服务
    org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 18
    数据库中间件
    架构策略
    谈判
    设计模式 总结 常用10种
    08 状态模式 state
    07 策略模式 strategy
    06 命令模式(不用)
    05 观察者模式 Observer
  • 原文地址:https://www.cnblogs.com/chubeautiful/p/3148935.html
Copyright © 2011-2022 走看看