开发者

Making JSF website multilingual

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' ?>开发者_如何学Python;
<!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?!


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 a Control wherein you overridde the reading of properties files to use UTF-8 instead. See also this article.


when working with resource bundles, consider using ResourceBundle Editor plugin for eclipse (http://sourceforge.net/projects/eclipse-rbe/).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜