merge_root_path = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_MERGE_NAME)
translation_excel_folder_path = os.path.join(merge_root_path, 'Translation_Excel')
if not os.path.exists(translation_excel_folder_path):
print('目标翻译文件 {0} 路径不存在'.format(translation_excel_folder_path))
exit(1)
merge_android_src_path = os.path.join(merge_root_path, 'Android', 'values-old')
merge_android_dst_path = os.path.join(merge_root_path, 'Android', 'values-new')
merge_ios_src_path = os.path.join(merge_root_path, 'iOS', 'strings-old')
merge_ios_dst_path = os.path.join(merge_root_path, 'iOS', 'strings-new')
merge_flutter_src_path = os.path.join(merge_root_path, 'Flutter', 'l10n-old')
merge_flutter_dst_path = os.path.join(merge_root_path, 'Flutter', 'l10n-new')
merge_pc_src_path = os.path.join(merge_root_path, 'PC', 'old')
merge_pc_dst_path = os.path.join(merge_root_path, 'PC', 'new')
enable_android_merge = os.path.exists(merge_android_src_path)
enable_ios_merge = os.path.exists(merge_ios_src_path)
enable_flutter_merge = os.path.exists(merge_flutter_src_path)
enable_pc_merge = os.path.exists(merge_pc_src_path)
if not os.path.exists(merge_android_dst_path):
os.makedirs(merge_android_dst_path)
if not os.path.exists(merge_ios_dst_path):
os.makedirs(merge_ios_dst_path)
if not os.path.exists(merge_flutter_dst_path):
os.makedirs(merge_flutter_dst_path)
if not os.path.exists(merge_pc_dst_path):
os.makedirs(merge_pc_dst_path)
if enable_android_merge or enable_ios_merge or enable_flutter_merge or enable_pc_merge:
refer_excel_file = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_COMMON_NAME,
'Refer_Standard.xls')
if os.path.exists(refer_excel_file):
refer_tuple = TranslateInfoExcelReader.read_excel_content_list(refer_excel_file)
else:
refer_tuple = []
translation_excel_file_list = os.listdir(translation_excel_folder_path)
translation_excel_file_list = [x for x in translation_excel_file_list if x.endswith(".xlsx")]
curr_time = time.strftime('%Y-%m-%d-%X', time.localtime(time.time())).replace(":", '')
android_log_file_name = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_MERGE_NAME,
'Translation_Log', "AndroidLog" + str(curr_time) + ".txt")
flutter_log_file_name = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_MERGE_NAME,
'Translation_Log', "FlutterLog" + str(curr_time) + ".txt")
pc_log_file_name = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_MERGE_NAME,
'Translation_Log', "PCLog" + str(curr_time) + ".txt")
ios_log_file_name = os.path.join(Config.CURRENT_WORKSPACE_ROOT_PATH, Config.CURRENT_WORKSPACE_MERGE_NAME,
'Translation_Log', "Log-漏翻记录.txt")
extract_root_path = os.path.join(Config.WORKSPACE_BASE_PATH )
locale_json_dst_file = os.path.join(os.path.join(extract_root_path), 'all_englist_translate_dict.text')
all_english_translate_dict = dict()
with open(locale_json_dst_file, 'r', encoding='utf-8') as f:
all_english_translate_dict = json.load(f)
if os.path.exists(ios_log_file_name):
os.remove(ios_log_file_name)
for excel in translation_excel_file_list:
excel_file = os.path.join(translation_excel_folder_path, excel)
print(excel_file)
excel_dict = TranslateInfoExcelReader.read_excel_content_dict(excel_file)
for item in excel_dict.values():
check_formatter(item.english, item.translate_result)
for refer in refer_tuple:
if refer.translate_result in excel_dict:
english = refer.english
platform = refer.platform
no = refer.no
note = refer.note
translate = FormatSpecifierParser.build_format_char(refer.english, refer.translate_result,
excel_dict[
refer.translate_result].translate_result)
excel_dict[english] = TranslateInfo(english, translate, platform, no, note)
locale = excel.replace('.xlsx', '')
for item in excel_dict.values():
# print(excel, item.english, item.translate_result)
if item.english in all_english_translate_dict:
all_english_translate_dict[item.english][locale] = item.translate_result
else:
tmp_translate_dict = dict()
tmp_translate_dict[locale] = item.translate_result
all_english_translate_dict[item.english] = tmp_translate_dict
if enable_android_merge and locale in Config.ANDROID_LOCALE_DICT:
locale_path = 'values-' + Config.ANDROID_LOCALE_DICT[locale]
merge_android_src_english_file = os.path.join(merge_android_src_path, 'values', 'strings.xml')
merge_android_src_locale_file = os.path.join(merge_android_src_path, locale_path, 'strings.xml')
merge_android_dst_locale_path = os.path.join(merge_android_dst_path, locale_path)
XmlMerger(excel_dict, merge_android_src_english_file, merge_android_src_locale_file,
merge_android_dst_locale_path, android_log_file_name).merge(1)
if enable_ios_merge and locale in Config.IOS_LOCALE_DICT:
locale_path = Config.IOS_LOCALE_DICT[locale] + '.lproj'
merge_ios_src_english_path = os.path.join(merge_ios_src_path, 'en.lproj')
merge_ios_dst_english_path = os.path.join(merge_ios_dst_path, 'en.lproj')
merge_ios_src_locale_path = os.path.join(merge_ios_src_path, locale_path)
merge_ios_dst_locale_path = os.path.join(merge_ios_dst_path, locale_path)
StringsMerger(locale, excel_dict, merge_ios_src_english_path, merge_ios_dst_english_path,
merge_ios_src_locale_path, merge_ios_dst_locale_path).merge()
if enable_flutter_merge and locale in Config.FLUTTER_LOCALE_DICT:
locale_path = Config.FLUTTER_LOCALE_DICT[locale]
merge_flutter_src_english_file = os.path.join(merge_flutter_src_path, 'intl_en.arb')
merge_flutter_src_locale_file = os.path.join(merge_flutter_src_path, 'intl_' + locale_path + '.arb')
merge_flutter_dst_locale_path = os.path.join(merge_flutter_dst_path, 'intl_' + locale_path + '.arb')
FlutterMerger(excel_dict, merge_flutter_src_english_file, merge_flutter_src_locale_file,
merge_flutter_dst_locale_path, flutter_log_file_name).merge(1)
if enable_pc_merge and locale in Config.PC_LOCALE_DICT:
locale_path = Config.PC_LOCALE_DICT[locale]
merge_pc_src_english_file = os.path.join(merge_pc_src_path, 'en.json')
merge_pc_src_locale_file = os.path.join(merge_pc_src_path, locale_path + '.json')
merge_pc_dst_locale_path = os.path.join(merge_pc_dst_path, locale_path + '.json')
FlutterMerger(excel_dict, merge_pc_src_english_file, merge_pc_src_locale_file,
merge_pc_dst_locale_path, pc_log_file_name).merge(1)
locale_json_dst_file = os.path.join(os.path.join(extract_root_path), 'all_englist_translate_dict_new.text')
with open(locale_json_dst_file, 'w', encoding='utf8') as f2:
json.dump(all_english_translate_dict, f2, ensure_ascii=False, indent=2) 代码解析
最新发布