gpt4 book ai didi

java - 设置系统语言

转载 作者:太空宇宙 更新时间:2023-11-04 06:37:59 26 4
gpt4 key购买 nike

我需要在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com