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 (Source → Externalize 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."