0

I'm coding a fullscreen bilingual app in Java. Fullscreen means, the language bar below the desktop would be hidden from the user, and... I need it! So, how can I reproduce it programmatically?!
Strictly speaking, I need to know, what the current OS language is, when a change language event occurs, and, a way to set it when needed.
How should I get the task done?
Thanks!

smr
  • 33
  • 6
  • 1
    possible duplicate of [how to detect operating system language (locale) from java code](http://stackoverflow.com/questions/2469435/how-to-detect-operating-system-language-locale-from-java-code) – Cheesebaron Jul 23 '15 at 20:55
  • As for detecting when it changes, I hunch is there wouldn't be any way to do that besides just polling. – Jason Sperske Jul 23 '15 at 21:02
  • @Cheesebaron - Nay! Or... not exactly! The thread you mentioned questions just one of my three questions! – smr Jul 23 '15 at 21:03
  • @LuxxMiner - Yes, I expected that! – smr Jul 23 '15 at 21:15
  • I tried the solutions... even polling! No help! Any other idea?! I wonder why Java doesn't support such a thing! – smr Jul 24 '15 at 18:20

2 Answers2

2

get OS language:

System.getProperty("user.language");

set OS language:

System.setProperty("user.language","..."); //... = What language you want to set it to

If you just want to change the language inside the program, via a combobox or something, just add an ActionListener to the component and use the set method mentioned before to set the language. System.setProperty("user.language",yourComboBox.getText()); Then you can just set the language inside your program by simple if-statements.

Lukas Rotter
  • 4,158
  • 1
  • 15
  • 35
0

To work with multiple languages in Java usually means to work with multiple Locales.

Use either

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

or

Locale defaultFormatLocale = Locale.getDefault(Locale.Category.FORMAT);

depending on for what you want to use the locale.

AFAIK, there is no OS independent way in the standard library to detect OS language changes. You probably will have to manually restart the application.

Puce
  • 37,247
  • 13
  • 80
  • 152