# 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,但是没有什么改变。
发布于 2022-01-19 12:05:13
发布于 2022-01-24 19:34:12
我能找到的唯一已知的解决方案,我已经成功地实现了(处理印地语和其他语言),就是音译输入。
我个人认为Google的回答是不受支持的,因为从拉丁文输入字符返回的目标语言(在语音上相当于输入者想要的语音)是实际的语言。因此,在印地语中检测到"HI“,但返回的翻译与输入相同。如果谷歌能够从音译的拉丁语字符中检测出它的印地语,那么为什么不直接返回结果呢?
Steps to work around:
1. translate through translate-api as normal. Use the latin characters as the inputs.
2. receive the results from the the translate, and ignore the returned translation. (It will be the same as the input latin). Collect the targetLanguageDetected field, and save this.
3. call google's (deprecated but still supported) transliterate interface, with the input language (received from step 2) and the same original latin character inputs (URL is: https://inputtools.google.com/request?text=${srcMessage}&itc=${srclang}-t-i0-und&num=${numChoices}&cp=0&cs=1&ie=utf-8&oe=utf-8&app=demopage) - srcMessage is the original latin character text, srclang is the output from step 2, and numchoices is the number of "suggestions" that are generated from the input.
4. re run step 1, with the output from step 3 (the "HI" characters, or whatever alphabet is returned)谷歌过去允许在不需要翻译成本的情况下进行检测,但现在已经不是这样了。
此外,Google的API在这种行为中是不一致的。例如,如果我输入俄语音译:“女贞”,我会得到“你好”。
发布于 2022-01-19 06:23:12
嗨,google云控制台是为英语制作的,你不是完全管理它,它只是你管理的例子,我试着关闭我的google,我尝试过sudo,我试过sudo,并且它的工作方式是相同的,使用sudo apt下载语言包,如果sudo su不工作的话,使用sudo来安装sudo,所以这意味着google不想让你这么做。
https://stackoverflow.com/questions/70765855
复制相似问题