其他分享
首页 > 其他分享> > 写了一个自动用google翻译文档的工具

写了一个自动用google翻译文档的工具

作者:互联网

写了一个自动用google翻译文档的工具

features:

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)

标签:翻译,google,doc,docx,sys,文档,fname,paragraphs,import
来源: https://www.cnblogs.com/cutepig/p/13771965.html