i18N国际化

2019-04-04  本文已影响0人  盗生一

===========iI8N的编写

utf-8:支持所有语言
编写中文: 随便起名_zh_CN.properties
1.必须通过临时文件 转为 随便起名_zh_CN.properties
native2ascii 临时文件名 随便起名_zh_CN.properties
2.通过插件 open with-->properties editor 直接编写
编写英文: 随便起名_en_US.properties

==========I18N的使用

1.写多个配置文件进行切换--通过Local.US/CHINA等
2.default/web.xml中也配置下
3.struts资源文件级别:
action级别:在同一个位置,以action(全名)为前缀------只有一个action可以使用
package级别:前缀必须是package-----------只有本包可以使用
app(整个应用(建在src下))级别:前缀可以任意取-----整个应用都可以使用
使用需要在struts.xml配置
<constant name="struts.custom.i18n.resources" value="前缀名"></constant>

-----------获取值

1.action-----getText(String key)
2.struts标签的<s:text name="key">

==========i18n处理资源参数

welcome.msg=welcome:{0}---配置
----设置占位符的值
<s:text name="welcome.msg">------得到welcome:{0}
<s:param value="username"></s:param>---设置{0}
</s:text>

========动态语言切换(在地址栏传递参数request_locale(必须这种形式)=en_US过去strut会自动解析):

<action name="lang" class="com.bjsxt.bbs2009.action.LangAction">
<result>/admin/Login-input.jsp</result>
</action>
<a href="admin/lang?request_locale=en_US">en</a>
<a href="admin/lang?request_locale=zh_CN">cn</a>

上一篇下一篇

猜你喜欢

热点阅读