代码拉取完成,页面将自动刷新
# -*- coding:utf-8 -*-
import os
from optparse import OptionParser
from LocalizableStringsFileUtil import LocalizableStringsFileUtil
import pyExcelerator
import time
#Add command option
def addParser():
parser = OptionParser()
parser.add_option("-f", "--filesDirectory",
help="Localizable.strings files directory.",
metavar="filesDirectory")
parser.add_option("-t", "--targetFilePath",
help="Target File (xls) Path.",
metavar="targetFilePath")
(options, args) = parser.parse_args()
return options
# Start convert Localizable.strings to xls
def startConvert(options):
directory = options.filesDirectory
targetFilePath = options.targetFilePath
if directory is not None:
if targetFilePath is not None:
destinyDir = targetFilePath + "/strings-files-to-xls_"+ time.strftime("%Y%m%d_%H%M%S")
if not os.path.exists(destinyDir):
os.makedirs(destinyDir)
for parent, dirnames, unusedfilenames in os.walk(directory):
lprogDirs = [di for di in dirnames if di.endswith(".lproj")]
for dirname in lprogDirs:
workbook = pyExcelerator.Workbook()
for parent, dirnames2, filenames in os.walk(directory+'/'+dirname):
stringFiles = [fi for fi in filenames if fi.endswith(".strings")]
for stringfile in stringFiles:
ws = workbook.add_sheet(stringfile)
# Key & Value
path = directory+dirname+'/' + stringfile
(keys, values) = LocalizableStringsFileUtil.getKeysAndValues(path)
for keyIndex in range(len(keys)):
key = keys[keyIndex]
value = values[keyIndex]
ws.write(keyIndex, 0, key)
ws.write(keyIndex, 1, value)
filePath = destinyDir +"/" + dirname.replace(".lproj", "") + ".xls"
workbook.save(filePath)
print "Convert %s successfully! you can see xls file in %s" % (directory ,filePath)
else:
print "Target file path can not be empty! try -h for help."
else:
print "Localizable.strings files directory can not be empty! try -h for help."
def main():
options = addParser()
startConvert(options)
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。