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

Specify source language Google Translation API in Python

我正在使用 Google 翻译 API 来翻译 python 中的个别单词。有时自动检测不准确。现在 API 似乎没有参数来指定源语言。

我在 github 上看到一些项目的函数将源作为参数,但这些方法很旧并且使用 url。

我该如何解决这个问题?

您可以提供源语言如下:

from google.cloud import translate

translate_client = translate.Client()

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