热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Tapestry之国际化的实现TWO

前面按照别人的想法做了一个,这次按照自己的想法自己做了一个。tml如下

前面按照别人的想法做了一个,这次按照自己的想法自己做了一个。

tml如下

<t:form t:id&#61;"locale"><t:loop source&#61;"LocalesSource" value&#61;"selectedLocale" formState&#61;"ITERATION"><t:test server&#61;"currentLocale" client&#61;"${selectedLocale.locale.language}"><img src&#61;"${selectedLocale.asset}" class&#61;"currentFlag" /><p:else><a t:type&#61;"actionLink" t:id&#61;"changeLocale" context&#61;"${selectedLocale.locale.language}" href&#61;"#"><img src&#61;"${selectedLocale.asset}" class&#61;"notCurrentFlag" />a>p:else>t:test>t:loop><div class&#61;"message">${message:greeting_message}div>t:form>

java如下&#xff1a;

public class LocaleSwitcher2
{&#64;Inject&#64;Property&#64;Symbol(SymbolConstants.SUPPORTED_LOCALES)
private String locales;&#64;Injectprivate PersistentLocale persistentLocale;&#64;Propertyprivate LocaleBean selectedLocale;&#64;Inject&#64;Path("context:images/country_zh.png")private Asset assetZh;&#64;Inject&#64;Path("context:images/country_it.png")private Asset assetIt;&#64;Inject&#64;Path("context:images/country_ja.png")private Asset assetJa;&#64;Inject&#64;Path("context:images/country_en.png")private Asset assetEn;public List getLocalesSource(){String[] countrys &#61; locales.split(",");List localeList &#61; new ArrayList();for (String country : countrys) {LocaleBean addBean &#61; new LocaleBean();addBean.setLocale(new Locale(country));if (country.equalsIgnoreCase("en")) {addBean.setAsset(assetEn);} else if (country.equalsIgnoreCase("ja")) {addBean.setAsset(assetJa);} else if (country.equalsIgnoreCase("zh")) {addBean.setAsset(assetZh);} else if (country.equalsIgnoreCase("it")) {addBean.setAsset(assetIt);} else {addBean.setAsset(assetEn);}localeList.add(addBean);}return localeList;}public ValueEncoder getLocaleEncoder(){return new ValueEncoder() {public String toClient(Locale locale){return locale.getLanguage();}public Locale toValue(String language){return new Locale(language);}};}void onActionFromChangeLocale(String language){persistentLocale.set(new Locale(language));}public String getCurrentLocale(){return persistentLocale.get().getLanguage();}}

public class LocaleBean
{
private Locale locale;private Asset asset;public Locale getLocale(){return locale;}public void setLocale(Locale locale){this.locale &#61; locale;}public Asset getAsset(){return asset;}public void setAsset(Asset asset){this.asset &#61; asset;}}

public class Test extends AbstractConditional
{&#64;Parameter(required
&#61; true)private String client;&#64;Parameter(required &#61; true)private String server;&#64;Parameterprivate boolean negate;&#64;Overrideprotected boolean test(){return client.equalsIgnoreCase(server);}}

效果图&#xff1a;

转:https://www.cnblogs.com/voctrals/archive/2013/04/02/2995531.html



推荐阅读
author-avatar
461067805QQ
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有