use of org.springframework.web.servlet.i18n.CookieLocaleResolver in project spring-framework by spring-projects.
the class CookieAssertionTests method setup.
@Before
public void setup() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setCookieDomain("domain");
this.mockMvc = standaloneSetup(new SimpleController()).addInterceptors(new LocaleChangeInterceptor()).setLocaleResolver(localeResolver).defaultRequest(get("/").param("locale", "en_US")).alwaysExpect(status().isOk()).build();
}
use of org.springframework.web.servlet.i18n.CookieLocaleResolver in project ORCID-Source by ORCID.
the class AjaxAuthenticationSuccessHandlerBase method checkLocale.
// new method - persist which ever local they logged in with
private void checkLocale(HttpServletRequest request, HttpServletResponse response, String orcidId) {
Locale lastKnownLocale = profileEntityManager.retrieveLocale(orcidId);
if (lastKnownLocale != null) {
localeContextResolver.setLocale(request, response, LocaleUtils.toLocale(lastKnownLocale.value()));
} else {
// have to read the cookie directly since spring has
// populated the request locale yet
CookieLocaleResolver clr = new CookieLocaleResolver();
// must match <property name="cookieName" value="locale_v3"
// />
clr.setCookieName("locale_v3");
Locale cookieLocale = org.orcid.jaxb.model.common_v2.Locale.fromValue(clr.resolveLocale(request).toString());
// update the users preferences, so that
// send out emails in their last chosen language
profileEntityManager.updateLocale(orcidId, cookieLocale);
}
}
Aggregations