2017-05-25 99 views
1

我一直在使用https://translate.google.com/來翻譯西班牙文PDF & Word文檔爲英文。將文檔從西班牙文翻譯成英文並保留格式

是否有Restful API(或其他方法)將文檔從西班牙文翻譯成英文,同時保留文檔的格式?

我知道我可以提取文本,然後使用Google API進行翻譯,但是我會忽略格式。

+0

您可以在網站上添加谷歌翻譯。看看這裏: https://stackoverflow.com/a/44260037/2339356 –

回答

0

你可以在Python運行這段代碼:

import goslate 
big_files = ['lenin.txt', 'liga.txt'] 
gs = goslate.Goslate() 

translation = [] 
for big_file in big_files: 
    with open(big_file, 'r') as f: 
     translated_lines = [] 
     for line in f: 
      translated_line = gs.translate(line, "en") 
      translated_lines.append(translated_line) 

     translation.append('\n'.join(translated_lines)) 

你在哪裏,你要翻譯的文檔是設置目錄,然後在big_files你寫的每一個文件的名稱。

相關問題