Reputation: 199
I have the following problem:
I want to change the language of my app programmatically.
So I used shared Preferences to change the locale.
Locale locale2 = new Locale("b0");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
b0 is the saved local.
b0 is working flawlessly with the German locale de and the English locale en , but not with the US one: en_US
Ofcourse I added a new folder:
res/values-en-rUS
With the american strings xml.
If I change the Language of my Phone to English (United States), the App starts with American English.
I even edited my lines to:
Locale locale2 = new Locale("en_US");
Still not working.
Is Anything wrong with "en_US"?
http://developer.android.com/reference/java/util/Locale.html
Any Help is very much accepted.
Upvotes: 3
Views: 1866
Reputation: 10710
I just found the answer (see the javadoc).
In your case, you should write:
Locale locale2 = new Locale("en","US");
The general function, in scala-based language, would be the following:
val locale = if(name contains '_') {
val splitted = sign.split("_")
new Locale(splitted(0),splitted(1))
} else {
new Locale(name);
}
Else it defines a new language code en_us
which is not what you want.
Upvotes: 2