Struts2的国际化(i18n)

Struts2学习笔记
******Struts2的国际化(i18n):******
JDK国际化包:
java.util
1.ResourceBundle
2.Locale
*.一个国际化属性文件:
baseName_language_country.properties;
如:hellofile_en_US.properties;hellofile_zh_CN.properties;
代码如下:
Locale locale = locale.getDefault();
ResourceBundle bundle = ResourceBundle.getBundle("hellofile",locale);
String value = bundle.getString("hello");
String result = MessageFormat.format(value, new Object[]{"北京"});
syso(value);
以上是java国际化底层的方法。

******Struts2 JSP页面的国际化:******
1.在struts.xml里:
<constant name="struts.custom.i18n.resources" value="message"></constant>
2.配好message_en_US.properties;message_zh_CN.properties;文件
3.jsp里<s:text name="addUser"></s:text>
4.在Action类里就可以用国际化。代码如:
this.addActionError(this.getText("username.invalid"));
username.invalid就是properties里的key键。getText()方法就是得到国际化属性放到action里面。
getText(String aTextName, List args);List args是配动态值的,如{0},{1};
5.在field域里就可以用国际化。代码如:
在RegisterAction-validation.xml的<filed>标签里写上<message key="username.xml.invalid">"username.xml.invalid
</message>

******包级别提示信息******
命名:package_en_US.properties;package_zh_CN.properties;
******类级别提示信息******
命名:RegisterAction_en_US.properties;RegisterAction_zh_CN.properties;

*.在jsp页面标签里看到key就想到国际化。

*.在资原文件里用<s:i18n>标签
<s:i18n name="属性文件名称">
<s:text name="hello">
<s:param>动态传参数</s:param>
</s:text>
</s:i18n>
资原文件要放在SRC目录下。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值