AdSense

網頁

2018/6/17

ZK i18n 多語系設定

ZK i18n多語系的語言設定檔預設會抓取WEB-INF目錄下的zk-label_lang_CNTY.properties檔,例如使用WEB-INF/zk-label_zh_TW.properties作為繁體中文語系的來源。

ZK會根據使用者環境的Locale來決定抓取的語系properties檔,如果沒有該語系的properties檔,則會以zk-label.properties檔做為預設。

在zul中可透過EL語法直接取得properties檔的內容。例如目前台灣繁體中文設定在zk-label_zh_TW.properites,內容如下

zk-label_zh_TW.properties

sys.login=登入
sys.logout=登出

在zul中使用EL來存取。

<zk>
<window>
   <button label="${labels.sys.login}"/>
</window>
</zk>

若在Java,例如ViewModel,則使用Labels.getLabel(String key)來取得。

System.out.println(Labels.getLabel("sys.logout")); // 印出"登出"

在Java程式中改變Locale並刷新頁面的方法如下。

@Command
public void toChinese(@ContextParam(ContextType.SESSION) Session session) {
    
    session.setAttribute(Attributes.PREFERRED_LOCALE, Locale.TRADITIONAL_CHINESE); // 修改Locale
    Executions.sendRedirect(null); // 重新載入頁面

}

參考:

沒有留言:

AdSense