smr
smr

Reputation: 33

Detecting when OS language is changed - Java

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!

Upvotes: 0

Views: 527

Answers (2)

Lukas Rotter
Lukas Rotter

Reputation: 4188

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.

Upvotes: 2

Puce
Puce

Reputation: 38132

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.

Upvotes: 0

Related Questions