语言配置加载

配置文件中类似如下格式文件加载:

en_US
zh_CN
zh_TW
ru_RU default
it_IT
ja_JP
ko_KR
iw_IL
ar_EG
es_ES
pt_PT
fr_FR
 

 

 // load locale config
    public static ArrayList<String> getLocales() {
        try {
            ArrayList<String> localeList = new ArrayList<String>();
            File file = new File(NwdDeviceConfig.getConfigPath() + NWD_LOCALE_CONFIG_PATH);
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line = "";
            String[] str = null;
            while ((line = br.readLine()) != null) {
                if (line != "" && line.indexOf("#") != 0) {
                    line = line.replace(" ", "");
                    if (line == "") continue;
                    if (line.length() > 5) {
                        str = line.split("_");
                        if (str.length == 2) {
                            line = str[0] + "_" + str[1].substring(0, 2);
                            if (str[1].indexOf("default") > -1) {//get default locale
                                //Log.i(TAG,"======xh======get default locale:"+str[0]+" "+str[1].substring(0,2));
                                defaultLocale = new Locale(str[0], str[1].substring(0, 2));
                            }
                        } else {
                            continue;
                        }
                    }
                    //add by fanjf 20190807 must check whether contain,only don't contain we can add it
                    if (!localeList.contains(line)) {
                        localeList.add(line);
                        //Log.d(TAG, "add " + line);
                    } else {
                        Log.w(TAG, "repeat language " + line);
                    }
                }
            }
            br.close();
            return localeList.size() == 0 ? null : localeList;
        } catch (java.io.FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值