有什么方法可以从 windows 属性中获取国家 ISO-2 代码,而不是从 JVM 中获取
Is there any way to get country ISO-2 code but from windows properties, NOT from JVM
基本上如标题所述,我已经尝试过:
Locale currentLocale = Locale.getDefault();
System.out.println(currentLocale.getDisplayLanguage());
System.out.println(currentLocale.getDisplayCountry());
System.out.println(currentLocale.getLanguage());
System.out.println(currentLocale.getCountry());
System.out.println(System.getProperty("user.country"));
System.out.println(System.getProperty("user.language"));
当我在寡妇设置中设置了完全不同的东西时,这一切都给我美国或英语。
请给我任何建议。
所以我希望获得 Contry 代码,例如,如果我在系统中设置了波兰,id 期望“PL”但我得到“US”
默认Java区域设置与系统区域设置不同,因为它可以被覆盖
- 具有
user.country
、user.language
和 user.variant
系统属性;
- 通过调用
Locale.setDefault()
.
non-standard 未记录 API 用于获取 OS 提供的语言环境信息。它在 Windows Vista 或更高版本上实现。尝试以下代码段。
import sun.util.locale.provider.HostLocaleProviderAdapter;
...
static String getHostCountry() {
for (Locale locale : new HostLocaleProviderAdapter().getAvailableLocales()) {
if (!locale.getCountry().isEmpty()) {
return locale.getCountry();
}
}
return null;
}
基本上如标题所述,我已经尝试过:
Locale currentLocale = Locale.getDefault();
System.out.println(currentLocale.getDisplayLanguage());
System.out.println(currentLocale.getDisplayCountry());
System.out.println(currentLocale.getLanguage());
System.out.println(currentLocale.getCountry());
System.out.println(System.getProperty("user.country"));
System.out.println(System.getProperty("user.language"));
当我在寡妇设置中设置了完全不同的东西时,这一切都给我美国或英语。 请给我任何建议。 所以我希望获得 Contry 代码,例如,如果我在系统中设置了波兰,id 期望“PL”但我得到“US”
默认Java区域设置与系统区域设置不同,因为它可以被覆盖
- 具有
user.country
、user.language
和user.variant
系统属性; - 通过调用
Locale.setDefault()
.
non-standard 未记录 API 用于获取 OS 提供的语言环境信息。它在 Windows Vista 或更高版本上实现。尝试以下代码段。
import sun.util.locale.provider.HostLocaleProviderAdapter;
...
static String getHostCountry() {
for (Locale locale : new HostLocaleProviderAdapter().getAvailableLocales()) {
if (!locale.getCountry().isEmpty()) {
return locale.getCountry();
}
}
return null;
}