org.springframework.web.servlet.i18n.CookieLocaleResolver Java Examples
The following examples show how to use
org.springframework.web.servlet.i18n.CookieLocaleResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocaleUtils.java From EasyReport with Apache License 2.0 | 6 votes |
/** * 根据当前request对象中的locale(Header的Accept属性)初始化系统国际化语言区域环境 * * @param request 当前请求对象 * @param response 当前响应对象 */ public static void setInitLocale(final HttpServletRequest request, final HttpServletResponse response) { final Locale locale = request.getLocale(); log.info("Init locale from user request,country:{},lang:{}", locale.getCountry(), locale.toLanguageTag()); if (localeResolver instanceof CookieLocaleResolver) { final CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver)localeResolver; final Cookie cookie = WebUtils.getCookie(request, cookieLocaleResolver.getCookieName()); if (cookie == null) { setLocale(locale.toLanguageTag(), request, response); } } if (localeResolver instanceof SessionLocaleResolver) { final Locale sessionLocale = (Locale)WebUtils.getRequiredSessionAttribute( request, SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME); if (sessionLocale == null) { setLocale(locale.toLanguageTag(), request, response); } } }
Example #2
Source File: WebContext.java From MaxKey with Apache License 2.0 | 6 votes |
/** * get locale from Spring Resolver,if locale is null,get locale from Spring. * SessionLocaleResolver this is from internationalization * * @return Locale */ public static Locale getLocale() { Locale locale = null; try { CookieLocaleResolver cookieLocaleResolver = (CookieLocaleResolver) getBean("localeResolver"); locale = cookieLocaleResolver.resolveLocale(getRequest()); } catch (Exception e) { LogFactory.getLog(WebContext.class).debug("getLocale() error . "); e.printStackTrace(); locale = RequestContextUtils.getLocale(getRequest()); } return locale; }
Example #3
Source File: WebMvcConfig.java From scaffold-cloud with MIT License | 5 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver slr = new CookieLocaleResolver(); slr.setDefaultLocale(Locale.CHINA); slr.setCookieMaxAge(LOCAL_COOKIE_TIME); return slr; }
Example #4
Source File: CookieAssertionTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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(); }
Example #5
Source File: BaseApplicationConfig.java From spring-boot-doma2-sample with Apache License 2.0 | 5 votes |
@Bean public LocaleResolver localeResolver() { // Cookieに言語を保存する val resolver = new CookieLocaleResolver(); resolver.setCookieName("lang"); return resolver; }
Example #6
Source File: I18nApplication.java From Spring-Boot-I18n-Pro with MIT License | 5 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver slr = new CookieLocaleResolver(); slr.setDefaultLocale(Locale.CHINA); slr.setCookieMaxAge(3600); slr.setCookieName("Language"); return slr; }
Example #7
Source File: WebAppConfig.java From SA47 with The Unlicense | 5 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(StringUtils .parseLocaleString("en")); return cookieLocaleResolver; }
Example #8
Source File: WebAppConfig.java From SA47 with The Unlicense | 5 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(StringUtils .parseLocaleString("en")); return cookieLocaleResolver; }
Example #9
Source File: WebConfig.java From Spring with Apache License 2.0 | 5 votes |
/** * Cookie configuration for the internationalization settings */ @Bean CookieLocaleResolver localeResolver() { final CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH); cookieLocaleResolver.setCookieMaxAge(3600); cookieLocaleResolver.setCookieName("locale"); return cookieLocaleResolver; }
Example #10
Source File: WebConfig.java From Spring with Apache License 2.0 | 5 votes |
@Bean CookieLocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH); cookieLocaleResolver.setCookieMaxAge(3600); cookieLocaleResolver.setCookieName("locale"); return cookieLocaleResolver; }
Example #11
Source File: WebConfig.java From Spring with Apache License 2.0 | 5 votes |
@Bean CookieLocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH); cookieLocaleResolver.setCookieMaxAge(3600); cookieLocaleResolver.setCookieName("locale"); return cookieLocaleResolver; }
Example #12
Source File: WebConfig.java From Spring with Apache License 2.0 | 5 votes |
@Bean CookieLocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH); cookieLocaleResolver.setCookieMaxAge(3600); cookieLocaleResolver.setCookieName("locale"); return cookieLocaleResolver; }
Example #13
Source File: CookieAssertionTests.java From java-technology-stack with MIT License | 5 votes |
@Before public void setup() { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setCookieDomain("domain"); localeResolver.setCookieHttpOnly(true); this.mockMvc = standaloneSetup(new SimpleController()) .addInterceptors(new LocaleChangeInterceptor()) .setLocaleResolver(localeResolver) .defaultRequest(get("/").param("locale", "en_US")) .alwaysExpect(status().isOk()) .build(); }
Example #14
Source File: CookieAssertionTests.java From spring-analysis-note with MIT License | 5 votes |
@Before public void setup() { CookieLocaleResolver localeResolver = new CookieLocaleResolver(); localeResolver.setCookieDomain("domain"); localeResolver.setCookieHttpOnly(true); this.mockMvc = standaloneSetup(new SimpleController()) .addInterceptors(new LocaleChangeInterceptor()) .setLocaleResolver(localeResolver) .defaultRequest(get("/").param("locale", "en_US")) .alwaysExpect(status().isOk()) .build(); }
Example #15
Source File: RequestUtil.java From stategen with GNU Affero General Public License v3.0 | 4 votes |
public static Locale getLocale(){ return (Locale) getRequest().getAttribute(CookieLocaleResolver.LOCALE_REQUEST_ATTRIBUTE_NAME); }
Example #16
Source File: MvcConfig.java From training with MIT License | 4 votes |
@Bean public CookieLocaleResolver localeResolver() { return new CookieLocaleResolver(); }
Example #17
Source File: I18NConfiguration.java From EasyEE with MIT License | 4 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); return cookieLocaleResolver; }
Example #18
Source File: I18NConfiguration.java From EasyEE with MIT License | 4 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); return cookieLocaleResolver; }
Example #19
Source File: MvcConfig.java From tutorials with MIT License | 4 votes |
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver cookieLocaleResolver = new CookieLocaleResolver(); cookieLocaleResolver.setDefaultLocale(Locale.ENGLISH); return cookieLocaleResolver; }