配置文件中类似如下格式文件加载:
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;
}