List of usage examples for org.springframework.web.servlet.i18n CookieLocaleResolver CookieLocaleResolver
public CookieLocaleResolver()
From source file:pl.java.scalatech.config.I18nConfig.java
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver clr = new CookieLocaleResolver(); log.info("++++ language : ", env.getProperty("language")); clr.setDefaultLocale(Locale.forLanguageTag(env.getProperty("language"))); return clr;//w w w . java2 s. c om }
From source file:com.tianjunwei.interceptor.LanguageCookieInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String language = request.getParameter("language"); if (language != null && language.equals("zh")) { Locale locale = new Locale("zh", "CN"); (new CookieLocaleResolver()).setLocale(request, response, locale); request.setAttribute("language", language); } else if (language != null && language.equals("en")) { Locale locale = new Locale("en", "US"); (new CookieLocaleResolver()).setLocale(request, response, locale); request.setAttribute("language", language); } else {/*from w w w. ja v a2s . c om*/ (new CookieLocaleResolver()).setLocale(request, response, LocaleContextHolder.getLocale()); language = LocaleContextHolder.getLocale().getLanguage(); request.setAttribute("language", language); } return true; }
From source file:com.mtt.myapp.home.controller.HomeControllerTest.java
@Test public void testHome() { MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); CookieLocaleResolver localeResolver = new CookieLocaleResolver(); req.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, localeResolver); User testUser2 = getTestUser();//from w w w. j a v a 2s .co m testUser2.setUserLanguage("EN"); ModelMap model = new ModelMap(); String viewName = homeController.home(testUser2, null, null, model, res, req); assertThat(viewName).isEqualTo("index"); User testUserError = Mockito.spy(testUser2); Mockito.when(testUserError.getRole()).thenReturn(Role.SYSTEM_USER); viewName = homeController.home(testUserError, "Test Error message!", null, model, res, req); assertThat(viewName).isEqualTo("login"); }
From source file:org.ngrinder.home.controller.HomeControllerTest.java
@Test public void testHome() { MockHttpServletResponse res = new MockHttpServletResponse(); MockHttpServletRequest req = new MockHttpServletRequest(); CookieLocaleResolver localeResolver = new CookieLocaleResolver(); req.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, localeResolver); User testUser2 = getTestUser();//from w w w .j a va 2 s .c om testUser2.setUserLanguage("EN"); ModelMap model = new ModelMap(); String viewName = homeController.home(testUser2, null, null, model, res, req); assertThat(viewName, is("index")); User testUserError = Mockito.spy(testUser2); Mockito.when(testUserError.getRole()).thenReturn(Role.SYSTEM_USER); viewName = homeController.home(testUserError, "Test Error message!", null, model, res, req); assertThat(viewName, is("login")); }
From source file:cn.edu.zjnu.acm.judge.config.LocaleConfiguration.java
@Bean(name = "localeResolver") public LocaleResolver localeResolver(ServletContext container, LocaleFactory localeFactory) { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setCookieName("locale"); localeResolver.setCookieMaxAge(15 * 24 * 60 * 60); localeResolver.setCookiePath(getCookiePath(container)); return new FilterLocaleResolver(localeResolver, Locale.SIMPLIFIED_CHINESE, locale -> localeFactory.getAllLanguages().contains(locale.getLanguage())); }
From source file:com.nkapps.billing.configs.MvcConfig.java
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver clr = new CookieLocaleResolver(); clr.setDefaultLocale(new Locale("ru")); return clr;/*from w w w . j a va 2 s. co m*/ }
From source file:com.uimirror.auth.conf.DispatcherConfig.java
@Bean(name = "localeResolver") public LocaleResolver sessionLocaleResolver() { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setDefaultLocale(new Locale("en")); localeResolver.setCookieName("uim_locale"); localeResolver.setCookieMaxAge(36000); return localeResolver; }
From source file:rashjz.info.com.az.config.SpringWebConfig.java
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver resolver = new CookieLocaleResolver(); resolver.setDefaultLocale(new Locale("en")); resolver.setCookieName("myLocaleCookie"); resolver.setCookieMaxAge(4800);//from w w w.j a v a 2 s .c om return resolver; }
From source file:com.alehuo.wepas2016projekti.configuration.DevelopmentConfiguration.java
/** * Lokalisaatioevsteen asetus/*from w w w. j a va 2 s . c o m*/ * * Oletusarvoinen lokalisaatio: fi_FI * * @return */ @Bean public CookieLocaleResolver localeResolver() { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); Locale finnishLocale = new Locale.Builder().setLanguage("fi").setRegion("FI").build(); localeResolver.setDefaultLocale(finnishLocale); localeResolver.setCookieName("locale"); //Evste vanhenee tunnissa localeResolver.setCookieMaxAge(3600); return localeResolver; }
From source file:com.redhat.rhtracking.config.WebConfig.java
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(StringUtils.parseLocaleString("en")); return cookieLocaleResolver; }