jsf學(xué)習(xí)二(國際化)
國際化(I18N)就是設(shè)計(jì)軟件應(yīng)用,在不改變它們程序邏輯的前提下支持各種語言和區(qū)域
本地化(L10N)就是設(shè)計(jì)軟件應(yīng)用支持特定地區(qū)
由于數(shù)據(jù)經(jīng)過本地化,因此同一應(yīng)用程序能在全世界使用
當(dāng)增加一種新的語言時(shí),應(yīng)用不需要重新編譯
在顯示和文化相關(guān)的數(shù)據(jù)(例如日期或貨幣)時(shí),格式應(yīng)用遵循用戶的語言和區(qū)域
文本內(nèi)容(如狀態(tài)消息和組件標(biāo)簽)不是硬編碼到應(yīng)用程序中,而通常是從文本文件中動(dòng)態(tài)提取的
國際化的步驟
創(chuàng)建一個(gè)包含應(yīng)用程序默認(rèn)語言的鍵/值對的文件
?文件命名格式:
Filename_languagecode_CountryCode.properties
例如:
ApplicationResources_zh_CN.properties
JSF 提供 <f:loadBundle> 標(biāo)簽以加載資源包
此標(biāo)簽具有兩個(gè)屬性:basename 和 var
basename 指定要加載的 properties 文件的名稱
var屬性用來為該properties文件起一個(gè)別名
如
<
f:view
>
????
<
f:loadBundle?
basename
="message"
?vars
="msg"
?
/>
….
????
<
h:outputLabel?
value
="#{msg.first}"
?
/>
</
f:view
>
資源文件編譯
native2ascii –encoding gb2312 messagesCN.properties? messages_zh_CN.properties
例
一個(gè)登陸實(shí)現(xiàn)國際化
后臺(tái)檢查登陸是否正確
??public?String?Login(string?userName,string?passWord)?{
??????if?(?UserName=="blog")?{
??????????return?"success";
??????}?else?{
?????FacesContext?context?=?FacesContext.getCurrentInstance();
?????ResourceBundle?bundle?=?ResourceBundle.getBundle("messages",?context.getViewRoot().getLocale());
??????String?msg?=?"";
?????if?(?username==""?||?passWord=="")
?????????msg?=?bundle.getString("username_isnull");
??
????context.addMessage?(null,?new?FacesMessage(msg));
????return?"shibai";?

?}
??}
前臺(tái)
<f:loadBundle?basename="message"?var="msg"/>
<html>
?<f:view>
?????<h:form>
??????<h:outputText?value="#{msg.login}"/>?<br/>
??????<h:messages?style="color:?blue"/><br/>
??????<h:inputText?id="username"?value="#{UserBean.userName}"
???????????????????????????required="true">
???????????<f:validateLongRange?minimum="0"?maximum="20"/>
??????</h:inputText><br/><br/>


????<h:outputText?value="#{msg.password}"/>?<br/>
??????<h:messages?style="color:?blue"/><br/>
??????<h:inputText?id="pssword"?value="#{UserBean.passWord}"
???????????????????????????required="true">
???????????<f:validateLongRange?minimum="0"?maximum="16"/>
??????</h:inputText><br/><br/>


?????<h:commandButton?value="#{msg.button_title}"?
??????????????????????????????????????action="#{userBean.Login}"/>
???</h:form>
?</f:view>
</html>
本地化(L10N)就是設(shè)計(jì)軟件應(yīng)用支持特定地區(qū)
由于數(shù)據(jù)經(jīng)過本地化,因此同一應(yīng)用程序能在全世界使用
當(dāng)增加一種新的語言時(shí),應(yīng)用不需要重新編譯
在顯示和文化相關(guān)的數(shù)據(jù)(例如日期或貨幣)時(shí),格式應(yīng)用遵循用戶的語言和區(qū)域
文本內(nèi)容(如狀態(tài)消息和組件標(biāo)簽)不是硬編碼到應(yīng)用程序中,而通常是從文本文件中動(dòng)態(tài)提取的
國際化的步驟
創(chuàng)建一個(gè)包含應(yīng)用程序默認(rèn)語言的鍵/值對的文件
?文件命名格式:
Filename_languagecode_CountryCode.properties
例如:
ApplicationResources_zh_CN.properties
JSF 提供 <f:loadBundle> 標(biāo)簽以加載資源包
此標(biāo)簽具有兩個(gè)屬性:basename 和 var
basename 指定要加載的 properties 文件的名稱
var屬性用來為該properties文件起一個(gè)別名
如





資源文件編譯
native2ascii –encoding gb2312 messagesCN.properties? messages_zh_CN.properties
例
一個(gè)登陸實(shí)現(xiàn)國際化
后臺(tái)檢查登陸是否正確















前臺(tái)

























posted on 2006-08-20 10:43 record java and net 閱讀(2370) 評論(1) 編輯 收藏 所屬分類: jsf學(xué)習(xí)