使用Python进行谷歌翻译的最佳方式

low*_*tty 23 python translation

我正在尝试将大量文本文件从英语翻译成其他几种语言.我们在项目中使用Python,我们首先尝试使用Google翻译服务进行翻译,然后我们将手动纠正错误.

我想出了两种翻译方式:

  1. 使用Python Google翻译API.这里:goslate 1.1.2:Python包

  2. 尝试使用谷歌翻译页面进行编程,即输入我们要翻译的文本,模拟HTTP请求并处理响应.谷歌翻译

有没有人有更好的报价?

mou*_*mou 20

我为python制作了自己的谷歌翻译功能;)试试吧https://github.com/mouuff/Google-Translate-API


Mad*_*May 15

事实上谷歌确实有一个带REST接口的官方翻译API.你可以在这里查看.请注意,它是付费API,没有免费配额.


小智 8

尝试使用该googletrans模块。例如:

from googletrans import Translator


translator = Translator()  # initalize the Translator object
translations = translator.translate(['see if this helps', 'tarun'], dest='hi')  # translate two phrases to Hindi
for translation in translations:  # print every translation
    print(translation.text)

# Output:
# ????? ?? ?? ??? ???? ??
# ????
Run Code Online (Sandbox Code Playgroud)

支持的语言 (106) 及其 ISO639-1 代码的字典:

import googletrans


print(googletrans.LANGCODES)  # {language name: iso639-1 language code}
# or
print(googletrans.LANGUAGES)  # {iso639-1 language code: language name}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅文档