2021-08-09 22:26:03 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os, sys, opencc
|
|
|
|
|
|
|
|
def convert(src_path, dst_path, cfg='s2twp.json'):
|
|
|
|
converter = opencc.OpenCC(cfg)
|
2021-08-19 11:40:43 +08:00
|
|
|
with open(src_path, "r", encoding='utf-8') as src, open(dst_path, "w+", encoding='utf-8') as dst:
|
2021-12-07 14:29:51 +08:00
|
|
|
dst.write("\n".join(
|
|
|
|
converter.convert(line.rstrip()).replace('(img/', '(../img/')
|
|
|
|
.replace('髮送', '傳送')
|
|
|
|
.replace('髮布', '釋出')
|
|
|
|
.replace('髮生', '發生')
|
|
|
|
.replace('髮出', '發出')
|
2022-01-25 15:08:00 +08:00
|
|
|
.replace('嚐試', '嘗試')
|
2022-04-28 11:19:32 +08:00
|
|
|
.replace('線上性', '線性')
|
2022-05-11 12:19:08 +08:00
|
|
|
.replace('復雜', '複雜')
|
2022-06-08 09:06:25 +08:00
|
|
|
.replace('討論瞭', '討論了')
|
2022-06-09 10:44:06 +08:00
|
|
|
.replace('倒黴', '倒楣')
|
2021-12-07 14:29:51 +08:00
|
|
|
for line in src))
|
2021-08-09 22:26:03 +08:00
|
|
|
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)
|