Reputation: 1409
Currently my System Locale is en-UK
, it used to be en-US
(I've restarted my computer for this change to be in effect)
When I print Locale.getDefault().getCountry().toString()
I still get US though.
In the API it states:
getDefault()
Gets the current value of the default locale for this instance of the Java Virtual Machine.
Maybe the JVM locale is not related to the system locale? If so, how do I get the system locale on Windows?
Edits:
Upvotes: 2
Views: 3641
Reputation: 1409
I realized in production an argument WAS being set that altered the Locale.getDefault() return value. This was difficult to check/prove.
My solution was that the user.country and user.language were not changed and reflected the actual Locale.
Locale locale = new Locale(System.getProperty("user.language"),System.getProperty("user.country"));
Locale.setDefault(locale);
//this will do the trick for me
Big thanks to everyone who answered and commented.
Upvotes: 1
Reputation: 1323
There was is bug in Sun JDK 6u27+ and JDK 7, BugId 7073906:
The Locale returned from Locale.getDefault() is en_US when it shoud be en_GB.
I think this is what is biting you here :)
Upvotes: 1
Reputation: 10423
The country variant is taken from the "Non-Unicode" settings in the extended dialog of Windows locale.
Upvotes: 1
Reputation: 799
Your JVM locale and System locale can indeed possibly be different.
When the JVM is first loaded it assigns its locale to be the same as the system's locale unless you specified otherwise on the command line (not all implementations let you do this).
You can see what the value of this JVM locale is from Locale.getDefault()
.
In case you want to change that you can: Locale.setDefault("<preferred_locale>")
read more about it here.
The system locale setting depends on the OS that you are using. I don't know much about Windows but, you can see what the values are from System.getEnv()
. It returns a Map<String, String>
of all environment properties and you can look for something like LANG or GDM_LANG, etc.
Upvotes: 3