Get user locale detected by i18n interceptor in action class

前端 未结 1 574
说谎
说谎 2020-12-19 18:55

I have a webapp that uses Struts 2. I use the i18n interceptor with all the default settings. I thought this interceptor worked as follow:

  1. If there is a parame
1条回答
  •  一生所求
    2020-12-19 19:19

    You shouldn't use a session key defined by the interceptor for internal usage to get an action locale.

    If a request_locale parameter is detected by the i18n interceptor the requested locale is created and put to the action context and also to the session under the key specified by the interceptor.

    If the next request to the interceptor doesn't include request_locale parameter then it gets a locale saved in the session, if not found the request locale is used.

    Again the interceptor put returned locale to the action context. So, to get a locale used by the struts tags you should use

     Locale locale = ActionContext.getContext().getLocale(); 
    

    0 讨论(0)
提交回复
热议问题