#!/usr/bin/env python3 import os, sys, opencc def convert(src_path, dst_path, cfg='s2twp.json'): converter = opencc.OpenCC(cfg) with open(src_path, "r", encoding='utf-8') as src, open(dst_path, "w+", encoding='utf-8') as dst: dst.write("\n".join( converter.convert(line.rstrip()).replace('(img/', '(../img/') .replace('é«®é', 'å³é') .replace('é«®å¸', 'éåº') .replace('é«®ç', 'ç¼ç') .replace('é«®åº', 'ç¼åº') .replace('å試', 'å試') .replace('ç·ä¸æ§ä¸è´', 'å¨ç·æ§ä¸è´') # ä¼å æâå¨çº¿â解æäºï¼ .replace('復é', 'è¤é') .replace('è¨è«ç', 'è¨è«äº') .replace('åé»´', 'å楣') .replace('ååæ§æ§', 'ååæ§') .replace('ä¸éºµæ¢ä»¶', 'ä¸é¢æ¢ä»¶') # ä¼å æâé¢æ¡â解æäºï¼ .replace('ç¶æ¥å¿', 'ç¶æ¥èª') # ä¼å æâå½æ¥â解æäºï¼æ²¡æèèåé¢çâæ¥å¿âï¼ .replace('çå³æé', 'ç實æé') # ä¼å æâå®æ¶â解æäºï¼æ²¡æèèåé¢çâçå®âï¼ for line in src)) print("convert %s to %s" % (src_path, dst_path)) if __name__ == '__main__': print(sys.argv) home = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), '..')) os.chdir(home) for f in os.listdir(): if f.endswith('.md'): convert(f, "zh-tw/" + f)