简体   繁体   English

在Python中指定源语言Google翻译API

[英]Specify source language Google Translation API in Python

I'm using Google Translation API to translate individual words in python. 我正在使用Google Translation API在python中翻译单个单词。 Sometimes autodetect is inaccurate. 有时自动检测不准确。 Now the API seems to take no argument to specify the source language. 现在,API似乎没有参数来指定源语言。

I've seen some projects on github with functions taking the source as argument but these methods are old and use the url. 我已经在github上看到了一些项目,这些项目带有将源作为参数的函数,但是这些方法比较老,并且使用url。

How am I supposed to fix this problem? 我应该如何解决这个问题?

You can provide the source language as follows: 您可以提供以下源语言:

from google.cloud import translate

translate_client = translate.Client()

result = translate_client.translate(
    text, source_language='en', target_language=target)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM