在java中获取OS语言 [英] Getting OS language in java

查看:75
本文介绍了在java中获取OS语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个问题。

I'm running into a kind of problem here.

我是法国人,正在使用英文版的Windows XP。因此,我将区域选项设置为法语,但仍然具有英语UI。

I'm French and working on an English version of Windows XP. Therefore, I set the regional options to French, but still have an English language UI.

我正在开发一个小型Java SE应用程序,并决定使用它进行国际化资源包。

I'm working on a small Java SE application, and decided to internationalize it using resources bundle.

要显示正确的语言,我使用此功能创建包:

To display the proper language, I create the bundle with this function :

private static ResourceBundle bundle = ResourceBundle
          .getBundle("locale.Strings", Locale.getDefault());

但是Locale.getDefault()函数返回区域设置(意思是:法语),而不是系统UI语言。因此,我的UI在英语环境中默认为法语。好吧,那不是我所期望的......

But the Locale.getDefault() function returns the regional settings (meaning : French) and not the system UI language. As a result, my UI defaults to French, in an English environment. And well, that's not really what I expected...

有谁知道恢复系统UI语言的平台无关方式?
提前致谢!

Does anyone knows of a platform-independent way to recover the system UI language ? Thanks in advance !

编辑:修复本地到语言环境,谢谢。

Edit : fixed Local to Locale, thanks.

推荐答案

这是Windows中的错误配置。 区域设置#getDefault()返回系统区域设置,而不是日期/时间格式化区域或位置。

This is a misconfiguration in Windows. The Locale#getDefault() returns the system locale, not the date/time formatting region or location.

在下面的Windows XP特定屏幕截图中,您可以将区域选项语言设置为法语或其他你喜欢。 Advanced 菜单中的下拉列表实际上设置了系统区域设置,在您的情况下应设置为英语。

In the below Windows XP specific screenshot, you could just set the Regional Options and Language to French or whatever you like. The dropdown in the Advanced menu actually sets the system locale and should in your case be set to English.

不可否认,这在Windows XP中解释不足,Windows 7做得更好:

Admittedly, this is in Windows XP poorly explained, Windows 7 does it somewhat better:

这篇关于在java中获取OS语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆