Writing International documents
By July
By July
International non-connection configuration page only requires:
spring.messages.basename=i18n.login
1: way 1.5X version of the configuration of the long die today found
Link Configuration
Writing class implements LocaleResover
public class LocaleSetting implements LocaleResolver { @Override public Locale resolveLocale(HttpServletRequest request) { /** * l=('en_US) 取得连接字符串 */ String lstr = request.getParameter("l"); Locale locale = Locale.getDefault(); if(!StringUtils.isEmpty(lstr)){ String[] split = lstr.split("_"); locale = new Locale(split[0],split[1]); } return locale; } @Override public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { } }
A Spring Boot requires only the existence of a succession WebMvcConfigurationSupport, so are configured in this class
In the arrangement described herein below # public class AppConfig the extends WebMvcConfigurationSupport / ** * Configuration international * / @Bean public LocaleResolver that initLocale () { return new new LocaleSetting (); }
2: 2.x versions of the configuration
/ ** * interceptor map * / @Override protected void addInterceptors (InterceptorRegistry Registry) { registry.addInterceptor (LocaleChangeInterceptor ()); Super .addInterceptors (Registry); } / ** * Configuration international * / @Bean public LocaleResolver that LocaleResolver () { the SessionLocaleResolver SLR = new new the SessionLocaleResolver (); // default language used slr.setDefaultLocale (Locale.SIMPLIFIED_CHINESE); return SLR; } @Bean publicLocaleChangeInterceptor the LocaleChangeInterceptor () { the LocaleChangeInterceptor LCI = new new the LocaleChangeInterceptor (); // parameter name used to distinguish the type of language / ** * <A class = "SM-BTN BTN" TH: the href = "@ {index.html (L = 'en-US')} " > Chinese </a> * <a class="btn btn-sm" th:href="@{index.html(l='zh-CN')}"> Dictionary Dictionary English </ A> * / lci.setParamName ( "L" ); return LCI; }