Aqara_localizable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +44 -0
  4. data/bin/Aqaralocalizable +13 -0
  5. data/lib/Aqara_localizable/cocoapods_plugin.rb +12 -0
  6. data/lib/Aqara_localizable/command/command_gen.rb +37 -0
  7. data/lib/Aqara_localizable/command/zxf.py +1 -0
  8. data/lib/Aqara_localizable/command.rb +21 -0
  9. data/lib/Aqara_localizable/gem_version.rb +3 -0
  10. data/lib/Aqara_localizable.rb +9 -0
  11. data/lib/script/git_shell/addPrefix.sh +124 -0
  12. data/lib/script/git_shell/android_git_clean.sh +18 -0
  13. data/lib/script/git_shell/commit_push.sh +45 -0
  14. data/lib/script/git_shell/creat_new_branch.sh +40 -0
  15. data/lib/script/git_shell/git_branch.sh +36 -0
  16. data/lib/script/git_shell/git_checkout.sh +37 -0
  17. data/lib/script/git_shell/git_delete_branch.sh +42 -0
  18. data/lib/script/git_shell/git_pull.sh +37 -0
  19. data/lib/script/git_shell/ios_commit_push.sh +23 -0
  20. data/lib/script/git_shell/ios_sdk_Build.sh +43 -0
  21. data/lib/script/git_shell/ios_sdk_checkout.sh +19 -0
  22. data/lib/script/git_shell/reset_hard.sh +36 -0
  23. data/lib/script/git_shell/switch_master_branch.sh +125 -0
  24. data/lib/script/ios_py_code/AqaraHome.xlsx +0 -0
  25. data/lib/script/ios_py_code/DownloadNewLanguage.py +59 -0
  26. data/lib/script/ios_py_code/__pycache__/DownloadNewLanguage.cpython-310.pyc +0 -0
  27. data/lib/script/ios_py_code/__pycache__/DownloadNewLanguage.cpython-39.pyc +0 -0
  28. data/lib/script/ios_py_code/__pycache__/handel_localize.cpython-39.pyc +0 -0
  29. data/lib/script/ios_py_code/handel_localize.py +120 -0
  30. data/lib/script/ios_py_code/handle_all_hit_tool.py +35 -0
  31. data/lib/script/ios_py_code/ios_sp_str_generator.py +149 -0
  32. data/lib/script/ios_py_code/new_value_notfoundkey.xlsx +0 -0
  33. data/lib/script/ios_py_code/notFoundKeys.xlsx +0 -0
  34. data/lib/script/ios_py_code/replace_ios.xlsx +0 -0
  35. data/lib/script/ios_py_code/result_notfoundkey.xlsx +0 -0
  36. data/lib/script/ios_py_code/scanKeyInCode.py +475 -0
  37. data/lib/script/ios_py_code/source.xlsx +0 -0
  38. data/lib/script/main.py +16 -0
  39. data/lib/script/output_file/ios/de.lproj/Localizable.strings +5109 -0
  40. data/lib/script/output_file/ios/en.lproj/Localizable.strings +5202 -0
  41. data/lib/script/output_file/ios/es.lproj/Localizable.strings +5107 -0
  42. data/lib/script/output_file/ios/fr.lproj/Localizable.strings +5101 -0
  43. data/lib/script/output_file/ios/it.lproj/Localizable.strings +5097 -0
  44. data/lib/script/output_file/ios/ko.lproj/Localizable.strings +5013 -0
  45. data/lib/script/output_file/ios/ru.lproj/Localizable.strings +4226 -0
  46. data/lib/script/output_file/ios/zh-HK.lproj/Localizable.strings +4807 -0
  47. data/lib/script/output_file/ios/zh-Hans.lproj/Localizable.strings +5166 -0
  48. data/lib/script/output_file/ios/zh-Hant-TW.lproj/Localizable.strings +4786 -0
  49. data/lib/script/source_language/hit_all_str.xlsx +0 -0
  50. data/lib/script/source_language/hit_all_str_copy.xlsx +0 -0
  51. data/lib/script/source_language/hit_all_str_new.xlsx +0 -0
  52. data/lib/script/source_language/hit_all_str_origin.xlsx +0 -0
  53. data/lib/script/source_language/hit_all_str_storage.xlsx +0 -0
  54. data/lib/script/source_language/offer_text.xlsx +0 -0
  55. data/lib/script/source_language/~$hit_all_str.xlsx +0 -0
  56. data/lib/script/util_code/ModifyInfo.py +16 -0
  57. data/lib/script/util_code/ShareStringElement.py +8 -0
  58. data/lib/script/util_code/__pycache__/ModifyInfo.cpython-310.pyc +0 -0
  59. data/lib/script/util_code/__pycache__/ModifyInfo.cpython-39.pyc +0 -0
  60. data/lib/script/util_code/__pycache__/delete_and_replace_for_ios.cpython-39.pyc +0 -0
  61. data/lib/script/util_code/__pycache__/file_util.cpython-310.pyc +0 -0
  62. data/lib/script/util_code/__pycache__/file_util.cpython-39.pyc +0 -0
  63. data/lib/script/util_code/__pycache__/lang_enum.cpython-310.pyc +0 -0
  64. data/lib/script/util_code/__pycache__/lang_enum.cpython-39.pyc +0 -0
  65. data/lib/script/util_code/__pycache__/replace_info.cpython-310.pyc +0 -0
  66. data/lib/script/util_code/__pycache__/replace_info.cpython-39.pyc +0 -0
  67. data/lib/script/util_code/__pycache__/str_config.cpython-39.pyc +0 -0
  68. data/lib/script/util_code/__pycache__/string_element.cpython-310.pyc +0 -0
  69. data/lib/script/util_code/__pycache__/string_element.cpython-39.pyc +0 -0
  70. data/lib/script/util_code/__pycache__/string_repeat_filter.cpython-310.pyc +0 -0
  71. data/lib/script/util_code/__pycache__/string_repeat_filter.cpython-39.pyc +0 -0
  72. data/lib/script/util_code/add_access_str.py +67 -0
  73. data/lib/script/util_code/android_general_script.py +224 -0
  74. data/lib/script/util_code/android_prepare.py +30 -0
  75. data/lib/script/util_code/android_saowei.py +44 -0
  76. data/lib/script/util_code/android_string_arrays_extract.py +48 -0
  77. data/lib/script/util_code/app_used_str_generator.py +162 -0
  78. data/lib/script/util_code/delete_and_replace_for_android.py +177 -0
  79. data/lib/script/util_code/delete_and_replace_for_ios.py +125 -0
  80. data/lib/script/util_code/duplicat_filter.py +32 -0
  81. data/lib/script/util_code/file_util.py +311 -0
  82. data/lib/script/util_code/final_lan_hit.py +80 -0
  83. data/lib/script/util_code/final_strdata.py +24 -0
  84. data/lib/script/util_code/git_conflict_resovle.py +19 -0
  85. data/lib/script/util_code/hit_android_project_replace.py +68 -0
  86. data/lib/script/util_code/hit_check_project_replace.py +89 -0
  87. data/lib/script/util_code/hit_ios_project_replace.py +59 -0
  88. data/lib/script/util_code/incremental_for_android/add_unexist_key.py +24 -0
  89. data/lib/script/util_code/incremental_for_android/android_incremental_str.py +47 -0
  90. data/lib/script/util_code/incremental_for_android/android_incremental_str_by_txt.py +21 -0
  91. data/lib/script/util_code/incremental_for_android/check_unexist_for_android.py +168 -0
  92. data/lib/script/util_code/incremental_for_android/incremental_module.py +51 -0
  93. data/lib/script/util_code/incremental_for_android/manual_review_replace.py +23 -0
  94. data/lib/script/util_code/incremental_for_android/serveral_incremental_str.py +23 -0
  95. data/lib/script/util_code/incremental_for_android/test_manual_review_replace.py +29 -0
  96. data/lib/script/util_code/incremental_for_android/unexist_key_process.py +58 -0
  97. data/lib/script/util_code/incremental_for_android/unexist_key_process_replace.py +24 -0
  98. data/lib/script/util_code/incremental_for_ios/incremental_module.py +56 -0
  99. data/lib/script/util_code/incremental_for_ios/manual_review_replace.py +23 -0
  100. data/lib/script/util_code/ios_camera_unique.py +49 -0
  101. data/lib/script/util_code/ios_general_script.py +209 -0
  102. data/lib/script/util_code/ios_handle_format.py +199 -0
  103. data/lib/script/util_code/ios_module_script.py +199 -0
  104. data/lib/script/util_code/ios_project_key_replace.py +62 -0
  105. data/lib/script/util_code/ios_saowei.py +29 -0
  106. data/lib/script/util_code/ios_share_xlsx_processor.py +72 -0
  107. data/lib/script/util_code/lang_enum.py +13 -0
  108. data/lib/script/util_code/leak_translate_complete.py +29 -0
  109. data/lib/script/util_code/multi_lan_main.py +120 -0
  110. data/lib/script/util_code/platform_merge_key.py +193 -0
  111. data/lib/script/util_code/product_android_project_replace.py +63 -0
  112. data/lib/script/util_code/product_data.py +25 -0
  113. data/lib/script/util_code/product_feature.py +14 -0
  114. data/lib/script/util_code/product_ios_project_replace.py +54 -0
  115. data/lib/script/util_code/product_repeat_key_replace.py +209 -0
  116. data/lib/script/util_code/product_song.py +14 -0
  117. data/lib/script/util_code/project_module_analyze.py +119 -0
  118. data/lib/script/util_code/replace_info.py +7 -0
  119. data/lib/script/util_code/run_all.py +75 -0
  120. data/lib/script/util_code/simple_task.py +7 -0
  121. data/lib/script/util_code/str_config.py +36 -0
  122. data/lib/script/util_code/str_copy_to_multilan.py +22 -0
  123. data/lib/script/util_code/string_element.py +39 -0
  124. data/lib/script/util_code/string_repeat_filter.py +341 -0
  125. data/lib/script/util_code/test_platform_merge_key.py +188 -0
  126. data/lib/script/util_code/test_product_repeat_key_replace.py +232 -0
  127. data/lib/script/util_code/unuse_string_scan_android.py +223 -0
  128. data/lib/script/util_code/unuse_string_scan_ios.py +162 -0
  129. data/lib/script/util_code/xiangrui.py +31 -0
  130. data/lib/script/zresult_platform/en.lproj/InfoPlist.strings +24 -0
  131. data/lib/script/zresult_platform/en.lproj/Localizable.strings +4703 -0
  132. data/lib/script/zresult_platform/ko.lproj/InfoPlist.strings +23 -0
  133. data/lib/script/zresult_platform/ko.lproj/Localizable.strings +4579 -0
  134. data/lib/script/zresult_platform/ru.lproj/InfoPlist.strings +23 -0
  135. data/lib/script/zresult_platform/ru.lproj/Localizable.strings +3800 -0
  136. data/lib/script/zresult_platform/zh-HK.lproj/InfoPlist.strings +25 -0
  137. data/lib/script/zresult_platform/zh-HK.lproj/Localizable.strings +4360 -0
  138. data/lib/script/zresult_platform/zh-Hans.lproj/InfoPlist.strings +23 -0
  139. data/lib/script/zresult_platform/zh-Hans.lproj/Localizable.strings +4710 -0
  140. data/lib/script/zresult_platform/zh-Hant-TW.lproj/InfoPlist.strings +25 -0
  141. data/lib/script/zresult_platform/zh-Hant-TW.lproj/Localizable.strings +4340 -0
  142. metadata +308 -0
@@ -0,0 +1,475 @@
1
+ import sys
2
+ import os.path
3
+ import csv
4
+ from util_code import str_config, file_util, string_repeat_filter, delete_and_replace_for_ios,string_element
5
+
6
+ #处理bundle中的多语言,整合成一个dict
7
+ def hanleBundle():
8
+ modules = [
9
+ 'main',
10
+ 'LMAccessNet.bundle',
11
+ 'LMCameraFramework.bundle',
12
+ 'LMChartFramework.bundle',
13
+ 'LMFramework.bundle',
14
+ 'LMLightFramework.bundle',
15
+ 'LMIrcodeLanguage.bundle',
16
+ 'LMMDUILanguage.bundle',
17
+ 'LMUpgradeLanguage.bundle',
18
+ ]
19
+ sdk_str_dir = '/Users/lumi/Desktop/companyCode/script/sdk_ios_bundle'
20
+ # print(sdk_str_dir)
21
+ suffixs = string_repeat_filter.generateIOSStringPathList('')
22
+ iosdict = {}
23
+ for strBundleName in modules:
24
+ for suff in suffixs:
25
+ path = f'{sdk_str_dir}/{strBundleName}{suff}'
26
+ readlocalizedFromPath(path,iosdict)
27
+ save_path = './source.text'
28
+ save_xlsx = './source.xlsx'
29
+ if os.path.exists(save_path):
30
+ os.remove(save_path)
31
+ file_util.writeToFileForDictStringElementInText(iosdict,save_path)
32
+ file_util.writeToFileForDictStringElement(iosdict,save_xlsx)
33
+
34
+
35
+ def generate_localizedString():
36
+ save_path = './source.xlsx'
37
+ if not os.path.exists(save_path):
38
+ return
39
+
40
+ final_dir = './output'
41
+ if not os.path.exists(final_dir):
42
+ os.makedirs(final_dir)
43
+ iosStringListPath = string_repeat_filter.generateIOSStringPathList(final_dir)
44
+ print(iosStringListPath)
45
+ if not os.path.exists(os.path.dirname(iosStringListPath[0])):
46
+ [os.makedirs(os.path.dirname(x)) for x in iosStringListPath]
47
+
48
+ write_fios = [open(path,r'w') for path in iosStringListPath]
49
+
50
+ ios_sum_dic = file_util.readXlsxFileToDict(save_path)
51
+ for key in ios_sum_dic:
52
+ ele = ios_sum_dic.get(key)
53
+ value_list= ele.valueList
54
+ # print(value_list)
55
+
56
+ for value,fios in zip(value_list,write_fios):
57
+ string = f'{key}=\"{value}\";\n'
58
+ fios.write(string)
59
+
60
+ for fios in write_fios:
61
+ fios.close()
62
+
63
+ pass
64
+
65
+ def readlocalizedFromPath(path,originDict):
66
+ if not os.path.exists(path):
67
+ print(path)
68
+ return []
69
+ file = open(path,'r')
70
+ index = string_repeat_filter.getIosLanIndex(path)
71
+ block = ''
72
+ for line in file.readlines():
73
+ line.strip()
74
+ # print(line)
75
+ if line.endswith(f';\n'):
76
+ block += line
77
+ #处理一个block
78
+ first_index = block.find(r'=')
79
+ k = block[0:first_index]
80
+ k = k[k.find(r'"')+1:k.rfind(r'"')]
81
+ k = k.strip()
82
+ v = block[first_index:-1]
83
+ v = v[v.find(r'"')+1:v.rfind(r'"')]
84
+ v = v.strip()
85
+ se = string_element.StringElement(k)
86
+ if k in originDict:
87
+ se = originDict.get(k)
88
+ se.addStrValue(v, index)
89
+ originDict[k] = se
90
+
91
+ block = ''
92
+ else:
93
+ # if not line.startswith(r'//') and not line.__contains__(r'***'):
94
+ block += line
95
+
96
+
97
+
98
+ #扫描代码中的key,检查语言包里是否有
99
+ def scanKeyInCode(codePath,platformUniteStrDict,notFoundkeys):
100
+
101
+ for root, dirc, files in os.walk(codePath):
102
+ for file in files:
103
+ if file.endswith('.m'):
104
+ rfile = open(os.path.join(root, file), 'r')
105
+ block = ''
106
+ for line in rfile.readlines():
107
+ block += line
108
+ if line.endswith(f';\n'):
109
+ #处理block 内容
110
+ fileKeyInOcBlock(block,platformUniteStrDict,root,file,notFoundkeys)
111
+ block = ''
112
+ elif file.endswith('.swift'):
113
+ rfile = open(os.path.join(root, file), 'r')
114
+ block = ''
115
+ for line in rfile.readlines():
116
+ block += line
117
+ if line.endswith(f'\n'):
118
+ # 处理block 内容
119
+ fileKeyInSwiftBlock(block, platformUniteStrDict, root, file, notFoundkeys)
120
+ block = ''
121
+
122
+ def fileKeyInSwiftBlock(block,dic,root,file,notFoundkeys):
123
+ keywords = [f'LHLocalizedTool.localizedString(forKey:"',
124
+ f'LMBundleNSLocalizedString("',
125
+ f'LHLocalizedTool.localizedString(forKey: "']
126
+ for keyword in keywords:
127
+ tempBlock = block
128
+ while tempBlock.__contains__(keyword):
129
+ left = tempBlock.find(keyword) + len(keyword)
130
+ right = tempBlock.find(f'"',left)
131
+ key = tempBlock[left:right]
132
+ if not key in dic:
133
+ se = string_element.StringElement(key)
134
+ se.module = f'{root}/{file}'
135
+ notFoundkeys[key]=se
136
+
137
+ tempBlock = tempBlock[right:len(tempBlock)]
138
+
139
+
140
+ def fileKeyInOcBlock(block,dic,root,file,notFoundkeys):
141
+ keywords = [f'localizedStringForKey:@"',
142
+ f'LMCALanuage(@"',
143
+ f'LMCTLanuage(@"',
144
+ f'LMIrcodeLocalizedString(@"',
145
+ f'LMLTLanuage(@"',
146
+ f'LMMDLocalizedString(@"',
147
+ f'kLMPositionFrameworkNSLocalized(@"']
148
+ for keyword in keywords:
149
+ tempBlock = block
150
+ while tempBlock.__contains__(keyword):
151
+ left = tempBlock.find(keyword) + len(keyword)
152
+ right = tempBlock.find(f'"',left)
153
+ key = tempBlock[left:right]
154
+ if not key in dic:
155
+ se = string_element.StringElement(key)
156
+ se.module = f'{root}/{file}'
157
+ notFoundkeys[key]=se
158
+
159
+ tempBlock = tempBlock[right:len(tempBlock)]
160
+
161
+ #遍历出项目中所有的key,如果不在多语言表里,就记录下来
162
+ def searchKeyNotInlanList():
163
+ codelist = [f'/Users/lumi/Desktop/companyCode/电信SDK/灯光Framework/LMLightFramework/',
164
+ f'/Users/lumi/Desktop/companyCode/电信SDK/登录模块SDK/LMLoginFramework/',
165
+ f'/Users/lumi/Desktop/companyCode/电信SDK/红外SDK/LMIrcodeFramework/',
166
+ f'/Users/lumi/Desktop/companyCode/电信SDK/基础库SDK/LMFramework/',
167
+ f'/Users/lumi/Desktop/companyCode/电信SDK/家庭位置SDK/LMPositionFramework/LMPositionFramework/',
168
+ f'/Users/lumi/Desktop/companyCode/电信SDK/曲线Framework/LMChartFramework/',
169
+ f'/Users/lumi/Desktop/companyCode/电信SDK/摄像头SDK/LMCameraFramework/',
170
+ f'/Users/lumi/Desktop/companyCode/电信SDK/AqaraHome/AqaraHome/',
171
+ f'/Users/lumi/Desktop/companyCode/电信SDK/OTA/LMFirmwareUpgradeFramework/',
172
+ f'/Users/lumi/Desktop/companyCode/电信SDK/入网SDK/APP_iOS_AccessNetSDK/LumiConnectSDK/LMDeviceAccessNet'
173
+ ]
174
+ codelist = [ f'/Users/lumi/Desktop/companyCode/电信SDK/AqaraHome/AqaraHome/',f'/Users/lumi/Desktop/companyCode/电信SDK/kanban/']
175
+
176
+ filepath = f'../source_language/hit_all_str.xlsx'
177
+ if not os.path.exists(filepath):
178
+ print(filepath)
179
+ return
180
+ platformUniteStrDict = file_util.readXlsxFileToDict(filepath)
181
+ notFoundkeys = {}
182
+ for path in codelist:
183
+ scanKeyInCode(path, platformUniteStrDict,notFoundkeys)
184
+
185
+
186
+ num = 0
187
+ for key in notFoundkeys:
188
+ se = notFoundkeys[key]
189
+ num+=1
190
+ print(f'{num}:{key},path:{se.module}')
191
+ # 存储
192
+ savePath = f'./notFoundKeys.xlsx'
193
+ file_util.writeToFileForDictStringElement(notFoundkeys,savePath)
194
+
195
+
196
+ def replaceKeyInCode():
197
+
198
+ filepath = f'./notFoundKeys.xlsx'
199
+ filepath2 = f'./new_value_notfoundkey.xlsx'
200
+
201
+ #先注释掉
202
+ # if not os.path.exists(filepath):
203
+ # print(filepath)
204
+ # return
205
+ # willReplaceDic = file_util.readOldXlsxFileToDict(filepath)
206
+ #
207
+ # #搜索老项目中的多语言
208
+ # modules = [
209
+ # 'main',
210
+ # 'LMAccessNet.bundle',
211
+ # 'LMCameraFramework.bundle',
212
+ # 'LMChartFramework.bundle',
213
+ # 'LMFramework.bundle',
214
+ # 'LMLightFramework.bundle',
215
+ # 'LMIrcodeLanguage.bundle',
216
+ # 'LMMDUILanguage.bundle',
217
+ # 'LMUpgradeLanguage.bundle',
218
+ # ]
219
+ # sdk_str_dir = '/Users/lumi/Desktop/companyCode/电信SDK/AqaraHome/AqaraHome/Common/Frameworks'
220
+ # # print(sdk_str_dir)
221
+ # suffixs = string_repeat_filter.generateIOSStringPathList('')
222
+ # #生成最终的dic
223
+ # probjDic = {}
224
+ # for strBundleName in modules:
225
+ # for suff in suffixs:
226
+ # path = f'{sdk_str_dir}/{strBundleName}{suff}'
227
+ # readlocalizedFromPath(path, probjDic)
228
+ #
229
+ # #把valuelist补充完整
230
+ # for key in willReplaceDic:
231
+ # se = willReplaceDic[key]
232
+ # for projKey in probjDic:
233
+ # projSe = probjDic[projKey]
234
+ # if key == projKey or key in projSe.valueList:
235
+ # se.valueList = projSe.valueList
236
+ # file_util.writeToFileForDictStringElement(willReplaceDic,filepath2)
237
+ #
238
+ # return
239
+
240
+ #补充它的key
241
+ excelfilepath = f'../source_language/hit_all_str.xlsx'
242
+ aaaaaaadic = file_util.readXlsxFileToDict(excelfilepath)
243
+
244
+ bbbdic = file_util.readOldXlsxFileToDict(filepath2)
245
+ for bbbkey in bbbdic:
246
+ belment = bbbdic[bbbkey]
247
+ belment.replaceid = None
248
+ if belment.valueList[0] == '' and belment.valueList[1] == '':
249
+ for aaakey in aaaaaaadic:
250
+ aelement = aaaaaaadic[aaakey]
251
+ if bbbkey == aaakey or bbbkey in aelement.valueList:
252
+ # print(f'valist:{belment.valueList[0]}')
253
+ belment.replaceid = aelement.id
254
+
255
+ elif belment.valueList[0] != '' and belment.valueList[1] != '':
256
+ for aaakey in aaaaaaadic:
257
+ aelement = aaaaaaadic[aaakey]
258
+ if belment.valueList[0] == aelement.valueList[0] and belment.valueList[1] == aelement.valueList[1]:
259
+ # print(f'a:{aelement.valueList}-b:{belment.valueList}')
260
+ belment.replaceid = aelement.id
261
+ # print(f'{belment.replaceid}')
262
+ resultFilePath = f'./result_notfoundkey.xlsx'
263
+ file_util.writeToFileForDictStringElement(bbbdic,resultFilePath)
264
+
265
+
266
+ #替换操作
267
+ willReplaceDic = bbbdic
268
+ replaceMap = {}
269
+ for key in willReplaceDic:
270
+ se = willReplaceDic[key]
271
+ if se.replaceid != None:
272
+ replaceMap[key]=se.replaceid
273
+
274
+ for key in replaceMap:
275
+ print(f'{key}:---------{replaceMap[key]}')
276
+
277
+ codelist = [ f'/Users/lumi/Desktop/companyCode/电信SDK/AqaraHome/AqaraHome/',f'/Users/lumi/Desktop/companyCode/电信SDK/kanban/']
278
+
279
+ for path in codelist:
280
+ codeReplace(path, replaceMap)
281
+
282
+ # 扫描代码中的key,检查语言包里是否有
283
+ def codeReplace(codePath, willReplaceDic):
284
+
285
+ for root, dirc, files in os.walk(codePath):
286
+ for file in files:
287
+ if file.endswith('.m'):
288
+ filedata = ''
289
+ rfile = open(os.path.join(root, file), 'r')
290
+ block = ''
291
+ for line in rfile.readlines():
292
+ block += line
293
+ if line.endswith(f';\n'):
294
+ # 处理block 内容
295
+ block = replacekeyInOcBlock(block,willReplaceDic)
296
+ filedata += block
297
+ block = ''
298
+ else:
299
+ pass
300
+ filedata += block
301
+
302
+ #写入文件
303
+ try:
304
+ fos = open(os.path.join(root,file), 'w')
305
+ fos.write(filedata)
306
+ fos.close()
307
+ except:
308
+ print(os.path.join(root,file))
309
+ finally:
310
+ pass
311
+ elif file.endswith('.swift'):
312
+ filedata = ''
313
+ rfile = open(os.path.join(root, file),'r')
314
+ block = ''
315
+ for line in rfile.readlines():
316
+ block += line
317
+ if line.endswith(f';'):
318
+ # 处理block 内容
319
+ block = replacekeyInSwiftBlock(block,willReplaceDic)
320
+ filedata += block
321
+ block = ''
322
+ else:
323
+ pass
324
+ filedata += block
325
+
326
+
327
+ #写入文件
328
+ try:
329
+ fos = open(os.path.join(root,file), 'w')
330
+ fos.write(filedata)
331
+ fos.close()
332
+ except:
333
+ print(os.path.join(root,file))
334
+ finally:
335
+ pass
336
+
337
+
338
+
339
+ def replacekeyInOcBlock(block,willReplaceDic):
340
+ for key in willReplaceDic:
341
+ replaceKey = willReplaceDic[key]
342
+ if block.__contains__(f'lizedStringForKey:@"{key}"'):
343
+ block = block.replace(f'lizedStringForKey:@"{key}"',f'lizedStringForKey:@"{replaceKey}"')
344
+ if block.__contains__(f'NSLocalizedString(@"{key}"'):
345
+ block = block.replace(f'NSLocalizedString(@"{key}"',f'NSLocalizedString(@"{replaceKey}"')
346
+ if block.__contains__(f'LMCALanuage(@"{key}"'):
347
+ block = block.replace(f'LMCALanuage(@"{key}"', f'LMCALanuage(@"{replaceKey}"')
348
+ if block.__contains__(f'LMCTLanuage(@"{key}"'):
349
+ block = block.replace(f'LMCTLanuage(@"{key}"', f'LMCTLanuage(@"{replaceKey}"')
350
+ if block.__contains__(f'LMIrcodeLocalizedString(@"{key}"'):
351
+ block = block.replace(f'LMIrcodeLocalizedString(@"{key}"', f'LMIrcodeLocalizedString(@"{replaceKey}"')
352
+ if block.__contains__(f'LMLTLanuage(@"{key}"'):
353
+ block = block.replace(f'LMLTLanuage(@"{key}"', f'LMLTLanuage(@"{replaceKey}"')
354
+ if block.__contains__(f'kLMPositionFrameworkNSLocalized(@"{key}"'):
355
+ block = block.replace(f'kLMPositionFrameworkNSLocalized(@"{key}"', f'kLMPositionFrameworkNSLocalized(@"{replaceKey}"')
356
+ if block.__contains__(f'LMMDLocalizedString(@"{key}"'):
357
+ block = block.replace(f'LMMDLocalizedString(@"{key}"',f'LMMDLocalizedString(@"{replaceKey}"')
358
+
359
+ return block
360
+
361
+
362
+ def replacekeyInSwiftBlock(block,willReplaceDic):
363
+ for key in willReplaceDic:
364
+ replaceKey = willReplaceDic[key]
365
+ if block.__contains__(f'LMBundleNSLocalizedString("{key}"'):
366
+ block = block.replace(f'LMBundleNSLocalizedString("{key}"',f'LMBundleNSLocalizedString("{replaceKey}"')
367
+ if block.__contains__(f'LHLocalizedTool.localizedString(forKey: "{key}"'):
368
+ block = block.replace(f'LHLocalizedTool.localizedString(forKey: "{key}"',f'LHLocalizedTool.localizedString(forKey: "{replaceKey}"')
369
+ if block.__contains__(f'LHLocalizedTool.localizedString(forKey: "{key}"'):
370
+ block = block.replace(f'LHLocalizedTool.localizedString(forKey:"{key}"',
371
+ f'LHLocalizedTool.localizedString(forKey:"{replaceKey}"')
372
+ return block
373
+
374
+
375
+ #需求:扫描代码中的未翻译的汉语
376
+ # 如果在表里能找到,就直接替换掉。
377
+ #找不到的话,就记录下信息,便于后期人工review.
378
+
379
+ def scanUnTranslateKey():
380
+ # 新增的多语言字典
381
+ filepath = './AqaraHome.xlsx'
382
+ willReplaceDic = file_util.tempReadXlsxFileToDict(filepath)
383
+ print('-----------')
384
+ # for key in willReplaceDic:
385
+ # se = willReplaceDic[key]
386
+ # print(se.valueList[0])
387
+ # return
388
+ codePath = f'/Users/lumi/Desktop/companyCode/电信SDK/AqaraHome/'
389
+ for root, dirc, files in os.walk(codePath):
390
+ for file in files:
391
+ if file.endswith('.m'):
392
+ # continue
393
+ #暂时调过
394
+ isOC = file.endswith('.m')
395
+ filedata = ''
396
+ rfile = open(os.path.join(root, file), 'r')
397
+ block = ''
398
+ for line in rfile.readlines():
399
+ block += line
400
+ if line.endswith(f';\n'):
401
+ # 处理block 内容
402
+ block = replaceUnTranslateKeyInBlock(block,willReplaceDic,isOC)
403
+ filedata += block
404
+ block = ''
405
+ else:
406
+ pass
407
+ filedata += block
408
+ #写入文件
409
+ try:
410
+ fos = open(os.path.join(root,file), 'w')
411
+ fos.write(filedata)
412
+ fos.close()
413
+ except:
414
+ print(os.path.join(root,file))
415
+ finally:
416
+ pass
417
+ elif file.endswith('.swift'):
418
+ isOC = False
419
+ filedata = ''
420
+ rfile = open(os.path.join(root, file), 'r')
421
+ block = ''
422
+ for line in rfile.readlines():
423
+ block += line
424
+ if line.endswith(f'\n'):
425
+ # 处理block 内容
426
+ block = replaceUnTranslateKeyInSwift(block, willReplaceDic, isOC)
427
+ filedata += block
428
+ block = ''
429
+ else:
430
+ pass
431
+ filedata += block
432
+ # 写入文件
433
+ try:
434
+ fos = open(os.path.join(root, file), 'w')
435
+ fos.write(filedata)
436
+ fos.close()
437
+ except:
438
+ print(os.path.join(root, file))
439
+ finally:
440
+ pass
441
+
442
+ def replaceUnTranslateKeyInSwift(block,wordsDic,isOc):
443
+ for key in wordsDic:
444
+ elment = wordsDic[key]
445
+ simpleChin = elment.valueList[0]
446
+ # print(f'block:{simpleChin}')
447
+ if block.__contains__(f'"{simpleChin}"') and\
448
+ not block.__contains__(f'lizedStringForKey') and \
449
+ not block.__contains__(f'LMBundleNSLocalizedString'):
450
+ # print(f'中文:{simpleChin}-block:{block}')
451
+ block = block.replace(f'"{simpleChin}"',f'LMBundleNSLocalizedString("{key}","{simpleChin}")')
452
+ # replaceUnTranslateKeyInBlock(block,wordsDic,isOc)
453
+ return block
454
+
455
+ def replaceUnTranslateKeyInBlock(block,wordsDic,isOc):
456
+ for key in wordsDic:
457
+ elment = wordsDic[key]
458
+ simpleChin = elment.valueList[0]
459
+ # print(f'block:{simpleChin}')
460
+ if block.__contains__(f'@"{simpleChin}"') and \
461
+ not block.__contains__(f'lizedStringForKey') and\
462
+ not block.__contains__(f'LMBundleNSLocalizedString'):
463
+ # print(f'中文:{simpleChin}-block:{block}')
464
+ block = block.replace(f'@"{simpleChin}"',f'LMBundleNSLocalizedString(@"{key}",@"{simpleChin}")')
465
+ # replaceUnTranslateKeyInBlock(block,wordsDic,isOc)
466
+ return block
467
+
468
+
469
+
470
+ if __name__ == '__main__':
471
+ # scanUnTranslateKey()
472
+ #扫描代码中所有的key,如果不在总表里,就列出来
473
+ # searchKeyNotInlanList()
474
+
475
+ replaceKeyInCode()
Binary file
@@ -0,0 +1,16 @@
1
+ # This is a sample Python script.
2
+
3
+ # Press ⇧⌘F11 to execute it or replace it with your code.
4
+ # Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
5
+
6
+
7
+ def print_hi(name):
8
+ # Use a breakpoint in the code line below to debug your script.
9
+ print(f'Hi, {name}') # Press ⇧⌘B to toggle the breakpoint.
10
+
11
+
12
+ # Press the green button in the gutter to run the script.
13
+ if __name__ == '__main__':
14
+ print_hi('PyCharm')
15
+
16
+ # See PyCharm help at https://www.jetbrains.com/help/pycharm/