I am suffering from a problem
I am setting Apps language using :
@TargetApi(Build.VERSION_CODES.N)
private static Context updateResources(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
configuration.setLocale(locale);
configuration.setLayoutDirection(locale);
Timber.d("LangCheck updateResources " + locale.getLanguage());
Timber.d("LangCheck updateResources " + locale.getDisplayLanguage());
return context.createConfigurationContext(configuration);
}
private static Context updateResourcesLegacy(Context context, String language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
configuration.locale = locale;
configuration.setLayoutDirection(locale);
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
Timber.d("LangCheck updateResources " + locale.getLanguage());
Timber.d("LangCheck updateResources " + locale.getDisplayLanguage());
return context;
}
After changing , I am able to use in selected language
But after restarting App , I am getting only English. i.e , the resources.getString(..)
gave English only even though the above functions run at every startup in base activity
I tried to find the language of the App using : Locale.getDefault().displayLanguage
. It's returning 'português' . It's correct
But , if I use resources.configuration.locale.displayLanguage
, I am getting 'inglês' !!!
Why this conflict ? That is ,
Locale.getDefault().displayLanguage => português
resources.configuration.locale.displayLanguage =>. inglês
I think since context language is still in English , I am getting getString () -> English Strigs
only
Why this conflict ?
pls help me ?