自动生成中文properties文件的好帮手

建立一个名叫“中文Unicode编码批量生成工具.wsf”脚本文件,内容如下。把直接用中文编写properties文件拖放到该脚本文件上面,即自动转换成包含相应中文字符Unicode的zh-cn properties文件,原文件被保存在"./_BACKUP FILES'"目录中。

<job id="BatchUnicode">
<script language="JScript"> 

 var beginTime = new Date ().getTime();

 if(WScript.Arguments.length==0)
  WScript.quit ();

 // File names in full path
 var inputFilesEnum = new Enumerator (WScript.Arguments);

 // Current directory: replacing last occurred "/xxx" with "" in filepath string
 var curDir = inputFilesEnum.item ().replace(/[^//]*$/ig, '')

 // Create backup directory
 var backDir = curDir +  '_BACKUP FILES';

 var fileSystem = new ActiveXObject ('Scripting.FileSystemObject');

 if (!fileSystem.folderExists (backDir))
  fileSystem.createFolder(backDir); 
 
 var count = 0;
 while (!inputFilesEnum.atEnd ())  {
  fileSystem.copyFile (inputFilesEnum.item(), backDir +'//');

  var f1=fileSystem.openTextFile (inputFilesEnum.item (), 1); // parameter '1' for 'read'
  var content=f1.readAll ();
  f1.close ();
  
  var f2=fileSystem.openTextFile (inputFilesEnum.item (), 2);  // parameter '2' for 'write'
  f2.write (convert (content));
  f2.close ();

  inputFilesEnum.moveNext ();
  count ++;
 }


 WScript.echo(info());


 function convert (str) {
  /**
   * Search all non-ASCII char and replace with it's unicode. 
   * -- patern "/[^/u0000-/u00FF]/g" to specify all non-ASCII char 
   * -- "$0" to represent any search result use the patern  "/[^/u0000-/u00FF]/g"
   * -- "$2" to represent every second result use the patern  "/(%u)(/w{4})/gi", case ignored
  **/
  return str.replace (/[^/u0000-/u00FF]/g, function($0){return escape($0).replace(/(%u)(/w{4})/gi, "//u$2")});
 }


 function info(){
  return unescape(
  '%u4E2D%u6587Unicode%u6279%u91CF%u751F%u6210%u5DE5%u5177%u3000%u3000%u722C%u5C71%u864E%u8F6F%u4EF6 pashanhu.54bk.com'
  + '/n' + new Array(56).join('_')  
  + '/n/n%u5904%u7406%u6587%u4EF6 '+count+' %u4E2A'
  + '/n/n%u7528%u65F6 '+((new Date().getTime()-beginTime)/1000)+' %u79D2'  
  + '/n/n%u606D%u559C%u60A8%uFF0C%u5904%u7406%u6210%u529F%uFF01'
  )
 }

</script>
</job>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值