org.springframework.web.servlet.i18n.LocaleChangeInterceptor Java Examples
The following examples show how to use
org.springframework.web.servlet.i18n.LocaleChangeInterceptor.
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: I18nConfig.java From springboot-learn with MIT License | 6 votes |
/** * Cookie方式 */ // @Bean // public LocaleResolver localeResolver2() { // CookieLocaleResolver clr = new CookieLocaleResolver(); // clr.setCookieName("localeCookie"); // //设置默认区域 // clr.setDefaultLocale(Locale.US); // //设置cookie有效期. // clr.setCookieMaxAge(3600); // return clr; // } @Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); //对请求页面路径中的参数lang进行拦截 lci.setParamName("lang"); return lci; }
Example #2
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testBeanDecoration() throws Exception { loadBeanDefinitions("mvc-config-bean-decoration.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor); assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor); LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1]; assertEquals("lang", interceptor.getParamName()); ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2]; assertEquals("style", interceptor2.getParamName()); }
Example #3
Source File: MvcNamespaceTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testBeanDecoration() throws Exception { loadBeanDefinitions("mvc-config-bean-decoration.xml", 16); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor); assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor); LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1]; assertEquals("lang", interceptor.getParamName()); ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2]; assertEquals("style", interceptor2.getParamName()); }
Example #4
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testBeanDecoration() throws Exception { loadBeanDefinitions("mvc-config-bean-decoration.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor); assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor); LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1]; assertEquals("lang", interceptor.getParamName()); ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2]; assertEquals("style", interceptor2.getParamName()); }
Example #5
Source File: I18nConfig.java From fw-spring-cloud with Apache License 2.0 | 6 votes |
/** * cookie区域解析器 * @return */ // @Bean // public LocaleResolver localeResolver() { // CookieLocaleResolver slr = new CookieLocaleResolver(); // //设置默认区域, // slr.setDefaultLocale(Locale.CHINA); // slr.setCookieMaxAge(3600);//设置cookie有效期. // return slr; // } @Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 设置请求地址的参数,默认为:locale // lci.setParamName(LocaleChangeInterceptor.DEFAULT_PARAM_NAME); return lci; }
Example #6
Source File: WebMvcAutoConfiguration.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 国际化参数拦截器 * * @return LocaleChangeInterceptor */ @Bean public LocaleChangeInterceptor localeChangeInterceptor() { final LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); lci.setParamName("lang"); return lci; }
Example #7
Source File: WebAppConfig.java From SA47 with The Unlicense | 5 votes |
@Override public void addInterceptors(InterceptorRegistry registry) { LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("lang"); registry.addInterceptor(localeChangeInterceptor); }
Example #8
Source File: I18nConfig.java From ruoyiplus with MIT License | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #9
Source File: I18nConfig.java From Milkomeda with MIT License | 5 votes |
@Autowired public void configRequestMappingHandlerMapping(RequestMappingHandlerMapping requestMappingHandlerMapping) { // 使用内置拦截器 final LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName(i18nProperties.getQuery()); SpringMvcPolyfill.addDynamicInterceptor(localeChangeInterceptor, Ordered.HIGHEST_PRECEDENCE + 10, Collections.singletonList("/**"), null, requestMappingHandlerMapping); }
Example #10
Source File: InterceptorConfiguration.java From EasyEE with MIT License | 5 votes |
/** * Interceptors */ @Override public void addInterceptors(InterceptorRegistry registry) { // Log HandlerInterceptor LogInterceptor logInterceptor=new LogInterceptor(); logInterceptor.setSysLogService(sysLogService); // 手动注入 registry.addInterceptor(logInterceptor).addPathPatterns("/**"); // I18N HandlerInterceptor LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("lang"); registry.addInterceptor(localeChangeInterceptor).addPathPatterns("/**"); super.addInterceptors(registry); }
Example #11
Source File: LocaleConfig.java From SuperBoot with MIT License | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #12
Source File: BaseApplicationConfig.java From spring-boot-doma2-sample with Apache License 2.0 | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { // langパラメータでロケールを切り替える val interceptor = new LocaleChangeInterceptor(); interceptor.setParamName("lang"); return interceptor; }
Example #13
Source File: DispatcherServletConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override protected void addInterceptors(InterceptorRegistry registry) { LOGGER.debug("Configuring localeChangeInterceptor"); LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }
Example #14
Source File: WebAppConfig.java From SA47 with The Unlicense | 5 votes |
@Override public void addInterceptors(InterceptorRegistry registry) { LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("lang"); registry.addInterceptor(localeChangeInterceptor); }
Example #15
Source File: LocaleConfig.java From wolf with MIT License | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #16
Source File: MvcNamespaceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testInterceptors() throws Exception { loadBeanDefinitions("mvc-config-interceptors.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); request.setRequestURI("/accounts/12345"); request.addParameter("locale", "en"); request.addParameter("theme", "green"); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(4, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor); assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor); assertTrue(chain.getInterceptors()[3] instanceof UserRoleAuthorizationInterceptor); request.setRequestURI("/admin/users"); chain = mapping.getHandler(request); assertEquals(2, chain.getInterceptors().length); request.setRequestURI("/logged/accounts/12345"); chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); request.setRequestURI("/foo/logged"); chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); }
Example #17
Source File: LocaleConfig.java From springBoot with MIT License | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #18
Source File: WebAppConfigurer.java From ShadowSocks-Share with Apache License 2.0 | 5 votes |
@Override public void addInterceptors(InterceptorRegistry registry) { // 添加 计数 拦截器 registry.addInterceptor(new Interceptor(countSerivce)).addPathPatterns("/**").excludePathPatterns("/webjars/**", "/css/**", "/images/**", "/js/**", "/favicon.ico", "/count"); // 本地化拦截器 LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor).addPathPatterns("/**"); }
Example #19
Source File: DispatcherServletConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override protected void addInterceptors(InterceptorRegistry registry) { LOGGER.debug("Configuring localeChangeInterceptor"); LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }
Example #20
Source File: WebMvcConfig.java From FlyCms with MIT License | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #21
Source File: WebConfig.java From auth-server with Apache License 2.0 | 5 votes |
/** * <p> * Localization interceptors. * </p> */ @Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); lci.setParamName("lang"); return lci; }
Example #22
Source File: I18nConfig.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #23
Source File: I18nConfig.java From RuoYi with Apache License 2.0 | 5 votes |
@Bean public LocaleChangeInterceptor localeChangeInterceptor() { LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); // 参数名 lci.setParamName("lang"); return lci; }
Example #24
Source File: DispatcherServletConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override protected void addInterceptors(InterceptorRegistry registry) { LOGGER.debug("Configuring localeChangeInterceptor"); LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }
Example #25
Source File: MvcNamespaceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testInterceptors() throws Exception { loadBeanDefinitions("mvc-config-interceptors.xml"); RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class); assertNotNull(mapping); mapping.setDefaultHandler(handlerMethod); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/"); request.setRequestURI("/accounts/12345"); request.addParameter("locale", "en"); request.addParameter("theme", "green"); HandlerExecutionChain chain = mapping.getHandler(request); assertEquals(4, chain.getInterceptors().length); assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor); assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor); assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor); assertTrue(chain.getInterceptors()[3] instanceof UserRoleAuthorizationInterceptor); request.setRequestURI("/admin/users"); chain = mapping.getHandler(request); assertEquals(2, chain.getInterceptors().length); request.setRequestURI("/logged/accounts/12345"); chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); request.setRequestURI("/foo/logged"); chain = mapping.getHandler(request); assertEquals(3, chain.getInterceptors().length); }
Example #26
Source File: I18nApplication.java From Spring-Boot-I18n-Pro with MIT License | 5 votes |
@Bean public WebMvcConfigurer webMvcConfigurer() { return new WebMvcConfigurer() { //拦截器 @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new LocaleChangeInterceptor()).addPathPatterns("/**"); registry.addInterceptor(new MessageResourceInterceptor()).addPathPatterns("/**"); } }; }
Example #27
Source File: DispatcherServletConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override protected void addInterceptors(InterceptorRegistry registry) { LOGGER.debug("Configuring localeChangeInterceptor"); LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }
Example #28
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 #29
Source File: DispatcherServletConfiguration.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override protected void addInterceptors(InterceptorRegistry registry) { LOGGER.debug("Configuring localeChangeInterceptor"); LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }
Example #30
Source File: LocaleConfiguration.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 4 votes |
@Override public void addInterceptors(InterceptorRegistry registry) { LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor(); localeChangeInterceptor.setParamName("language"); registry.addInterceptor(localeChangeInterceptor); }