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