""" * Version: 0.1.0.0.0 """ import sys, re import pingcap.pe.flash.util as util import pingcap.pe.flash.util_zh2en as util_zh2en if __name__ == "__main__": input_md_file_path = sys.argv[1] output_md_file_path = sys.argv[1].split(".")[0] + "_translated_zh2en.md" print(util.speak_title("Translate Markdown to Markdown in English")) mode = "standard" if mode != "silent": print( "Translate markdown file:", input_md_file_path, "to", output_md_file_path, "for", "pe", ) en_1gram_list = util.load_1gram_terms_en("pe") fr = open(input_md_file_path, "r") lines = fr.read() fr.close() f = open(output_md_file_path, "w") write_lines = [] translation_mute_zone = False for line in lines.split("\n"): if ( re.match("^ *``", line) and len(re.findall("``", line)) % 2 == 1 and translation_mute_zone ): translation_mute_zone = False write_lines += [line] elif ( re.match("^ *``", line) and len(re.findall("``", line)) % 2 == 1 and not translation_mute_zone ): translation_mute_zone = True write_lines += [line] elif not re.match("^ *``", line) and translation_mute_zone: write_lines += [line] else: write_lines += [ util_zh2en.translate_zh2en_md_line( line, en_1gram_list, "silent", True, input_md_file_path ) ] f.write("\n".join(write_lines)) f.close() if mode == "standard": print(util.speak_result("Output Markdown File Path: " + output_md_file_path))