Search code examples
javawindowsjava-6

How to get systeminfo locale - Locale.getDefault()


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:

  • after researching the other questions about this, I found it useful to say that I'm dealing with Java 6.
  • I've just found that on my OS (Windows 7) the System locale change is not reflected in Java, but the Control Panel > Region and Language > Formats change is reflected.
  • I've overlooked something, in production code the osgi.nl config attribute is set, changing what Locale.getDefault would return otherwise

Solution

  • 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.