1.添加多语言文件*.properties
F64_en_EN.properties详情如下:
F60_G00_M100=Please select data. F60_G00_M101=Are you sure you want to delete? F60_G00_M102=The data is changed. Do you want to save it ?
2、配置springMVC配置文件
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <!--后续开发中需要国际化的模块添加到这里即可--> <value>i18n.Example</value> </list> </property> <property name="defaultEncoding" value="UTF-8" /> <property name="useCodeAsDefaultMessage" value="true" /> </bean> <!--设置cookie解释器分析设置的国际化多语言 --> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> <property name="cookieMaxAge" value="315360000" /> <property name="defaultLocale" value="en_EN" /> <property name="cookieName" value="Language"> </property> </bean>
3.在登录成功后修改运行环境的语言
// 根据选择的语言种类设置配置文件中的localeResolver的内容 if ("EN".equals(logonUser.getLanguage())) { Locale localeEN = new Locale("en", "EN"); localeResolver.setLocale(request, response, localeEN); } else if ("JA".equals(logonUser.getLanguage())) { Locale localeJP = new Locale("ja", "JP"); localeResolver.setLocale(request, response, localeJP); } else { Locale localeEN = new Locale("en", "EN"); localeResolver.setLocale(request, response, localeEN); }
4.定义取得文言内容的方法
protected String getMessage(String code,Object... params){ return messageSource.getMessage(code, params, LocaleContextHolder.getLocale()); }
5.取得文言内容
String title = getMessage("RF64_L001");
原文地址:https://www.cnblogs.com/vickylinj/p/9588735.html
时间: 2024-10-28 14:49:04