JS获取国际化文件:
1:loadTWProperties() 加载 common_zh-TW.properties 文件,
2:$.i18n.prop(‘user‘) 获取文件中的值
function loadTWProperties(){
jQuery.i18n.properties({
name:‘common‘, //文件名
path:‘jscipt/i18n/‘, //路径
language : ‘zh-TW‘, //后缀
mode:‘map‘
});
}
function loadCNProperties(){
jQuery.i18n.properties({
name:‘common‘, //文件名
path:‘jscipt/i18n/‘, //路径
language : ‘zh-CN‘, //后缀
mode:‘map‘
});
}
JSP获取国际化文件:
1:jsp顶部加入<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 2:basename文件名
<fmt:bundle basename="messagerResources"> <fmt:message key="user"/> </fmt:bundle>
JAVA获取国际化文件:applicationContext.xml加入bean
<!-- 资源文件绑定器 -->
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<!-- <property name="basename" value="messagerResources" /> -->
<property name="basenames">
<list>
<value>messagerResources</value>
</list>
</property>
</bean>
private static ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
String strCHINA= ctx.getMessage(key,args,Locale.CHINA) //获取中文
String strENGLISH= ctx.getMessage(key,args,Locale.ENGLISH); //获取英文