Last active
December 18, 2015 16:39
-
-
Save relax-more/5812865 to your computer and use it in GitHub Desktop.
[java] spring framework, locale の判定と、それに応じた表示文言の切り替えに関してメモ
This file contains hidden or 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
SpringMVC のLocaleResolver を利用すると、自動で locale の判定をしてくれる | |
更に、画面に表示する文言も自動で切り替えを行なってくれる |
This file contains hidden or 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
public class LocaleChangeInterceptor extends HandlerInterceptorAdapter { | |
@Override | |
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | |
// any logic... | |
} | |
@Override | |
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, | |
ModelAndView modelAndView) throws Exception { | |
// any logic... | |
} | |
@Override | |
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) | |
throws Exception { | |
// any logic... | |
} | |
} |
This file contains hidden or 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
btn.test = this is test button text |
This file contains hidden or 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
<bean id="localeResolver" | |
class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> | |
</bean> | |
<!-- 他にもAcceptLanguageLocaleResolverなどなどあるが、自分が利用したケースではAcceptLanguage だけでなく、 | |
設定した言語を利用できるようにする必要があり LocaleChangeIntersepter を併用している。 | |
そのためAcceptLanguageLocaleResolver が利用できなかった --> | |
<!-- <bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver"> | |
</bean> --> | |
<bean id="messageSource" | |
class="org.springframework.context.support.ResourceBundleMessageSource"> | |
<property name="basename" value="messages/messages" /> | |
</bean> |
This file contains hidden or 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
<spring:message code="btn.test" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment