Tapestry4Localization本地化/国际化

Tapestry4Localization本地化/国际化
1、方法1 — 使用Tapestry

1)Home.html
<span jwcid=”@Insert” value=”message:required”/> //使用message前缀

或者使用ognl:messages

<span jwcid=”@Insert” value=”ognl:messages.format(‘required’, ‘第{0}个元素’,’第{1}个元素’)”/>

不要使用
<span jwcid=”@Insert” value=”ognl:getMessage(‘required’)”/>
因为getMessage方法在T4中被@deprecated

—–the key ‘title’—- will be first find in Home_zh.properties or Home.properties

if in Home.properties can not be founded

it will find WEB-INF/myapp.properties,
The specification may also have a message catalog; for instance,
for WEB-INF/myapp.application,
the files would be named WEB-INF/myapp.properties,
etc. Again, the name of the file is based on the servlet name (“myapp”).

2)
myapp_zh.properties
required=u8bf7u8f93u5165{0}u7684u503c{1}

3)
Home_zh.properties
required=u8bf7u8f93u5165{0}u7684u503c{1}

2、方法2 –使用spring的MessageSource
1)利用spring加载messges_*local.properties
 <bean id=”messageSource”>
  <!–<property name=”basename” value=”classpath:messages”/>–>
   <property name=”basenames”>
      <list>
        <value>classpath:messages</value>
      </list>
    </property> 
 </bean>
把messageSource注入到Tapestry Components/Pages中

2)BasePage.java

import org.springframework.context.MessageSource;
//need inject //or direct impl it;
public abstract BasePage extends org.apache.tapestry.html.BasePage{

 public abstract MessageSource getMessageSource();

}
3)HomePage.java extends BasePage.java

4)Home.page
  <inject property=”messageSource” object=”spring:messageSource” />
5)Home.html

<span jwcid=”@Insert” value=”ognl:messageSource.getMessage(‘required’,new java.lang.Object [] {‘Login’,’!’}, ‘Default’, null)”/>

6)messges_zh.properties
required=u8bf7u8f93u5165{0}u7684u503c{1}
——————————————————————
7)或者再封装以下
public abstract BasePage extends org.apache.tapestry.html.BasePage{
 public abstract MessageSource getMessageSource();
 public String getCustomMessage(java.lang.String arg0,java.lang.Object[] arg1,java.lang.String arg2,java.util.Locale arg3){
  return this.getMessageSource().getMessage(arg0,arg1,arg2,arg3);
 }
}
then in the Home.html

<span jwcid=”@Insert” value=”ognl:getCustomMessage(‘required’,new java.lang.Object [] {‘Login’,’!’}, ‘Default’, null)”/>

原创文章,转载请注明: 转载自海波无痕

本文链接地址: Tapestry4Localization本地化/国际化

文章的脚注信息由WordPress的wp-posturl插件自动生成

此条目发表在javaee分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论链接可以 移除 nofollow.