将ios以及android的多语言文件写成excel方便翻译,iosandroid
投稿于 被查看 25296 次 评论:177
将ios以及android的多语言文件写成excel方便翻译,iosandroid
此小工具的出炉是因为我们的策划抱怨翻译ios的多语言很麻烦,文本文件看起来像这个样子: /* No comment provided by engineer. */ "下一步" = "下一步"; 他说,要是像excel这样:|"下一步" |"下一步" |
两列,则好多了。
于是我就着手用python写了这样一个转换工具。
由于我的python初学,所以,写出来的代码还请大家多指点。
我的计划是:
- 静态地址文件读取与转换;
- 动态文件地址读取与转换;
- 反向工程。
多多指教!
1.[图片] 第一次尝试
2.[Python]代码
#!/usr/bin/env python # -*- coding:utf-8 -*- ''' # command line tool for reading *.strings file (the file for multi-language support of ios, the same for android.), make it a excel file for the translator. 1. reading file: receive file name and target name 2. Created on Jul 18, 2011 @author: ernest ''' import codecs import pyExcelerator #采用此方式是为了解决编码问题 file = codecs.open("C:/Users/ernest/Desktop/Localizable.strings", 'r', 'utf-8') string = file.read() file.close() #去除无用字段; string = string.replace('/* No comment provided by engineer. */', '').replace('\n', '') #拆分字段; list = [x.split(' = ') for x in string.split(';')] #excel操作; workbook = pyExcelerator.Workbook() ws = workbook.add_sheet('sheet1') for x in range(len(list)): for y in range(len(list[x])): if list[x][y]: ws.write(x,y,list[x][y]) workbook.save('C:/Users/ernest/Desktop/strings.xls')
用户评论