用python脚本将excel表格内容,生成多语言文本xx.string

完成demo可访问:https://github.com/gleeeli/PythonLocalizableProject

excel表格.png
生成的iOS多语言文本.sting文件.png

脚本内容:

#coding=gbk

import openpyxl


from openpyxl import load_workbook

# MineModule  LoginModule  PostModule MessageCenterModule MomentModule MineSetModule ConfigModule MessageListModule GoFishingModule SecretStoryModule
# ['个人中心', '个人设置', '通用',']

wb = load_workbook('./多语言中英文对照.xlsx')
localModuleFilePath = "files/ConfigModule.strings"

#获取工作表--Sheet
# 获得所有sheet的名称
print(str(wb.sheetnames))
# 根据sheet名字获得sheet
a_sheet = wb['通用']
# 获得sheet名
print(a_sheet.title)
# 获得当前正在显示的sheet, 也可以用wb.get_active_sheet()
sheet = wb.active
def writeFileHead():
    with open(localModuleFilePath, 'a') as file_object:
        file_object.write("/*\n " +localModuleFilePath+"\n Pods\n Created by liguanglei on 2023/3/29.\n\n*/\n\n")

def writeRowTofile(key, value):
    with open(localModuleFilePath, 'a') as file_object:
        file_object.write("\"" + key+"\" = \"" + value + "\";\n")


writeFileHead()
for row in a_sheet.values:
    key = str(row[0])
    chineseValue = str(row[1])
    chineseValue = chineseValue.replace("{count}","%s")
    yinhaoStr = "\\\""
    chineseValue = chineseValue.replace("\"", yinhaoStr)
    if key != "None" and key != "" and key != "Key值" and chineseValue != "None":
        print(key + "=" + chineseValue + "备注:" + str(row[2]))
        writeRowTofile(key, chineseValue)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容