Getting the OS language in Java

I am facing some kind of problem.

I am French and working on the English version of Windows XP. Therefore, I installed regional options in French, but still have a user interface in English.

I am working on a small Java SE application and decided to internationalize it with a resource package.

To display the correct language, I create a package using this function:

private static ResourceBundle bundle = ResourceBundle .getBundle("locale.Strings", Locale.getDefault()); 

But the Locale.getDefault () function returns regional settings (which means: French), and not the system interface language. As a result, my default user interface is in French in an English environment. And well, this is not quite what I expected ...

Does anyone know of a platform-independent way to restore the system user interface language? Thanks in advance!

Edit: Fixed Local to Locale, thanks.

+7
source share
3 answers

This is an incorrect configuration on Windows. Locale#getDefault() returns the locale of the system, not the region or location of the date / time.

In the screenshot below of Windows XP, you can simply set the regional settings and language to French or whatever you like. The drop-down list in the "Advanced" menu actually sets the language standard for the system and should be set in your case in English.

enter image description here

Admittedly, this is poorly explained in Windows XP; Windows 7 does it a little better:

enter image description here

+7
source

I don’t have the means to try (as I usually avoid anything done by Microsoft), but look at them:

Java 7 required:

 Locale uiLocale = Locale.getDefault(Locale.Category.DISPLAY); 

What should be used to receive translations (starting with Java 7), anyway.

If this is not very useful, I would try:

 System.out.println(System.getenv("LC_MESSAGES")); System.out.println(System.getenv("LANG")); System.out.println(System.getenv("LANGUAGE")); 

However, in this case, I would expect some similarities by default to Locale ...

+3
source

I tried several things thanks to your suggestions, and here is my observation:

  • If you are using Java 6 and not Java 7, you are editing the file.
  • If you use Java 7, you should do as BalusC says: change the setting in Region and Language Settings. After that, Locale.getDefault () by default returns the display language, that is, English, if you set it to English. To verify this, you can create your own language by calling Locale.getDefault (Locale.Category.DISPLAY).
0
source

All Articles