def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir+"/"+file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"

                path = targetDir + "/values-"+languageName+"/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = file.replace(".xls", ".xml")
                XmlFileUtil.writeToFile(
                    keys, values, path, filename, options.additional)
    print "Convert %s successfully! you can xml files in %s" % (
        fileDir, targetDir)
def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"
                elif languageName == "zh-Hant":
                    languageName = "zh-rTW"
                else:
                    match = re.match(r"^([a-z]{2})-([A-Z]{2})$", languageName)
                    if match:
                        languageName = match.group(1) + "-r" + match.group(2)

                path = targetDir + "/values-" + languageName + "/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = "strings.xml"
                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)
Example #3
0
def convertFromSingleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)
            table = xlsFileUtil.getTableByIndex(0)
            firstRow = table.row_values(0)
            keys = table.col_values(0)
            del keys[0]

            for index in range(len(firstRow)):
                if index <= 0:
                    continue
                languageName = firstRow[index]
                values = table.col_values(index)
                del values[0]

                if languageName == "zh-Hans":
                    languageName = "zh-rCN"

                path = targetDir + "/values-" + languageName + "/"
                if languageName == 'en':
                    path = targetDir + "/values/"
                filename = file.replace(".xls", ".xml")
                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)
def startConvert(options):
    fileDir = options.fileDir

    if fileDir is None:
        Log.error("strings files directory can not be empty! try -h for help.")
        return

    if options.targetDir is None:
        Log.error("target files directory can not be empty! try -h for help.")
        return

    targetDir = options.targetDir + "/strings-files-to-xml_" + \
        time.strftime("%Y%m%d_%H%M%S")

    for _, _, filenames in os.walk(fileDir):
        stringsFilenames = [fi for fi in filenames if fi.endswith(".strings")]
        for filename in stringsFilenames:
            path = fileDir+"/"+filename
            (keys, values) = StringsFileUtil.getKeysAndValues(path)
            XmlFileUtil.writeToFile(keys, values, targetDir,
                                    filename.replace(".strings", ".xml"), options.additional)

    Log.info("Convert successfully! you can see xml files in %s" % (targetDir))
def convertFromMultipleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir+"/"+file)

            languageName = file.replace(".xls", "")
            if languageName == "zh-Hans":
                languageName = "zh-rCN"
            path = targetDir + "/values-"+languageName+"/"
            if languageName == 'en':
                path = targetDir + "/values/"
            if not os.path.exists(path):
                os.makedirs(path)

            for table in xlsFileUtil.getAllTables():
                keys = table.col_values(0)
                values = table.col_values(1)
                filename = table.name.replace(".strings", ".xml")

                XmlFileUtil.writeToFile(
                    keys, values, path, filename, options.additional)
    print "Convert %s successfully! you can xml files in %s" % (
        fileDir, targetDir)
def startConvert(options):
    fileDir = options.fileDir

    if fileDir is None:
        Log.error("strings files directory can not be empty! try -h for help.")
        return

    if options.targetDir is None:
        Log.error("target files directory can not be empty! try -h for help.")
        return

    targetDir = options.targetDir + "/strings-files-to-xml_" + \
        time.strftime("%Y%m%d_%H%M%S")

    for _, _, filenames in os.walk(fileDir):
        stringsFilenames = [fi for fi in filenames if fi.endswith(".strings")]
        for filename in stringsFilenames:
            path = fileDir + "/" + filename
            (keys, values) = StringsFileUtil.getKeysAndValues(path)
            XmlFileUtil.writeToFile(keys, values, targetDir,
                                    filename.replace(".strings", ".xml"),
                                    options.additional)

    Log.info("Convert successfully! you can see xml files in %s" % (targetDir))
def convertFromMultipleForm(options, fileDir, targetDir):
    for _, _, filenames in os.walk(fileDir):
        xlsFilenames = [fi for fi in filenames if fi.endswith(".xls")]
        for file in xlsFilenames:
            xlsFileUtil = XlsFileUtil(fileDir + "/" + file)

            languageName = file.replace(".xls", "")
            if languageName == "zh-Hans":
                languageName = "zh-rCN"
            path = targetDir + "/values-" + languageName + "/"
            if languageName == 'en':
                path = targetDir + "/values/"
            if not os.path.exists(path):
                os.makedirs(path)

            for table in xlsFileUtil.getAllTables():
                keys = table.col_values(0)
                values = table.col_values(1)
                filename = table.name.replace(".strings", ".xml")

                XmlFileUtil.writeToFile(keys, values, path, filename,
                                        options.additional)
    print "Convert %s successfully! you can xml files in %s" % (fileDir,
                                                                targetDir)