0

In our eclipse application we are using the method to provide localization with a dedicated nls bundle, a messages.java and localized messages_xx_XX.properties files. This works generally very nice: When running on a german Windows, we get the german strings, english ones on an english Windows etc.

The request is now, that it shall be possible for a user to switch to a different language. So even when his Windows is set to german, he shall be able to run our software with e.g. english strings.

This didn't look to be too difficult, because there are several documentations out there, describing various methods to switch the Locale for a Java application. E.g. by using the commandline switches -Duser.language and -Duser.country. Or by using an approach as outlined in this stackoverflow post: How to set eclipse console locale/language.

Another method for eclipse should be to use the -nl switch for eclipse as e.g. "eclipse.exe -nl en".

Nooow: None of these approaches does work! Whatever you do on e.g. a german Windows system you'll always get the german strings, no matter what sort of approach you use.

Digging in the issue I found, that the binding to the respective messages_xx_XX.properties files takes place in the NLS.class in the "buildVariants" method. In this method "Locale.getDefault" is called and from the return value the country- and language codes are extracted and used to combine the names of the respective .properties files.

Unfortunately Locale.getDefault always returns de_DE on a Windows system with display language set to german (see http://blog.ej-technologies.com/2011/12/default-locale-changes-in-java-7.html). So no matter what you do, it seems one can't change the default locale for a java application by using any of the methods described above.

Or is there a way?

It would also help us, if we would know, how to reset the nlSuffixes field in org.eclipse.osgi.util.NLS programmatically, so we could try to trigger a reload of the translation properties files.

Community
  • 1
  • 1
Gavin Proggy
  • 71
  • 1
  • 4
  • Does this article [Default locale changes in Java 7 ](http://blog.ej-technologies.com/2011/12/default-locale-changes-in-java-7.html) help? – DavidPostill Jul 10 '14 at 15:38

1 Answers1

1

Found the solution by myself:

  1. Quite tricky: It does not work with an eclipse application inside of eclipse in debug mode. You need to export your application and then run it via the eclipse executable!
  2. The setting, which influences the locale for the NLS approach is taken from the eclipse framework property "osgi.nl".
  3. The way how it worked for me was, to put this property into the respective .ini file written by the eclipse export wizard as -Dosgi.nl=<code>

Sample .ini file part:

-vmargs
-Xmx1024m
-Xms256m
-XX:NewRatio=3
-Dosgi.nl=en_US
-Dorg.eclipse.ecf.provider.filetransfer.retrieve.connectTimeout=30000
-Dorg.eclipse.ecf.provider.filetransfer.retrieve.closeTimeout=15000
Gavin Proggy
  • 71
  • 1
  • 4