This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Change JVM locale before Start up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Change JVM locale before Start up" Watch "Change JVM locale before Start up" New topic
Author

Change JVM locale before Start up

Mart?n L?pez
Greenhorn

Joined: Apr 18, 2002
Posts: 3
Hi,
Someone now how to change the default locale before a program start whitout modify the OS locale and the program, may be with a parameter.
Thanks in advance
Mart´┐Żn.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Moving to Java In General( intermediate ) forum...


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ashish Mahajan
Ranch Hand

Joined: Feb 19, 2003
Posts: 77
Hi mlopez,
Locale eng = Locale.US;
Locale.setDefault(eng);


The best teams have no specialists, only general contributors with special skills
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
mlopez,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you want to modify the locale before the program starts as you said, the solution is going to be OS-specific. The simplest solution is to modify the OS settings - e.g. on Windows XP go to Control Panel -> Regional and Language Options. If (as you said earlier) you don't want to do that either, there may be other undocumented solution. I found that on Windows XP if you do System.getProperties() one of the props is "user.country" - this is not a standards property required by the Java API, but that or something equivalent is probably on most operating systems. I found that if I invoke java with
java -Duser.country=CAN MyClass
and from MyClass.java call
System.out.println(Locale.getDefault());
my JVM now thinks it's in Canada. The OS locale remains unchanged.
Note that if you want a good cross-platform solution, you're really going to have to do it inside the program as Ashish shows. If you want, you can have the program read a properties file (or better yet, use Perferences) to detarmine what default locale the user wants.


"I'm not back." - Bill Harding, Twister
Mart?n L?pez
Greenhorn

Joined: Apr 18, 2002
Posts: 3
Thanks guys.
Jim I', going to test this. I know that the best solution is a configuration file but I can't modify the program.
Ashish Mahajan
Ranch Hand

Joined: Feb 19, 2003
Posts: 77
Hi Martin,
Am assuming that u r developing standalone app. So as Jim said normally developer should store the user settings about the language. In 1.4 use Preferences API for 1.3 (Mac OS X) use xml (i know jdom, it's much faster)
Now when the app starts the first thing to do is to check the System's locale got by Locale.getDefault() if this language bundle is installed (the software may be having language pack updates) if installed then no probs one can go ahead. If the language bundle is not available then one should show the message to the user stating that and set the language to the softeware's default locale by Locale.setDefault(Locale)
Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change JVM locale before Start up
 
Similar Threads
please explain every line
How to avoid System.out.println()
How to change the current OS Locale
Dynamic Internationalization (I18N) - Creating a Multilingual Application
Change date for other languages ?