How to auto-detect the current system language?

Asked

Viewed 374 times

3

package linguagem;
import java.util.*;
public class Linguagem {
    public static void main(String[] args) {
        Locale locale = new Locale("PORTUGUESE", "PT");
        System.out.println("Linguagem: " + locale.getDisplayLanguage());
    }
}

Then he returns portuguese.

inserir a descrição da imagem aqui

However, my system is in English, I need you to call me back english.

inserir a descrição da imagem aqui

Is there any way to auto detect the current system language?

  • 2

    Welcome to Stackoverflow in English. Whenever you have both the code and an image of the code, prefer to leave only the code, which is sufficient, as long as it is formatted correctly.

  • An important detail is that new Locale("PORTUGUESE", "PT") nay returns a locale that corresponds to the Portuguese language. The problem is that the constructor does not validate the entry and accepts anything. Correct for Portuguese from Portugal is new Locale("pt", "PT")

1 answer

5

You can use it Locale.getDefault();

Of documentation:

... The Java Virtual Machine sets the default locale During startup based on the host Environment....

In free translation:

The Java virtual machine obtains location configuration on startup based on system configuration.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.