[java] Setting java locale settings

When I use the default java locale on my linux machine it comes out with the US locale settings, where do I change this so that it comes out with the correct locale?

This question is related to java locale

The answer is


I believe java gleans this from the environment variables in which it was launched, so you'll need to make sure your LANG and LC_* environment variables are set appropriately.

The locale manpage has full info on said environment variables.


On linux, create file in /etc/default/locale with the following contents

LANG=en.utf8

and then use the source command to export this variable by running

source /etc/default/locale

The source command sets the variable permanently.


You can change on the console:

$ export LANG=en_US.utf8

One way to control the locale settings is to set the java system properties user.language and user.region.


If you are on Mac, simply using System Preferences -> Languages and dragging the language to test to top (before English) will make sure the next time you open the App, the right locale is tried!!


On linux, create file in /etc/default/locale with the following contents

LANG=en.utf8

and then use the source command to export this variable by running

source /etc/default/locale

The source command sets the variable permanently.


One way to control the locale settings is to set the java system properties user.language and user.region.


With the user.language, user.country and user.variant properties.

Example:

java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass


For tools like jarsigner which is implemented in Java.

JAVA_TOOL_OPTIONS=-Duser.language=en jarsigner

If you ever want to check what locale or character set java is using this is built into the JVM:

java -XshowSettings -version

and it will dump out loads of the settings it's using. This way you can check your LANG and LC_* values are getting picked up correctly.


One way to control the locale settings is to set the java system properties user.language and user.region.


With the user.language, user.country and user.variant properties.

Example:

java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass


You could call during init or whatever Locale.setDefault() or -Duser.language=, -Duser.country=, and -Duser.variant= at the command line. Here's something on Sun's site.


You can change on the console:

$ export LANG=en_US.utf8

You could call during init or whatever Locale.setDefault() or -Duser.language=, -Duser.country=, and -Duser.variant= at the command line. Here's something on Sun's site.


If you ever want to check what locale or character set java is using this is built into the JVM:

java -XshowSettings -version

and it will dump out loads of the settings it's using. This way you can check your LANG and LC_* values are getting picked up correctly.


You could call during init or whatever Locale.setDefault() or -Duser.language=, -Duser.country=, and -Duser.variant= at the command line. Here's something on Sun's site.


One way to control the locale settings is to set the java system properties user.language and user.region.


I had to control this in a script that ran on a machine with French locale, but a specific Java program had to run with en_US. As already pointed out, the following works:

java -Duser.language=en -Duser.country=US ...

Alternatively,

LC_ALL=en_US.UTF-8 java ...

I prefer the latter.


With the user.language, user.country and user.variant properties.

Example:

java -Duser.language=th -Duser.country=TH -Duser.variant=TH SomeClass


I had to control this in a script that ran on a machine with French locale, but a specific Java program had to run with en_US. As already pointed out, the following works:

java -Duser.language=en -Duser.country=US ...

Alternatively,

LC_ALL=en_US.UTF-8 java ...

I prefer the latter.