我需要在 Windows 中设置一个文本字段,并将其输入语言设置为马拉雅拉姆语-印度。
我尝试使用此代码:
System.setProperty("user.language","MY");
System.setProperty("user.country","IN");
但是没有成功。
如何在 Java 中设置系统语言?
最佳答案
应该注意的是,“user.language”和“user.country”值需要在启动时作为 VM 参数传递,而不是使用 System.setProperty()
设置。在运行时,从System.setProperty()
开始不会影响内存中已有的默认区域设置。如果需要在运行时更改默认区域设置,请使用 Locale.setDefault();
// THIS WON'T WORK - IF YOU NEED TO SET DEFAULT LOCALE AT RUNTIME, USE Locale.setDefault()
System.setProperty("user.language","MY");
System.setProperty("user.country","IN");
先设置Locale,然后更改系统属性
Locale.setDefault( new Locale("MY"));
System.setProperty("user.language","MY");
Locale.setDefault( new Locale("IN") );
System.setProperty("user.language","IN");
引用:http://www.avajava.com/tutorials/lessons/how-do-i-set-the-default-locale-via-system-properties.html
关于java - 设置系统语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25091027/