Struts2 Core Developers Guide-Localization

1.Overview
支持国际化的模块:
[list]
[*]1. the UI Tags
[*] 2. Messages and Errors from the ValidationAware interface (implemented by ActionSupport and ValidationAwareSupport)
[*] 3. Within action classes that extend ActionSupport through the getText() method
[*]2.Resource Bundle Search Order(Resouce文件搜索规则)
[*] 1. ActionClass.properties
[*] 2. BaseClass.properties (all the way to Object.properties)
[*] 3. Interface.properties (every interface and sub-interface)
[*] 4. ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
[*] 5. package.properties (of the directory where class is located and every parent directory all the way to the root directory)
[*] 6. search up the i18n message key hierarchy itself
[*] 7. global resource properties
[/list]
规则如下图

Package hierarchy

To clarify #5, while traversing the package hierarchy, Struts 2 will look for a file package.properties:

com/
acme/
package.properties
actions/
package.properties
FooAction.java
FooAction.properties

If FooAction.properties does not exist, com/acme/action/package.properties will be searched for, if not found com/acme/package.properties, if not found com/package.properties, etc.

3.Examples
[list]
[*]
<s:property value="getText('some.key')" />

可以嵌套在ui tags中
[*]
<s:text name="some.key" />

[*]

<s:i18n name="some.package.bundle" >
<s:text name="some.key" />
</s:i18n>

指定显示需要查找的resource bundle的文件.
[/list]
4.I18n Interceptor
该拦截器可以在运行过程中改变某个session对应的locale信息,和localization配合以实现internationlization.
5.Global Resources (struts.custom.i18n.resources) in struts.properties
6.由于struts2支持与action相关的resource的定义,导致可以造成会有多个重复的key的存在.
解决该问题的方法是,通过定义ActionSupport.properties in com/opensymphony/xwork2 and put it on your classpath.来实现所有action的key的统一定义.不过这样一来所有的action都必须继承自ActionSupport.
由以上启发,其实也可以自己写一个接口,当作标记接口,所有的action都实现该接口,并且在该接口的文件夹中加入interfacename.properties文件也可以解决该问题.
7.Formatting Dates and Numbers(日期和数字的格式化)
[list]
[*]struts2其实通过i10n来实现数字和日期的格式化的.
[*]定义日期或者数字显示的格式需要利用ognl表达式的特性.
[*]例子
format.time = {0,time}
format.number = {0,number,#0.0##}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,\u00A4##0.00}

[*]通过s:text标签嵌套需要转化的数字或者日期的值来实现以上数据的格式化.
[*]Localizing form data with getText代码示例如下
<s:textfield key="orderItem.price" value="%{getText('format.number',{'orderItem.price'})}" />

详细的说明请参考getText in ActionSupport代码中实际调用的方法为
textProvider.getText(String key, String[] args)
[/list]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的影城管理系统,源码+数据库+论文答辩+毕业论文+视频演示 随着现在网络的快速发展,网上管理系统也逐渐快速发展起来,网上管理模式很快融入到了许多生活之中,随之就产生了“小徐影城管理系统”,这样就让小徐影城管理系统更加方便简单。 对于本小徐影城管理系统的设计来说,系统开发主要是采用java语言技术,在整个系统的设计中应用MySQL数据库来完成数据存储,具体根据小徐影城管理系统的现状来进行开发的,具体根据现实的需求来实现小徐影城管理系统网络化的管理,各类信息有序地进行存储,进入小徐影城管理系统页面之后,方可开始操作主控界面,主要功能包括管理员:首页、个人中心、用户管理、电影类型管理、放映厅管理、电影信息管理、购票统计管理、系统管理、订单管理,用户前台;首页、电影信息、电影资讯、个人中心、后台管理、在线客服等功能。 本论文主要讲述了小徐影城管理系统开发背景,该系统它主要是对需求分析和功能需求做了介绍,并且对系统做了详细的测试和总结。具体从业务流程、数据库设计和系统结构等多方面的问题。望能利用先进的计算机技术和网络技术来改变目前的小徐影城管理系统状况,提高管理效率。 关键词:小徐影城管理系统;Spring Boot框架,MySQL数据库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值