I18nInterceptor

An interceptor that handles setting the locale specified in a session as the locale for the current action request. In addition, this interceptor will look for a specific HTTP request parameter and set the locale to whatever value is provided. This means that this interceptor can be used to allow for your application to dynamically change the locale for the user's session. This is very useful for applications that require multi-lingual support and want the user to be able to set his or her language preference at any point. The locale parameter is removed during the execution of this interceptor, ensuring that properties aren't set on an action (such as request_locale) that have no typical corresponding setter in your action.

For example, using the default parameter name, a request to foo.action?request_locale=en_US, then the locale for US English is saved in the user's session and will be used for all future requests.

Interceptor parameters:

  • parameterName (optional) - the name of the HTTP request parameter that dictates the locale to switch to and save in the session. By default this isrequest_locale
  • attributeName (optional) - the name of the session key to store the selected locale. By default this is WW_TRANS_I18N_LOCALE

Extending the interceptor:

There are no known extensions points for this interceptor.

Example code:

 
 <action name="someAction" class="com.examples.SomeAction">
     <interceptor-ref name="i18n"/>
     <interceptor-ref name="basicStack"/>
     <result name="success">good_result.ftl</result>
 </action>

该拦截器的作用是让用户可以动态的改变locale

请求的时候加 request_locale=zh_CN
而且存在session里

猜你喜欢

转载自yaozuodaoforfly.iteye.com/blog/2051517