Friday, June 13, 2008

JSF Internnationalization

In faces-config.xml
Let's say your browser Language Preference is "zh-cn, en-us", it will look up properties files in the sequece below

If the language is non-Latin 1(ISO-8859-1) and non-Unicode, you need convert the properties file by native2ascii. Here is a sample of how to use native2ascii
native2ascii -encoding GBK messages_zh-cn.txt

Set locale in faces-config.xml

Set locale property of in the page
<f:view locale="zh-cn">
<f:loadBundle basename="messages" var="msgs"/>
Or set locale property with the value of a variable, which could come from cookie, database or whatever...
<f:view locale="#{user.locale}">
<f:loadBundle basename="messages" var="msgs"/>

To refer to the message in page, see the sample below
<%@ taglib uri="" prefix="f" %>
<%@ taglib uri="" prefix="h" %>
<%@page contentType="text/html;charset=UTF-8"%>

<f:loadBundle basename="messages" var="msgs"/>

<title><h:outputText value="#{msgs.titleText}"/></title>

<h3><h:outputText value="#{msgs.hintText}"/></h3>
<h:outputText value="#{msgs.nameText}"/>:
<h:inputText value="#{}"/><p>
<h:outputText value="#{msgs.passText}"/>:
<h:inputSecret value="#{user.password}"/><p>
<h:commandButton value="#{msgs.commandText}"



No comments:

Post a Comment