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
Joined: Apr 18, 2002
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.
Joined: Feb 19, 2003
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