-
리소스 언어파일 임의로 가져오기과거...../개발일지 2012. 9. 4. 16:26
Locale[] localeA = Locale.getAvailableLocales();
boolean haveLang = false;
for (int i = 0; i < localeA.length; i++) {
if (localeA[i].getCountry().equals(mIsoCode[position])) {
haveLang = true;
mLangCode = localeA[i].getLanguage() + "_" + mIsoCode[position];
mEmptyTextView.setText(getEmptyTextRes(localeA[i]));
break;
}
}
함수 부분:
private String getEmptyTextRes(Locale locale){
Resources standardResources = getApplicationContext().getResources();
AssetManager assets = standardResources.getAssets();
DisplayMetrics metrics = standardResources.getDisplayMetrics();
Configuration config = new Configuration(standardResources.getConfiguration());
config.locale = locale;
Resources defaultResources = new Resources(assets, metrics, config);
return defaultResources.getString(R.string.xxxxxx);
}
*************위의 부분은 못 얻어오는 로케일 리스트가 있어서 새로운 방법을 찾았다*****************
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Resources r = getResources();
Configuration c = r.getConfiguration();
String[] loc = r.getAssets().getLocales();
for (int i = 0; i < loc.length; i++) {
Log.d("LOCALE", i + ": " + loc[i]);
c.locale = new Locale(loc[i]);
Resources res = new Resources(getAssets(), metrics, c);
String s1 = res.getString(R.string.hello_world);
c.locale = new Locale("");
Resources res2 = new Resources(getAssets(), metrics, c);
String s2 = res2.getString(R.string.hello_world);
if(!s1.equals(s2)){
Log.d("DIFFERENT LOCALE", i + ": "+ s1+" "+s2 +" "+ loc[i]);
}
}