I18nInterceptor

本文介绍了一种用于动态设置用户会话中locale的拦截器,该拦截器能够通过HTTP请求参数来更改用户的语言偏好,并将其保存在会话中以供后续请求使用。此功能对于需要多语言支持的应用非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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里
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值