Java 7 默认语言环境
我刚刚安装了 jre7,我很惊讶地发现我的默认区域设置现在是 en_US。对于jre6,它是de_CH。
与jre7有什么不同?默认区域设置不再是操作系统之一吗? (顺便说一句,我使用的是 Windows7)
谢谢您的回答。
编辑: 我看到 Category.FORMAT 的区域设置是“旧”区域设置 (de_CH)。 Category.DISPLAY 的区域设置从操作系统的语言中获取语言(在 Windows 中,这是在“控制面板”>“区域和语言”>“键盘和语言”>“显示语言”中完成的)以及来自...?
似乎不同的是属性“user.country”。使用 Java6,我得到“CH”,使用 Java7,我得到“US”。
I have just installed jre7 and I'm surprised to see that my default locale is now en_US. With jre6 it was de_CH.
What is different with jre7? Is the default locale no more the one of the Operating System? (btw, I'm using Windows7)
Thx for your answer.
Edit:
I have seen the Locale for Category.FORMAT is the "old" one (de_CH). The Locale for Category.DISPLAY takes the language from the language of the OS (in Windows this is done in Control Panel > Region and Language > Keyboard and Languages > Display Language) and the contry from...?
What seems to be different is the property "user.country". With Java6 I get "CH" and with Java7 I get "US".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这是设计好的。 Java 7 改变了
Locale.getDefault()
的工作方式。 Oracle 已输入一个缺陷,但他们基本上说这是按设计的。综上所述,必须修改操作系统的显示语言。仅修改区域格式已经不够了。
请阅读此处的错误报告:Locale.getDefault() 返回错误的 Java SE 7 语言环境
This is as designed. Java 7 has changed the way
Locale.getDefault()
works. A defect has been entered with Oracle, but they basically said this is As Designed.To sum up, you must modify the Display Language of the OS. Modifying the Region Format only is no longer sufficient.
Read the bug report here: Locale.getDefault() returns wrong Locale for Java SE 7
此更改很好地描述了 博客文章 和 兼容性页面。
请注意,您可以通过将
sun.locale.formatasdefault
系统属性设置为true
来恢复到旧的行为。The change is described quite well in this blog post and on the compatibility page.
Note that you can revert to the old behavior by setting the
sun.locale.formatasdefault
system property totrue
.Java 7 中的区域设置似乎有一些变化,即 UI 和“用户”区域设置之间的区别。请参阅此。有 现在
setDefault(Locale.Category, Locale)
。但是,这并不能真正解释您所经历的情况 - 我只是指出 Java 7 中有关区域设置处理的更改这一事实。There seems to be some changes regarding Locale in Java 7, namely differentiation between UI and 'user' locale. See this. There is now
setDefault(Locale.Category, Locale)
. However, this does not really explain what you are experiencing - I'm merely pointing out the fact that there has been changes in Java 7 regarding locale handling.这对我来说确实看起来像一个错误:
用 java 5 或 java 6 打印运行它:'nl_NL'
java7: 'en_US'
This really looks like a bug to me:
running this with java 5 or java 6 prints: 'nl_NL'
java7: 'en_US'
如何在程序开始时按照以下方式设置您的区域设置,具体取决于 java 版本:
}
What about setting your Locale at the start of the program in the following way, depending on java version:
}
检查 Windows 控制面板区域和语言选项中的“位置”设置(德语:“Region und Sprache”、“Aufenthaltsort”)。
Check the setting "Location" in Windows control panel Regional and language options (German: "Region und Sprache", "Aufenthaltsort").
如果您足够勇敢,您可以调用:
这会为这两个类别设置默认区域设置
但这当然可能会导致副作用。
If you are brave enough you can call the :
This sets the default Locale for both of those categories
But this of course could cause side effects.