坚持每天写博文,积累下开发中的点点滴滴
什么是国际化
不同国家的人可以使用自己本地的语言。
国际化:I18n(internationalization的首末字符i和n,18为中间的字符数)支持多 种语言,使java代码能够脱离地域的限制,不同国家移植代码时不需要改变代码本身。注意:同一时间只能有一种特定的组合,英文加上一种其他语言,如:英文+中文
准备资源文件,并在XML文件中进行配置
资源文件可以是一下三种格式:
baseName_language_country.properties
baseName_language.properties
baseName.properties
在xml中配置常量
<constant name="struts.custom.i18n.resources" value="baseName"/>
4.准备工作完成我们可以先获得本机操作系统默认的区域和语言
public static void main(String[] args) {
Locale locale=Locale.getDefault();
System.out.println("country:"+locale.getCountry());
System.out.println("language:"+locale.getLanguage());
}
结果为:
country:CN
language:zh
5.在JSP中使用<s:text name=“”/>
标签输出国际化信息