JSF语言环境:浏览器定义的语言似乎被忽略了 [英] JSF locale: browser defined language seems to be ignored

查看:104
本文介绍了JSF语言环境:浏览器定义的语言似乎被忽略了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的团队正在使用java开发Web 2.0应用程序,我们正在使用JSF作为表示层。我们从表示层开始,所以我们还没有添加业务和数据层。



我们使用的技术:
- JSF(Mojarra 2.0.3)
- Primefaces 2.1(JSF组件库)
- Spring Security 3.0.5
- jBoss 5.1



我被要求添加对应用程序的语言环境支持。所以我按如下方式配置了faces-config.xml文件:

 < application> 
< locale-config>
< default-locale> en< / default-locale>
< supported-locale> pt< / supported-locale>
< supported-locale> zh< / supported-locale>
< supported-locale> es< / supported-locale>
< / locale-config>
< message-bundle>
com。< company>。< product> .i18n.MessageBundle
< / message-bundle>
< / application>

我创建了MessageBundle后缀文件并部署了应用程序。我读到JSF使用3个条件来选择语言环境:
1)请求语言环境(Accept-Language请求标头)和支持的语言环境之间的匹配
2)faces配置中定义的应用程序默认语言环境file
3)JVM默认语言环境



当我尝试在浏览器选项中更改语言时,应用程序不会更改语言环境。即使我只配置一种语言而不是默认语言。我在这里错过了什么吗?这是预期的,或者实际上它应该在我更改浏览器语言时更改内容(假设它是受支持的语言)?



我非常感谢任何提示或至少有一个指针指向我可以找到答案的地方,因为我已经谷歌搜索了它没有运气。



提前致谢。

解决方案

我最终发现了问题所在。在代码中的某处有一个语言环境声明,因此,无论我在浏览器中选择哪种语言,所呈现的语言都将始终相同。一旦我删除了该声明,一切都开始正常工作。



我很抱歉没有尽快发布。



<另外,我还要感谢大家的提示。即使答案不在其中,我一路上学到了很多东西。


Currently my team is developing a web 2.0 application in java and we are using JSF for the presentation layer. We are beginning with the presentation layer so we have yet to add the business and data layer.

Technologies we use: - JSF (Mojarra 2.0.3) - Primefaces 2.1 (JSF library of components) - Spring Security 3.0.5 - jBoss 5.1

I was asked to add locale support to the app. So I configured the faces-config.xml file as follows:

<application>
    <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>pt</supported-locale>
        <supported-locale>en</supported-locale>
        <supported-locale>es</supported-locale>
    </locale-config>
    <message-bundle>
        com.<company>.<product>.i18n.MessageBundle
    </message-bundle>
</application>

I created the MessageBundle suffixed files and deployed the app. I read that there are 3 criteria that JSF uses to choose the locale: 1) match between request locales (Accept-Language request header) and the supported locales 2) application default locale defined in the faces config file 3) JVM default locale

When I try to change the language in my browser options the app does not change the locale. Even if I only configure one language other than the default one. Am I missing something here? Is this what to expect or in fact it should change contents when I change the browser language (provided it is a supported language)?

I would very much appreciate any tips or at least a pointer as to where I could find the answer seen as I have googled already for it with no luck.

Thanks in advance.

解决方案

I eventually found out what the problem was. Somewhere inside the code there was a locale declaration, for that reason, no matter which language I chose in my browser, the presented language would always be the same. Once I removed that declaration everything started working as supposed to.

I'm sorry for not posting this sooner.

Also I'd like to thank you all for your tips. Even though the answer was not in them, I learned a lot along the way.

这篇关于JSF语言环境:浏览器定义的语言似乎被忽略了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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