Portal module: How to change the language of the website

Hi,
We’re implementing a multilingual website through a Cuba-Platform Portal module.

HTML templates use Thymeleaf to get literals from messagge packs (property files).

We don’t know how to intercept the user event for changing the language and how to change de HTTP session and the AppContext for making the language change effective.

We implemented unsuccessfully following code for try to change the language:

@RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model, HttpServletRequest httpServletRequest) {
        HttpSession httpSession = httpServletRequest.getSession();
        Connection connection = (Connection)httpSession.getAttribute("cuba_Connection");

        Locale locale = new Locale("es");
        PortalSession portalSession = PortalSessionProvider.getUserSession();

        UserSession userSession= PortalSessionProvider.getUserSession();
        userSession.setLocale(locale);
        portalSession.setLocale(locale);
        httpSession.setAttribute("cuba_Connection", connection);
        httpServletRequest.setAttribute("cuba_Connection", connection);
        PortalSecurityContext portalSecurityContext = new PortalSecurityContext(portalSession);
        AppContext.setSecurityContext(portalSecurityContext);
        return "index";
    }

Debugging above code, session locale setting is set to “es” language but it isn’t persistent because HTML pages are shown in default user’s language.

Any idea would be very appreciated.

Regards,

Xavier Lorente