对完整HTML页面在JSF中进行国际化的正确方法? [英] correct way to do internationalization in JSF for full HTML pages?

查看:112
本文介绍了对完整HTML页面在JSF中进行国际化的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF2应用程序,到目前为止,我正在以典型的方式使用消息资源包进行国际化.例如:

I have a JSF2 application and so far I'm doing the internationalization in a typical way with a message resource bundle; example:

<f:view contentType="text/html" locale="#{loginHandler.currentLocale}">

<f:loadBundle basename="MessageResource" var="msg" />

<h:outputText value="#{msg.user_firstNameLabel}" />

我的问题是我有一个信息页面,其中包含两种语言的内容段落.我不想让页面上的每一行文本都成为消息属性文件中的key | value.

My problem is I have an information page with paragraphs of content in two languages. I prefer not to take every line of text on the page and make them key|values in the message properties file.

如果内容在两个html文件中;例如contactus_en.html和contactus_fr.html,根据当前语言环境显示正确语言的正确方法是什么?

If the content is in two html files; say contactus_en.html and contactus_fr.html, what would be the right way to display the right language based on the current locale?

谢谢! 罗布

推荐答案

执行所要求的最简单方法是创建一个控制器,该控制器将读取HTML文件的内容并按需返回它们.在这种情况下,您可以使用非常简单的声明从JSF页面中将其写出:

The easiest way to do what you are asking for is to create a controller that would read the contents of your HTML files and return them on demand. In such case you can write out it from your JSF page with very simple declaration:

<h:outputText escape="false" value="#{yourController.contactus}" />

由于您将要读取HTML文件的内容,因此需要告诉JSF不要对其进行转义(因此,escape ="false").
当然,您的控制器需要提供名为getContactus()的方法,该方法应读取您感兴趣的HTML文件的内容并将其作为String返回.我相信您可以轻松地处理它:)

Since you are going to read the contents of HTML file(s), you need to tell JSF not to escape them (thus escape="false").
Of course your controller need to provide method named getContactus() which should read the contents of HTML files of your interest and return them as String. I believe you can easily handle it :)

编辑-添加有关如何选择文件的信息.

如果您的HTML文件是与语言环境相关的,因此它们已经是双语语言,但是对于英语和法语而言是不同的,则可以轻松地从UIViewRoot获取当前的视图语言环境:

If your HTML files are locale-dependent so these are already bi-lingual but different for English and French, you can easily get current view Locale from UIViewRoot:

Locale currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
String fileName = "contactus_" + currentLocale.toString() + ".html";

这篇关于对完整HTML页面在JSF中进行国际化的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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