0

This is a really simple question that I just don't understand.

I use messages.properties files and the Messages class (generated by Eclipse) for my localization. I have this code:

public class LocaleTest {

    public static void main(String[] args) {
        System.out.println(Messages.getString("LocaleTest.LocaleTestMessage")); //$NON-NLS-1$
    }

}

And two properties files:

messages.properties

LocaleTest.LocaleTestMessage=This is the locale test.

messages_es.properties

LocaleTest.LocaleTestMessage=Esta es la prueba de locales.

The messages.properties and Messages.java files are created by Eclipse's "Externalize Strings" function (SourceExternalize Strings...).

When I run this in Eclipse (via standard Ctrl+F11) on a Spanish system, it displays "Esta es la prueba de locales," as expected. But when I export to .jar with default options and run from the command line, it prints "This is the locale test."

In a GUI application, the entire application is always in the main language (the strings from messages.properties).

I know the files are being exported correctly because it works if I add the following to the top of my messages class:

static {
    Locale.setDefault(new Locale("es"));
}

I've set my "Default language for non-unicode programs" to "Spanish", as described here.

So, why does this happen, and how can I fix it?

EDIT: Printing Locale.getDefault().getLanguage() yields "English" from the command line. From Eclipse, it prints "español."

wchargin
  • 15,589
  • 12
  • 71
  • 110
  • what is the locale set to be in your command line? – Thorbjørn Ravn Andersen Dec 15 '12 at 23:48
  • "English"; meant to include that. Sorry. – wchargin Dec 15 '12 at 23:49
  • What should have been set - environment variables, etc - in the command line for it to be Spanish? Check it is so. – Thorbjørn Ravn Andersen Dec 15 '12 at 23:52
  • It's supposed to determine the locale from the "Current language for non-Unicode programs" (Region and Language control panel), which is "Spanish (Mexico)". I want to be able to double-click a GUI jar and have it run in whatever language the user's system is in. – wchargin Dec 15 '12 at 23:54
  • Running `set LANG=es` and `set LC_ALL=es` before `java -jar ltest.jar` doesn't change the outcome, but running `java -Duser.language=es -Duser.region=MX -jar ltest.jar` runs as expected (Spanish). – wchargin Dec 15 '12 at 23:57

0 Answers0