Servers on unix machine are always using en as default locale. Following is locale output
LANG=en_US
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=C
I just don't understand if LANG is set correctly then why servers starts with en locale.
Locale getDefault() method in Java This method returns default Locale set by the Java Virtual Machine. This is static method so it can be called without creating object of the class Locale. Return Value: The method returns default Locale set by the Java Virtual Machine.
To specify the English language as it is used in the United Kingdom, use en-GB as the locale.
The default Locale is constructed statically at runtime for your application process from the system property settings, so it will represent the Locale selected on that device when the application was launched.
A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
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:
LC_ALL
LC_ALL
doesn't exist, scan the environment for LANG
user.language
is set, use that in place of the environment variables.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 LocaleTest
en_UK
> LC_ALL=ja_JP java LocaleTest
ja_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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With