Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b80187
commit f3b3935
Showing
4 changed files
with
35 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 26 additions & 32 deletions
58
src/main/java/com/nonononoki/alovoa/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,46 @@ | ||
package com.nonononoki.alovoa.config; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.Locale; | ||
|
||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.support.ReloadableResourceBundleMessageSource; | ||
import org.springframework.web.servlet.LocaleResolver; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.i18n.CookieLocaleResolver; | ||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; | ||
|
||
@Configuration | ||
@EnableWebMvc | ||
@ComponentScan | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); | ||
} | ||
|
||
@Override | ||
public void addResourceHandlers(ResourceHandlerRegistry registry) { | ||
registry | ||
.addResourceHandler("/**") | ||
.addResourceLocations("classpath:/static/"); | ||
} | ||
|
||
@Bean(name = "localeResolver") | ||
public LocaleResolver getLocaleResolver() { | ||
CookieLocaleResolver clr = new CookieLocaleResolver(); | ||
clr.setDefaultLocale(Locale.ENGLISH); | ||
return clr; | ||
} | ||
|
||
@Bean(name = "messageSource") | ||
public MessageSource getMessageResource() { | ||
ReloadableResourceBundleMessageSource messageResource= new ReloadableResourceBundleMessageSource(); | ||
messageResource.setBasename("classpath:i18n/messages"); | ||
messageResource.setDefaultEncoding(StandardCharsets.UTF_8.name()); | ||
return messageResource; | ||
} | ||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); | ||
localeInterceptor.setParamName("lang"); | ||
registry.addInterceptor(localeInterceptor).addPathPatterns("/*"); | ||
} | ||
|
||
public void addInterceptors(InterceptorRegistry registry) { | ||
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); | ||
localeInterceptor.setParamName("lang"); | ||
registry.addInterceptor(localeInterceptor).addPathPatterns("/*"); | ||
} | ||
|
||
@Bean | ||
public CookieLocaleResolver localeResolver() { | ||
return new CookieLocaleResolver(); | ||
} | ||
|
||
@Bean | ||
public ReloadableResourceBundleMessageSource messageSource() { | ||
ReloadableResourceBundleMessageSource messageResource = new ReloadableResourceBundleMessageSource(); | ||
messageResource.setBasename("classpath:i18n/messages"); | ||
messageResource.setDefaultEncoding(StandardCharsets.UTF_8.name()); | ||
return messageResource; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters