Search code examples
javaandroidlocale

Language Change After Deploy - Android


My app supports 6 languages. I use the below function to switch between them. In order to create them, i used android translator. When i test my app on several devices it works just fine, but when i deploy it on the play store (as bundle) only 2 of them work (English and Greek) the other languages (Russian, Italian, France, german) doesn't work. Even if i change my device language to that specific language it doesn't change. Any ideas?

---Edit---

I found that when the app get installed it doesn't contain all the string files. If you specify a language then it downloads them and displays them. How can i force to download specific strings or even better when the app gets installed from the app store to have all the string.xml files?

// My locales
tempLangLocale = new String[]{"default", "eng", "el","it","fr","de","ru"};
// Language Change functions
public void changelang(String lang) {
    myLocale = new Locale(lang);
    SharedPreferences prefs = getSharedPreferences("CommonPrefs", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString("Language", lang);
    editor.commit();
    Locale.setDefault(myLocale);
    android.content.res.Configuration config = new android.content.res.Configuration();
    config.locale = myLocale;
    getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}

@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if (myLocale != null) {
        newConfig.locale = myLocale;
        Locale.setDefault(myLocale);
        getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
    }
}

Solution

  • So i found a fix. If i create an apk instead a bundle app. Apparently, the bundle app doesn't contain all the language files and it downloads them depending on the device locale.