Locale.getDefault() returns en always
In Linux/Unix/Mac, the settings LC_ALL
and LANG
can control the default locale for Java programs. In Windows, the locales are set from the Control Panel, under Regional and Language Options.
When the JVM starts in a *nix environment, it will do this:
- Scan the environment for
LC_ALL
- If
LC_ALL
doesn't exist, scan the environment forLANG
- If the JVM setting
user.language
is set, use that in place of the environment variables. - If nothing is set, default to
en_US
(I believe this is the final failure case)
In your environment, you have LC_ALL
set to C
, which is just the C locale. It's basically a traditional fallback to the days when locales weren't used.
You can change LC_ALL
in your case, and restart your JVM, and you should get a new value for java.util.Locale.getDefault()
.
Example:
import java.util.Locale;public class LocaleTest { public static void main(String[] args) { System.out.println(Locale.getDefault()); }}
Here's running:
> LC_ALL=en_UK java LocaleTesten_UK> LC_ALL=ja_JP java LocaleTestja_JP
Also note that if you're running Java 1.7.0-b147, there is a bug with the JRE not recognizing environment settings for locale, and will always use the default system locale.
Bug report here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7073906