• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Changing locale works in debug version of app, but only updates to EN or ES in release version?

RedHeadDev

Lurker
So I wanted to create a way for a user to change between 6 different languages within my Android app. Currently, I have string resource files for English (default), Spanish, German, French, Japanese, and Russian. When I run the code on my emulator, or on my phone through debug, everything works perfectly. The app updates when I select a language, and runs great.

However, when I change to the release version, generate a signed app bundle and upload it to the play store for internal testing, and I download the app from there, the only language options that work is English and Spanish. All my other language options revert to English, despite my logs stating that the locale of the configuration properly changed to the specific locale I want.

My guess is that maybe there's some sort of phone specific setting that's preventing me from seeing the additional languages? But I'm unsure how to work around that, and I'm also confused why, if that's the case, Spanish would be working but no other languages.

Here is the OnClick that sets the locale and calls my UpdateLocale method (These correspond to buttons I've added within an alert dialog box for language selection):

Code:
public void onClick(DialogInterface dialog, int which) {
   switch (which) {
      case 0:
         Locale usLocale = new Locale("en");
         editor.putString("Locale", "en");
         editor.apply();
         updateLocale(usLocale);
         dialog.dismiss();
         break;// english
      case 1:
         Locale esLocale = new Locale("es");
         editor.putString("Locale", "es");
         editor.apply();
         updateLocale(esLocale);
         dialog.dismiss();
         break;// spanish
      case 2:
         Locale deLocale = new Locale("de");
         editor.putString("Locale", "de");
         editor.apply();
         updateLocale(deLocale);
         dialog.dismiss();
         break;// german
      case 3:
         Locale frLocale = new Locale("fr");
         editor.putString("Locale", "fr");
         editor.apply();
         updateLocale(frLocale);
         dialog.dismiss();
         break;// french
      case 4:
         Locale jaLocale = new Locale("ja");
         editor.putString("Locale", "ja");
         editor.apply();
         updateLocale(jaLocale);
         dialog.dismiss();
         break;// japanese
      case 5: Locale ruLocale = new Locale("ru");
         editor.putString("Locale", "ru");
         editor.apply();
         updateLocale(ruLocale);
         dialog.dismiss();
         break;// russian
   }
   recreate();
}

And here is the UpdateLocale method itself:

Code:
public void updateLocale(Locale locale) {
    Resources res = getResources();
    Locale.setDefault(locale);

    Configuration configuration = res.getConfiguration();

    if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 24) {
        Log.e(TAG, "updateLocale: the os version is " + Integer.parseInt(android.os.Build.VERSION.SDK));
        LocaleList localeList = new LocaleList(locale);

        LocaleList.setDefault(localeList);
        configuration.setLocales(localeList);
        configuration.setLocale(locale);

    } else if (Integer.parseInt(android.os.Build.VERSION.SDK) >= 17){
        Log.e(TAG, "updateLocale: the os version is " + Integer.parseInt(android.os.Build.VERSION.SDK));
        configuration.setLocale(locale);

    } else {
        configuration.locale = locale;
    }

    res.updateConfiguration(configuration, res.getDisplayMetrics());
    recreate();
}

I have already added the locales I want to my build.gradle file

Code:
resConfigs "en", "de", "es", "fr", "ja", "ru"

And I have added the following to all activities within my android manifest
Code:
android:configChanges="locale"

If anyone knows what I might be doing wrong, or what I might be able to look for to figure out why there's a disconnect between my Debug and Release versions, I'd be eternally grateful.
 
Last edited:
I'm not a developer, and only speak one language, so I apoligize if this is way off the mark. Does the end user have to have the languages installed on their phone by chance?
 
Apparently by default they are! After looking it up, I simply disabled language-splitting within my build.gradle file, and now all languages that I give as options work perfectly!
Good news. If you're free and willing to help me, check out my free app and leave a 5-star, please. It's available on Google Play Store and just for a development exercise. Thank you in advance. :D
 
Back
Top Bottom