5

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.

Michell Bak
  • 13,182
  • 11
  • 64
  • 121

2 Answers2

6

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());

    }
}
Pete Houston
  • 14,931
  • 6
  • 47
  • 60
  • Thanks a lot! I'll have a look at both this and the other similar solution, and see what works best in my case :) – Michell Bak Dec 07 '11 at 17:11
1

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());
Community
  • 1
  • 1
skynet
  • 9,898
  • 5
  • 43
  • 52
  • Thanks a lot! I'll have a look at both this and the other similar solution, and see what works best in my case :) – Michell Bak Dec 07 '11 at 17:11