2

My app supports two languages: ru and us(default) If system language is only English then nothing happened when I try to change language to ru BTW : everything is working fine in debug mode.

Is the application can change local to ru for example if have the only en system language? If you have an idea please share.

UpdateResouces

private static Context updateResources(Context context, String language) {

    Locale locale = new Locale(language, getCountry(language));
    Locale.setDefault(locale);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

        Resources res = context.getResources();
        Configuration config = new Configuration(res.getConfiguration());
        config.setLocale(locale);
        context = context.createConfigurationContext(config);

    } else {

        Resources resources = context.getResources();
        Configuration configuration = resources.getConfiguration();
        configuration.locale = locale;
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());

    }

    return context;
}

getCountry

private static String getCountry(String language) {
    switch (language) {
        case "ru" : return "RU";
        default: return "US";
    }
}

Folders with languages enter image description here

And also I change the language from settings

<string-array name="language_entries">
    <item>Русский</item>
    <item>English</item>
</string-array>
<string-array name="language_entryValues">
    <item>ru</item>
    <item>en</item>
</string-array>

attachBaseContext also modified

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(LocaleManager.setLocale(base));
}

Thank you in advance

hidd
  • 336
  • 3
  • 11
  • Please make sure your russian translation is also located in the release directory (in most cases the main directy) and not only in a debug subdirectory. – J. Hegg Nov 16 '20 at 21:39
  • @J.Hegg could you please give details about it. I have values folders in \app\src\main\res and there are no options to specify debug or release directory as I get. What do you mean saying about the release directory? – hidd Nov 16 '20 at 21:49

1 Answers1

4

The issue was in App Bundle.
By default only system languages will be downloaded with app installation.
Others will be downloaded on-demand.

Solution:

android {
bundle {
    language {
        // Specifies that the app bundle should not support
        // configuration APKs for language resources. These
        // resources are instead packaged with each base and
        // dynamic feature APK.
        enableSplit = false
        }
    }
}

Thanks to answer: https://stackoverflow.com/a/52733674/4515680

hidd
  • 336
  • 3
  • 11