translation tool

ExpandedBlockStart.gif code
  1  from  xml.dom  import  minidom
  2 
  3  def  createDocument(strContentName, strDeveloper, strFile, strOutputFile):
  4      doc  =  minidom.Document()
  5 
  6       # Create slim
  7      slim  =  doc.createElement( " slim " )
  8      slim.setAttribute( " slimEd " " 1.0 " )
  9      slim.setAttribute( " xmlns " " www.sap.com/slim " )
 10 
 11       # Create header
 12      header  =  doc.createElement( " header " )
 13 
 14       # Create locale
 15      locale  =  doc.createElement( " locale " )
 16 
 17       # Create develLc
 18      develLc  =  doc.createElement( " develLc " )
 19      develLc.appendChild(doc.createTextNode( " en++ " ))
 20 
 21       # Create contentLc
 22      contentLc  =  doc.createElement( " contentLc " )
 23      contentLc.appendChild(doc.createTextNode( " en++ " ))
 24 
 25      locale.appendChild(develLc)
 26      locale.appendChild(contentLc)
 27 
 28      header.appendChild(locale)
 29 
 30       # objType
 31      objType  =  doc.createElement( " objType " )
 32      objType.appendChild(doc.createTextNode( " line " ))
 33      header.appendChild(objType)
 34 
 35       # collection
 36      collection  =  doc.createElement( " collection " )
 37      collection.appendChild(doc.createTextNode( " BUSMB_SBO_iPhone_10 " ))
 38      header.appendChild(collection)
 39 
 40       # domain
 41      domain  =  doc.createElement( " domain " )
 42      domain.appendChild(doc.createTextNode( " FI " ))
 43      header.appendChild(domain)
 44 
 45       # contentName
 46      contentName  =  doc.createElement( " contentName " )
 47      contentName.appendChild(doc.createTextNode(strContentName))
 48      header.appendChild(contentName)
 49 
 50       # defaults
 51      defaults  =  doc.createElement( " defaults " )
 52 
 53       # maxL
 54      maxL  =  doc.createElement( " maxL " )
 55      maxL.appendChild(doc.createTextNode( " 255 " ))
 56      defaults.appendChild(maxL)
 57      header.appendChild(defaults)
 58 
 59       # workflow
 60      workflow  =  doc.createElement( " workflow " )
 61 
 62       # contacts
 63      contacts  =  doc.createElement( " contacts " )
 64 
 65       # developer
 66      developer  =  doc.createElement( " developer " )
 67      developer.appendChild(doc.createTextNode(strDeveloper))
 68      contacts.appendChild(developer)
 69      workflow.appendChild(contacts)
 70      header.appendChild(workflow)
 71 
 72       # asd
 73      asd  =  doc.createElement( " asd " )
 74      header.appendChild(asd)
 75 
 76      slim.appendChild(header)
 77 
 78       # body
 79      body  =  doc.createElement( " body " )
 80 
 81       # loGrp
 82      loGrp  =  doc.createElement( " loGrp " )
 83      loGrp.setAttribute( " grpClass " " textType " )
 84      loGrp.setAttribute( " grpName " " XTXT " )
 85 
 86      input  =  open(strFile,  ' r ' )
 87       for  line  in  input.readlines():
 88           if (line.find( ' " ' !=   - 1 ):
 89              parseLine(doc, loGrp, line)
 90      
 91      body.appendChild(loGrp)
 92      slim.appendChild(body)
 93 
 94      output  =  open(strOutputFile,  ' w ' )
 95      slim.writexml(output)
 96      
 97  def  createItem(doc, loGrp, strtk, strmaxL, strText):
 98       # lo
 99      lo  =  doc.createElement( " lo " )
100      lo.setAttribute( " tK " , strtk)
101      lo.setAttribute( " maxL " , strmaxL)
102 
103       # loC
104      loC  =  doc.createElement( " loC " )
105      loC.appendChild(doc.createTextNode(strText))
106      lo.appendChild(loC)
107      loGrp.appendChild(lo)
108      
109  def  parseLine(doc, loGrp, line):
110      keystart  =  line.find( ' " ' )
111      keyend  =  line.find( ' " ' , keystart + 1 )
112      key  =  line[keystart : keyend]
113 
114      valuestart  =  line.find( ' = ' +   2
115      valueend  =  line.rfind( ' " ' )
116      value  =  line[valuestart : valueend]  +   " ; "
117 
118       if (key.find( ' # ' !=   - 1 ):
119          length  =  line[line.find( ' # ' ) + 1  : keyend]
120           # key = line[keystart : line.find('#')-2]
121       else :
122          length  =   " 255 "
123      createItem(doc, loGrp, key, length, value)
124 
125  if   __name__   ==   " __main__ " :
126      createDocument( " BUSMB_SBO_iPhone_Setting_10 " " 000 " " C:\Settings.strings " " C:\iphone_setting.xml " )
127      createDocument( " BUSMB_SBO_iPhone_Main_10 " " 000 " " C:\main.strings " " C:\iphone_main.xml " )
128 

 

转载于:https://www.cnblogs.com/zhtf2014/archive/2010/08/08/1795117.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值