Let's say I've got two strings.xml
files - one for English and one for Danish.
While most users would probably be happy with the Danish translations, it's not unlikely that some would prefer the English translations.
Is there a way to override Android's default choice of string resources? I'd love to have a setting that'd enable users to ignore any language-specific string resources and just default back to English.
Set your default Locale
to English
:
public class MyApplication extends Application
{
private Locale locale = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (locale != null)
{
newConfig.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
@Override
public void onCreate()
{
super.onCreate();
Configuration config = getBaseContext().getResources().getConfiguration();
locale = new Locale("en-US");
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
}
One option would be to change the locale within your app
Changing Locale within the app itself
Locale appLoc = new Locale("en");
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
getBaseContext().getResources().updateConfiguration(appConfig,
getBaseContext().getResources().getDisplayMetrics());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With