In application supporting multiple languages using Locale.setDefault(newLocale);
we are changing the language but there is no way to change language to device default language. What is the best way to find device default language in settings programatically.
Asked
Active
Viewed 4,730 times
3

MWiesner
- 8,868
- 11
- 36
- 70

Vishal Pawar
- 4,324
- 4
- 28
- 54
-
3Call `Locale.getDefault()`, and save the result. – CommonsWare Jan 16 '16 at 13:38
-
After setting new locale it will return the last locale we set so its not usefull, thanks – Vishal Pawar Jan 16 '16 at 13:39
-
1:: sigh :: Call `Locale.getDefault()` **before you call `Locale.setDefault()`**, and save the result. – CommonsWare Jan 16 '16 at 13:41
-
No but if user changes the language in settings it will not work. :) – Vishal Pawar Jan 16 '16 at 13:43
3 Answers
5
check this:
Resources.getSystem().getConfiguration().locale.getLanguage();

Vyacheslav
- 26,359
- 19
- 112
- 194
2
In general, store user modifiable setting in a variable controlled by you, not Oracle. I.e. never call Locale.setDefault
when user changes your application's locale, but rather change a variable under your control.
There are overrides for each locale-dependent method that take Locale
parameter.
That's where you should pass locale variable under your control.
This way, you can always consult Locale.getDefault
for system settings.

Alexander Pogrebnyak
- 44,836
- 10
- 105
- 121
-
thanks for your answer but its in context of android so Locale.setDefault is useful to me to set the new language in app – Vishal Pawar Jan 16 '16 at 13:56