how to detect operating system language (locale) from java code

后端 未结 4 568
小鲜肉
小鲜肉 2020-11-30 03:09

What is the correct way of knowing operating system language (locale) from java code?

I have tried

Locale.getDefault()
System.getProperties(\"user.l         


        
4条回答
  •  失恋的感觉
    2020-11-30 03:40

    To be precise, you can try following code:

    public Locale getLocale() {
        if (this.locale == null) {
            this.locale = new Locale(System.getProperty("user.language"), System.getProperty("user.country"));
        }
        return this.locale;
    }
    

提交回复
热议问题