加载了错误的Java资源包 [英] Wrong Java resource bundle loaded

查看:66
本文介绍了加载了错误的Java资源包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在使用Java资源包来转换其标签. 我目前有两个文件:

In my application, I'm using java resource bundle for the translation of its labels. I currently have two files:

  • 带有英语(默认语言)标签的resources.properties
  • 带有法语标签的resources_fr.properties

然后,我使用以下命令加载捆绑包属性:

Then, I load the bundle properties with the following command:

ResourceBundle.getBundle(RESOURCE_BUNDLE_NAME, locale);

...,其中locale是用户的语言环境.

... where locale is the user's locale.

当我使用法语网络浏览器时,没关系,因为我的语言环境已正确设置为fr,所以我收到的所有消息都是法语. 但是,当我将浏览器切换为美国英语"时,它们仍然是法语!

When I'm working with a French web browser, that's ok, I'm getting all my messages in French, as my locale is correctly set to fr. But when I switch my browser to English US, they're still in French!

已使用en_US语言环境正确设置了locale变量,但是getBundle方法返回了具有fr语言环境的包,而不仅仅是返回了默认的包...

The locale variable is correctly set with the en_US locale, but the getBundle method returns me a bundle with the fr locale instead of just returning the default bundle...

这是正常行为吗?我很惊讶,因为我期望在没有附加特定资源包(例如法语)的情况下使用resources.properties的英语值...

Is it a normal behaviour? I'm very surprised, as I was expecting the English values of resources.properties to be used when the locale has no specific resource bundle attached to it (like French)...

推荐答案

这可能有助于澄清您的问题:

This might help to clarify your question:

http://docs.oracle.com/javase/tutorial/i18n/resbundle/propfile.html

这些语言环境对象应与在 前两个步骤.例如,Locale.FRENCH对象对应 到LabelsBundle_fr.properties文件. Locale.ENGLISH没有 匹配LabelsBundle_en.properties文件,因此默认文件为 使用.

These Locale objects should match the properties files created in the previous two steps. For example, the Locale.FRENCH object corresponds to the LabelsBundle_fr.properties file. The Locale.ENGLISH has no matching LabelsBundle_en.properties file, so the default file will be used.

这篇关于加载了错误的Java资源包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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