Reputation: 3182
I want to test how my application looks like, and force it to load some specific language, but I don't want and don't need it in production code, so it can be some switch in eclipse or some code in onCreate.
EDIT: I don't want to manually change this, I want code what will let me to automate my tests.
Upvotes: 2
Views: 1536
Reputation: 22647
Just change the language on your emulator. If you need to run automated tests against particular languages, just define separate AVDs configured for each language.
Any code you call is just going to force the same thing to happen as if you had changed the settings.
Upvotes: 0
Reputation: 3182
I did something like this in my onCreate method:
// LOCALE
if (DEBUG == true)
{
Misc.setLocale(this, "en"); // change "en" to "fr" for french
}
And here is setLocale
method:
public static void setLocale(Context context, String language)
{
final Locale locale = new Locale(language);
Locale.setDefault(locale);
final Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
Now I can really fast change languages, I don't need to bother with emulator or settings in my device. I also can't forget about this, because of checking for DEBUG value.
Upvotes: 4