【问题标题】:Translating a document from Spanish to English & preserve formatting将文档从西班牙语翻译成英语并保留格式
【发布时间】:2017-10-26 10:15:52
【问题描述】:

我一直在使用https://translate.google.com/ 将西班牙语 PDF 和 Word 文档翻译成英语。

是否有 Restful API(或其他方法)将文档从西班牙语翻译成英语,同时保留文档的格式?

我知道我可以提取文本然后使用 Google API 进行翻译,但我会丢失格式。

【问题讨论】:

标签: google-translate translate


【解决方案1】:

您可以在 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 中写入每个文档的名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-13
    • 2019-07-14
    • 2017-12-27
    相关资源
    最近更新 更多