Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to call java.exe with a different locale (language setting) ?

2,292 views
Skip to first unread message

Gianni Galore

unread,
Dec 14, 2010, 6:42:30 AM12/14/10
to
In my current WinXP I set the locale to "italian" how can I temporarily (for a java.exe call) switch to a
locale equal to "english"?

Is there a command line parameter similar to

java.exe --locale=EN_US -jar mylib.jar .....

Gianni

Patrick

unread,
Dec 14, 2010, 8:34:31 AM12/14/10
to

Try this:

java -Duser.language=en -Duser.region=US -jar mylib.jar

Patrick

Lew

unread,
Dec 14, 2010, 8:39:58 AM12/14/10
to
On 12/14/2010 06:42 AM, Gianni Galore wrote:
> In my current WinXP I set the locale to "italian" how can I temporarily (for a java.exe call) switch to a
> locale equal to "english"?

That depends on the target program's sensitivity to locales and how it reads
them from the command line. I find nothing in a short googling that indicates
a universal mechanism. I suppose you could use Windows' Control Panel to
change the default locale before running the program. I do not know if
there's a way to script such a change.

> Is there a command line parameter similar to
>
> java.exe --locale=EN_US -jar mylib.jar .....

java ...

There is no such command-line parameter, but you can change environment
variable values with the "-D" option if the program uses them.

Changing the locale in the environment is unlikely to have any effect on the
particular Java program unless the program itself has internationalization
support, e.g., via ResourceBundle. If it does, then such a program might
support a "-D" or positional parameter that sets the locale.

<http://download.oracle.com/javase/tutorial/i18n/index.html>

--
Lew
Ceci n'est pas une pipe.

Lew

unread,
Dec 14, 2010, 8:45:41 AM12/14/10
to
Gianni Galore a écrit :
>> In my current WinXP I set the locale to "italian" how can I
>> temporarily (for a java.exe call) switch to a
>> locale equal to "english"?
>>
>> Is there a command line parameter similar to
>>
>> java.exe --locale=EN_US -jar mylib.jar .....

Patrick wrote:
> Try this:
>
> java -Duser.language=en -Duser.region=US -jar mylib.jar

Huh, those properties aren't listed at
<http://download.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties()>

Are they universally available? (Which is not to say that every Java program
refers to them.)

Documentation?

Stanimir Stamenkov

unread,
Dec 14, 2010, 5:22:38 PM12/14/10
to
Tue, 14 Dec 2010 08:45:41 -0500, /Lew/:

> Patrick wrote:
>
>> Try this:
>>
>> java -Duser.language=en -Duser.region=US -jar mylib.jar
>
> Huh, those properties aren't listed at
> <http://download.oracle.com/javase/6/docs/api/java/lang/System.html#getProperties()>
>
> Are they universally available? (Which is not to say that every Java
> program refers to them.)
>
> Documentation?

I see "user.language" referenced from:

http://download.oracle.com/javase/6/docs/api/java/util/Locale.html#setDefault%28java.util.Locale%29

And then I read
<http://java.sun.com/developer/technicalArticles/J2SE/locale/>:

> ... on some Java runtime implementations, the application user can
> override the host's default locale by providing this information on
> the command line by setting the user.language, user.country, and
> user.variant system properties.
> (...)
> You can experiment with the above code example. Running on a U.S.
> English system, the above code prints en_US. If you provide
> command-line options as described above, you can coax your
> application into using any locale you need. For example, you can
> invoke the application like this:
>
> java -Duser.language=fr -Duser.country=CA Default

This gives pretty good chance the properties are supported by most
(if not all) available JVM implementations. If one has control over
the JVM implementation used, I think the given documentation is
enough in order to rely on the properties for start-up configuration.

Here's some more docs from IBM:

http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/rzaha/sysprop2.htm

This lists the "file.encoding" property which is also not listed at
System.getProperties() but in my experience is widely used and
relied on as standard.

--
Stanimir

Arne Vajhøj

unread,
Dec 14, 2010, 9:01:11 PM12/14/10
to

Call Locale.setDefault as the first thing in the code.

And remember if it is not your code then you can
create a main that calls the real main after doing so.

Arne

Real Gagnon

unread,
Dec 15, 2010, 6:53:23 AM12/15/10
to
gg...@osgitest.org (Gianni Galore) wrote in
news:4d075824$0$6760$9b4e...@newsspool3.arcor-online.net:

Try something like :

java -Duser.language=en -Duser.region=US MyApplication

Bye.

--
Real Gagnon from Quebec, Canada
* Java, Javascript, VBScript or PowerBuilder snippets
* http://rgagnon.com/howto.html
* http://rgagnon.com/bigindex.html

Roedy Green

unread,
Dec 15, 2010, 9:22:26 PM12/15/10
to
On Tue, 14 Dec 2010 14:34:31 +0100, Patrick <pat...@antispam.invalid>
wrote, quoted or indirectly quoted someone who said :

see http://mindprod.com/jgloss/properties.html
user.county, user.region and user.language
--
Roedy Green Canadian Mind Products
http://mindprod.com

Doubling the size of a team will probably make it produce even more slowly.
The problem is the more team members, the more secrets, the less each team
member understands about how it all fits together and how his changes may
adversely affect others.

DRan

unread,
Dec 19, 2010, 9:52:38 AM12/19/10
to

if you look at http://java.sun.com/developer/technicalArticles/J2SE/locale/
Half way down it mentions the command line arguments ( user.language
and user.country ).

0 new messages