写了一个自动用google翻译文档的工具
features:
- [x] 支持word
- [x] 每一个段落下面放上对照的翻译
from googletrans import Translator
import sys
import docx
fname = sys.argv[1] if len(
sys.argv) > 1 else r'F:\GoogleDriveSync3\jobrelated\The Fast Forward MBA in Project Management ( PDFDrive.com ).full.docx'
translator = Translator()
foname = fname + '-cn.docx'
doc = docx.Document(fname)
docdes = docx.Document(fname)
N = len(doc.paragraphs)
for i in range(N):
print(1.0*i/N,)
subCont = doc.paragraphs[i].text
try:
s = translator.translate(subCont, src='en', dest='zh-cn')
docdes.paragraphs[i].add_run('\n' + str(s.text) + '\n')
except Exception as e:
print('except:', e)
docdes.save(foname)