Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to override strings.xml in res/values?

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.

like image 802
Michell Bak Avatar asked Dec 07 '11 15:12

Michell Bak


2 Answers

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

    }
}
like image 63
Pete Houston Avatar answered Oct 14 '22 16:10

Pete Houston


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());
like image 23
skynet Avatar answered Oct 14 '22 14:10

skynet