make multi language android application

痞子三分冷 提交于 2019-12-30 06:51:41

问题


I created multi language (English, Russian, Uzbek) app. I put 4 string resoureses in 4 folders (values, values-en, values-ru, values-uz) as docs. When I change app language updates resourses configuration in App Controller like below:

 Settings.LANGUAGE = prefs.getString(User.LANG, Settings.RUSSIAN);
 Locale locale = new Locale(Settings.LANGUAGE);
 Locale.setDefault(locale);
 Configuration configuration = new Configuration();
 configuration.locale = locale;
 getBaseContext().getResources().updateConfiguration(configuration,
     getBaseContext().getResources().getDisplayMetrics());

After that App restarts by calling App controller's method like below:

public void reStart() {
    Intent i = getBaseContext().getPackageManager()
            .getLaunchIntentForPackage(getBaseContext().getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
}

After them It works well almost all devises. But on Samsung Galaxy S6 (SM-G920F), it works as crazy. Some words are in english and others are in Uzbek and ets. So, How to fix this error? isn't the concepts of "Supporting Different Languages" supported by (applicable to) all devices? By the way, I have checked that all resources are given in corresponding languages (as shown in attached image):


回答1:


From my observations, weird behaviour was affecting only Activity titles, and I found that I was setting translations of activity titles in Manifest file. Only these translations were misbehaving. All other dynamically set translations were working fine. So, to fix the problem, I removed all activity labels from Manifest file, then set activity titles in onCreate method as below:

getSupportActionBar().setTitle(R.string.title_activity_followers);

Problem solved.



来源:https://stackoverflow.com/questions/39727543/make-multi-language-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!