Locale not changing in struts 2

516 Views Asked by At

Since struts 2's default I18nInterceptor fails when the system is distributed, I have implemented a cookie based solution. I added an interceptor that looks for the request_locale param and sets the cookie. And it also looks for the cookie. If either the request_locale param comes or the cookie is present, I set the new Locale. This interceptor is called after the struts's I18N interceptor. But after setting, I don't see the language changing. Below is the intercept method of my interceptor.

public String intercept(ActionInvocation invocation) throws Exception {

    HttpServletRequest request = ServletActionContext.getRequest();
    String localeStr = request.getParameter("request_locale");
    if (localeStr != null) {
        setLocaleInCookie(localeStr);
    }
    if (localeStr == null) {
        localeStr = getLocaleFromCookie();
    }

    if (localeStr != null) {
        ActionContext.getContext().setLocale(new Locale(localeStr));
    }

    return invocation.invoke();
}

I would like to know If I am doing is right. Is there any other solution or workaround for this?

0

There are 0 best solutions below