首页常见问题正文

编写中文本地环境的资源文件

更新时间:2024-03-06 来源:黑马程序员 浏览量:

IT培训班

  参照applicationRes.properties资源文件的内容,在D盘编写一个用于产生中文本地环境下的临时文件application_temp.properties,该资源文件的内容具体如下。

title=Web应用的国际化
heading=你好!一个国际化应用程序
message=今天是{0,date,long},现在的时间是{0,time,medium}.
我今天买了{1}本书,共花了{2,number,currency}.

  接下来使用native2ascii命令将application_temp.properties文件中本地编码的字符转换为Unicode编码。首先在命令行窗口进入D盘根目录(application_temp.properties文件所在的目录),然后执行如下命令。

native2ascii -encoding gb2312
application_temp.properties applicationRes_zh.properties

  执行完成native2ascii命令后,会在当前目录下生成一个名为applicationRes_zh.properties的文件,该文件的内容如例10-8所示。

  例10-8 application_zh.properties

title=Web\u5e94\u7528\u7684\u56fd\u9645\u5316
heading=\u4f60\u597d\uff01\u4e00\u4e2a\u56fd\u9645\u5316\u5e94\u7528\u7
a0b\u5e8f
message=\u4eca\u5929\u662f{0,date,long},\u73b0\u5728\u7684\u65f6\u95f4\
u662f{0,time,medium}.\u6211\u4eca\u5929\u4e70\u4e86{1}\u672c\u4e66,
    \u5171\u82b1\u4e86{2,number,currency}.

  接下来将完成Unicode编码转换后的applicationRes_zh.properties文件,复制到chapter10工程的src目录中,这样就完成了中文本地环境下资源文件的编写。

分享到:
在线咨询 我要报名
和我们在线交谈!