Reputation: 345
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";
}
}
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
Upvotes: 2
Views: 2000
Reputation: 345
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
Upvotes: 5