Java / JSF i18n长文本(术语,常见问题) [英] Java/JSF i18n long texts (terms,faq)

查看:151
本文介绍了Java / JSF i18n长文本(术语,常见问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数情况下,我只是在页面的某处组合了很多短文本字符串。但在某些情况下,我只有一个包含长静态文本的页面,如术语或常见问题解答。

in most cases i just have a lot of short text strings combined somewhere in the page. But on a few occasions i have just a page with long static text, like terms or faq.

现在,只需将段落放在资源包中,或者建立一个切换到terms_en.xhtml等等。

Now, just put the paragraph also in the resource bundle or build a switch to either terms_en.xhtml and so on.

在JSF中处理长文本的最佳/默认方式是什么?

Whats the best/default way to handle long texts in JSF?

推荐答案

通常有两种方法:


  1. 无论资源文件有多长,都要放入文本。我相信你不想这样做,因为它很麻烦,资源文件变得难以维护。

  2. 创建静态文件(即HTML页面或简单文本文件)并在运行时加载它们。对于HTML文件,您可以轻松地使用例如iframe嵌入它们。您只需要读取正确的文件,但名称可以由后端控制器根据UIViewRoot Locale构建。对于静态文本文件,您的方法会有所不同:只需在后端按需加载它们并询问内容。

个人用法,我更喜欢简单文本文件的第二种方法。如果您不需要任何丰富功能,例如给定单词或段落的不同样式,则可以非常容易地实现。
实际上iframe方式也很容易处理,我不买这个想法的唯一原因是这个iframe的东西意味着两个请求而不是一个。

Personally, I prefer second approach with simple text files. If you do not need any "rich" features like different styles for given word or paragraph, it could be very easy to implement. In fact iframe way is also very easy to handle, the only reason I don't buy this idea is this iframe thing which means two requests instead of just one.

顺便说一句。实际上你可以在后端加载HTML并正确显示,但你必须记住不要逃避标签:

BTW. Actually you could load HTML on the backend side and display that correctly but you have to remember not to escape the tags:

<h:outputText escape="false" value="#{someController.faq}" />

请确保最终用户无法输入此内容,因为您最终会遇到XSS漏洞。

Be sure this is not something that could be entered by end user as you would end up with XSS vulnerability.

这篇关于Java / JSF i18n长文本(术语,常见问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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