Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make multi language android application

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):

enter image description here

like image 688
Akbar Avatar asked Oct 29 '22 19:10

Akbar


1 Answers

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.

like image 191
Akbar Avatar answered Nov 15 '22 06:11

Akbar