【发布时间】:2022-01-19 05:52:50
【问题描述】:
# google-translate version 3.6.1
from os import environ
import os
from google.cloud import translate
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = r"/multilingual-bot.json"
project_id = 'multilingual-bot'
assert project_id
parent = f"projects/{project_id}"
client = translate.TranslationServiceClient()
client.get_supported_languages(parent=parent, display_language_code="en")
sample_text = "kevu chale che badhu"
target_language_code = "en"
lan_response = client.detect_language(parent=parent, content=sample_text)
response = client.translate_text(contents=[sample_text],source_language_code='gu',target_language_code=target_language_code,parent=parent)
for translation in response.translations:
print(translation.translated_text)
print(lan_response)
当我在 sample_text 中传递“kevu chale che badhu”时,输出保持不变,但如果我们用根语言更改它,即“કેવુ ચલે છે બધુ”,它将返回正确的输出。我也将源语言代码更改为 gu,但没有任何改变。
【问题讨论】:
-
如果我的回答解决了您的问题,请考虑接受并点赞。如果没有,请告诉我,以便我改进答案。
标签: google-cloud-platform google-translate