`
kidiaoer
  • 浏览: 806649 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

struts国际化处理

阅读更多
struts国际化处理
STRUTS提供了很好的国际化的支持,STRUTS允许将不同语言的文字写在多个资源文件中,每个资源对应一种语言,而在JSP页面上则通过STRUTS标签来显示文字,该标签可以根据浏览器的当前语言设置确定从对应的语种资源文件中取出字符串,显示在页面上。

1、资源文件
资源文件一般保存在src目录下,根据不同语言文字,建立对应的资源文件,文件命名格式如下:
例如,英文(美国) ApplicationResources_en_US.properties
      中文(简体)ApplicationResources_zh_CN.properties
      中文(繁体)ApplicationResources_tw.properties
      泰语 ApplicationResources_th.properties
      日语 ApplicationResources_jp.properties
资源文件的扩展名一般为properties。
ApplicationResources是一个包含"key=value" 对的文件,定义了一个KEY对应当前语言下的文字。
如:ustc=中国科技大学
    class=近代物理系
struts-config.xml文件中指定了资源文件的对应设置。
<message-resources parameter="ApplicationResources" />

2、native2ascii
1)native2ascii简介
资源文件建立起来之后,struts并不能正常使用,需要把资源文件的编码转换成unicode。
native2ascii在JDK安装目录的bin目录下。用来将别的文本类文件(比如*.txt,*.ini,*.properties,*.java等等)编码转为Unicode编码。
Unicode编码的定义:Unicode(统一码、万国码、单一码)是一种在计算机上使用的字符编码。它为每种语言中的每个字符设定了统一并且唯一的二进制编码,以满足跨语言、跨平台进行文本转换、处理的要求。

2)native2ascii命令格式:
native2ascii -[options] [inputfile [outputfile]]
说明: -[options]:表示命令开关,有两个选项可供选择
-reverse:将Unicode编码转为本地或者指定编码,不指定编码情况下,将转为本地编码。
-encoding encoding_name:转换为指定编码,encoding_name为编码名称。
[inputfile [outputfile]]
inputfile:表示输入文件全名。
outputfile:输出文件名。如果缺少此参数,将输出到控制台。
格式如下:
native2ascii -encoding GBK ApplicationResources.properties ApplicationResources_zh_CN.properties

3、eclipse国际化化插件propedit
native2ascii转码后的文件,不能阅读中文含义,后期维护和修改资源文件也比较麻烦。幸好eclipse国际化化插件propedit。安装Propedit插件后,资源文件中能直接显示中文。
具体操作步骤:
1)展开Eclipse的Help菜单,将鼠标移到Software Update子项,在出现的子菜单中点击Find and Install;
2)在Install/Update对话框中选择Search for new features to install,点击Next;
3)在Install对话框中点击New Remote Site;
4)在New Update Site对话框的Name填入“PropEdit”或其它任意非空字符串,
在URL中填入http://propedit.sourceforge.jp/eclipse/updates/
5)在Site to include to search列表中,除上一步加入的site外的其它选项去掉,点击Finsih;
6)我的eclipse版本是3.2,安装时出现如下错误:
Requested operation cannot be performed because it would invalidate the current configuration.
See details for more information.
Properties Search for Eclipse 3.1.x (2.0.0) requires plug-in "org.eclipse.search (3.1.0)", or equivalent.
7)把Updates对话框中的Select the features to install列表中将所有结尾为“3.1.x”的选项去掉
8)点击Finish关闭对话框;
9)在下载后,同意安装,再按提示重启Eclipse,在工具条看到形似vi的按钮表示安装成功,插件可用。
此时,Eclpise中所有properties文件的文件名前有绿色的P的图标作为标识。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics