准备资源文件,资源文件的命名格式如下:
baseName_language_country.properties
baseName_language.properties
baseName.properties
其中baseName是资源文件的基本名,我们可以自定义,但language和country必须是java支持的语言和国家。如:
中国大陆: baseName_zh_CN.properties
美国: baseName_en_US.properties
现在为应用添加两个资源文件:
第一个存放中文:it_zh_CN.properties
内容为:welcome=欢迎来到传智播客
第二个存放英语(美国): it_en_US.properties
内容为: welcome=welcome to it
对于中文的属性文件,我们编写好后,应该使用jdk提供的native2ascii命令把文件转换为unicode编码的文件。命令的使用方式如下:
native2ascii 源文件.properties 目标文件.properties
配置全局资源与输出国际化信息
当准备好资源文件之后,我们可以在struts.xml中通过struts.custom.i18n.resources常量把资源文件定义为全局资源文件,如下:
<constant name=