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;
        }

  • 相关阅读:
    定时任务、间隔执行任务实现
    界面上小说或视频下载
    简单的打印日志
    无法识别的配置节 system.webServer
    压缩解压
    zabbix初级进阶
    Mysql高可用集群-解决MMM单点故障
    Mycat详解及配置读写分离(Centos7)
    MHA-结合MySQL半同步复制高可用集群(Centos7)
    MySQL全同步复制基于GR集群架构实现(Centos7)
  • 原文地址:https://www.cnblogs.com/chubeautiful/p/3148935.html
Copyright © 2011-2022 走看看