使 JSF 网站多语言化
尝试使 JSF Web 应用程序成为多语言的。为此,用
标签覆盖所有 HTML 代码:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns= ... >
<f:view locale="#{actionsContainer.languageDetails.locale}">
<head>
<meta charset="utf-8" />
<f:loadBundle basename="messages.Messages" var="key" />
</head>
<body>
<h:outputText value="#{key.myText}" />
</body>
</f:view>
</html>
比在资源中我有几个“Messages.properties”文件,其中包含对某些语言的翻译:
- Messages_en.properties
- Messages_es.properties
- Messages .properties // 默认
该文件“Messages_es.properties”的示例内容是:
myText=España
假设我的语言环境是“es”,然后西班牙语翻译文件加载它的值并呈现到屏幕上。但是,特殊字符(例如“ñ”)在浏览器输出中无法正确显示。我得到的不是特殊的西班牙语字母,而是类似“ó”的东西。
我尝试使用 UTF-8 编码保存 .properties 文件,不带 BOM。并且输出已更改为类似“”的内容。
所以问题是如何在输出中获得这个特殊的任何语言字母?!
Trying to make JSF web application multilingual. For that purpose cover all the HTML code with <f:view>
tags:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns= ... >
<f:view locale="#{actionsContainer.languageDetails.locale}">
<head>
<meta charset="utf-8" />
<f:loadBundle basename="messages.Messages" var="key" />
</head>
<body>
<h:outputText value="#{key.myText}" />
</body>
</f:view>
</html>
Than in resources I have several 'Messages.properties' files with a translations to some languages:
- Messages_en.properties
- Messages_es.properties
- Messages.properties // default
The sample content of this files 'Messages_es.properties' is:
myText=España
Let's take, my locale is "es", and than Spanish translation file loads it's value and renders to the screen. However, the special characters (eg 'ñ') doesn't display properly in a browser output. Instead of special Spanish letters I am getting something like this "ó".
I have tried to save .properties file with UTF-8 encoding, without BOM. And the output has been changed to something like this "".
And so the question is how do I get this special any language letters in an output?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,属性文件使用 ISO-8859-1 编码读取。您需要 JDK native2ascii 工具将 UTF-8 属性文件转换为 ISO-8859-1 属性文件,然后使用它们。
然而,在 JSF 中,您还可以使用
Control
指定自定义ResourceBundle
,其中您可以覆盖属性文件的读取以使用 UTF-8。另请参阅本文。Properties files are by default read using the ISO-8859-1 encoding. You need the JDK native2ascii tool to convert UTF-8 properties files to ISO-8859-1 properties files and then use those instead.
In JSF you can however also specify a custom
ResourceBundle
with aControl
wherein you overridde the reading of properties files to use UTF-8 instead. See also this article.使用资源包时,请考虑使用 eclipse 的 ResourceBundle Editor 插件 (http://sourceforge.net/projects/eclipse-rbe/)。
when working with resource bundles, consider using ResourceBundle Editor plugin for eclipse (http://sourceforge.net/projects/eclipse-rbe/).