Android 多語言翻譯的自動拷貝
阿新 • • 發佈:2019-02-16
1. python 指令碼實現特定string 的拷貝新增
source/vaues-xxx/string.xml -> aim/values-xxx/strings.xml
#!/usr/bin/python # -*- coding: utf-8 -*- import os import re #source and aim path,must be right source_dir = "./Email_UnifiedEmail_svn/CP_G11N_SVN/SmartPhone_StringResource_Folder/res/_NEW/" aim_dir = "./out/" #source string names res_names = ["account_setup_options_sync_tasks_label","account_settings_sync_tasks_enable","account_settings_sync_tasks_summary"] end_tag = "</resources>" #comments between sources strings comments = [" // add for task begin\n"," // add for task end\n"] def getSubFile(dirpath): #遍歷filepath下所有檔案,包括子目錄 files = os.listdir(dirpath) for file in files: #print file fi_d = os.path.join(dirpath,file) if os.path.isdir(fi_d): getSubFile(fi_d) else: cp_res(fi_d) def cp_res(filepath): #print filepath #print filepath.split("/")[-1] #print filepath.split("/")[-2] aim_lines = [] aim_lines_end = [] aim_path = aim_dir + filepath.split("/")[-2] + "/" + filepath.split("/")[-1] has_end = False #read aim file print "parser the aim file start ..." file = open(aim_path) while 1: line = file.readline() if not line: break if end_tag in line: has_end = True if has_end: aim_lines_end.append(line) else: aim_lines.append(line) file.close() #print len(aim_lines) print "merge the source file start ..." aim_lines.append(comments[0]) #read souce file file = open(filepath) while 1: line = file.readline() if not line: break for res_name in res_names: if res_name in line: aim_lines.append(line) file.close() aim_lines.append(comments[1]) #write to aim file print "write to aim file start ..." fo = open(aim_path, "wb") for line in aim_lines: fo.writelines(line) for line in aim_lines_end: fo.writelines(line) fo.close() def main(): getSubFile(source_dir) if __name__ == '__main__': main()