Search in sources :

Example 1 with CookieLocaleResolver

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();
}
Also used : LocaleChangeInterceptor(org.springframework.web.servlet.i18n.LocaleChangeInterceptor) CookieLocaleResolver(org.springframework.web.servlet.i18n.CookieLocaleResolver) Before(org.junit.Before)

Example 2 with CookieLocaleResolver

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);
    }
}
Also used : Locale(org.orcid.jaxb.model.common_v2.Locale) CookieLocaleResolver(org.springframework.web.servlet.i18n.CookieLocaleResolver)

Aggregations

CookieLocaleResolver (org.springframework.web.servlet.i18n.CookieLocaleResolver)2 Before (org.junit.Before)1 Locale (org.orcid.jaxb.model.common_v2.Locale)1 LocaleChangeInterceptor (org.springframework.web.servlet.i18n.LocaleChangeInterceptor)1