今天做了个小小的struts1.2国际化,把我作的发过来给大家做个参考,给大家抛砖引玉。
首先我需要写配置文件,就是ApplicationResource.properties文件,在里面定义key=value
key就是随便起的英文名(当然最好和页面中文的英文当key最好),value就是这个配置文件所要展现的语言,比如
key是homepage value=首页
格式是英文:ApplicationResource_语言_国家名.properties
在action 写的时候就是
String lang=request.getParameter("lang"); //通过lang得到传过来的语言
Locale locale=request.getLocale();// 当前软件使用语言情况
System.out.println(locale.getLanguage()+"----"+locale.getCountry());
locale=new Locale(lang,"");// 根据传递的语言信息得到新的本地化
HttpSession session=request.getSession(true);
session.setAttribute(Globals.LOCALE_KEY,locale);
return mapping.findForward("index");
从页面传过来的时候连接是
<a href="./Local.do?method=convert&lang=en" target="_top">英文</a>
其实很简单的国际化,欢迎大家抛砖引玉。