全局资源文件
可以在struts.properties中配置全局资源文件,示例如下:
- struts.custom.i18n.resources = application
查找顺序
struts按照如下顺序查找资源文件
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
访问资源
有三种方式访问资源文件
使用getText
- <s:property value="getText('some.key')" />
使用text标记
- <-- Fourth Example -->
- <s:text name="some.key" />
- <-- Fifth Example -->
- <s:text name="some.invalid.key" >
- The Default Message That Will Be Displayed
- </s:text>
使用I18n标记
- <s:i18n name="some.package.bundle" >
- <s:text name="some.key" />
- </s:i18n>
I18n Interceptor
此拦截器的主要功能是支持动态改变会话的Local。实现原理是会拦截每一个请求参数,如果请求参数包含request_locale键(可配置),拦截 器会将其值解析出Local对象储存到会话的属性,缺省健值为WW_TRANS_I18N_LOCALE(可配置),然后会将此Local传递给当前 Action实例。
以便Action实现的LocalProvider和TextProvider接口立即使用此Local获取资源文件。