1说明
一个系统的国际化就是根据操作系统的语言,页面上的表现形式发生相应的变化。比如如果操作系统是英文,页面的文字应该用英语,如果操作系统是中文,页面的语言应该是中文。
IE浏览器设置语言环境:
Windows系统下:
IE -->工具-->Intener选项--->语言--->设置语言首选项--->添加XX语言,就可实现添加。
2 步骤
(1)、建立资源文件
资源文件的命名规则:
默认的命名为:
文件名前缀.properties
根据语言的命名为:
文件名前缀.语言种类.properties
例如:
中文:
resource_zh_CN.properties
注:
关于资源文件中中文字符编码的转换:
对于中文的属性文件,我们编写好后,应该使用jdk提供的native2ascii命令把文件转换为unicode编码的文件。命令的使用方式如下:
native2ascii 源文件.properties 目标文件.properties但是 Myeclipse智能可自动将中文字符转化成ASCII码。
内容:
item.username=用户名
item.password=密码
英文:
resource_en_US.properties
内容:
item.username=username_en
item.password=password_en
默认:
resource.properties
内容:
item.username=username
item.password=password
(2)、 配置文件中
需要在配置文件中加入:
<constant
name="struts.custom.i18n.resources"value=
"cn.itcast.struts2.action.i18n.resource">
</constant>
说明:
1、 这样struts2就会去找你写的资源文件
2、 name的值可以在org/apache/struts2/default.properties中找到。
3、 如果放置的资源文件在src下,则value的值可以直接写,如果在
包中则可以写成包名.resource。
4、 在这里resource是个基名,也就是说可以加载以resource开头的文件。
(3)、页面中
利用<s:text name=”item.username”/>就可以把资源文件中的内容输出来。
|
|
(4)、在action中
可以利用ActionSupport中的getText()方法获取资源文件的value值。
|