使用native2ascii進行編碼轉換

在項目開發中,由於涉及到國際化,所以採用該工具進行轉換,將中文字符轉為unicode的ascii形式.
項目開發平台是繁體2k系統,

簡單例子,msg.txt原始內容為簡體中文(即,msg.txt中是big5編碼)
1.所以得到繁體字的編碼可以直接運行:
native2ascii msg.txt msg_zh_TW.properties
得到編碼為 \u7c21\u9ad4\u4e2d\u6587(在頁面顯示正常)

2.我用其他工具將msg.txt轉為簡體gbk編碼後,這時打開該文件,是一些不認識的中文字行(潠极笢恅),
換掉文件後綴為htm,打開後顯示為正常的簡體字.
當直接使用
native2ascii msg.txt msg_zh_TW.properties
其結果編碼為 \u6f60\u6781\u7b22\u6045(在頁面顯示為,潠极笢恅)
採用以下命令即正常
native2ascii -encoding gbk msg.txt msg_zh_TW.properties
得到結果 \u7b80\u4f53\u4e2d\u6587(在頁面顯示正常)



當文件比較多時,可以寫成ant任務,自動批次處理
 <target name="gbk2ascii" depends="clean_gbk" description="Native to ascii for gbk properties(*zh_CN.properties)">
  <native2ascii encoding="GBK" src="${project.web.prop.dir}"
   dest="${project.web.prop.dir}" includes="**/*zh_CN.properties_native"
   ext=".properties"/>
 </target>

 <target name="big2ascii" depends="clean_big" description="Native to ascii for big properties(*zh_TW.properties)">
  <native2ascii encoding="BIG5" src="${project.web.prop.dir}"
   dest="${project.web.prop.dir}" includes="**/*zh_TW.properties_native"
   ext=".properties" />
 </target>

转载于:https://www.cnblogs.com/oisiv/archive/2006/06/27/437256.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值